I have this setup in the factories.rb.
Factory.sequence(:email) { |n| "email#{n}@factory.com" }
Factory.sequence(:username) { |n| "username_#{n}" }
Factory.define :user do |u|
u.email { Factory.next :email }
u.username { Factory.next :username }
u.first_name 'Ivan'
u.last_name 'Pupkin'
u.latitude '42'
u.longitude '-71'
u.password 'qwerty'
u.password_confirmation 'qwerty'
end
When i creating two instances of the Factory(:users) i got uniqueness error.
describe CartsController do
let(:user) { Factory(:user) }
let(:another_user) { Factory(:user) }
let(:cart) { Factory(:cart) }
describe 'show my cart' do
before { sign_in user}
before { get :show, :id => user.carts.last }
it { should respond_with :success }
end
describe 'show different person cart' do
before { sign_in user }
before { get :show, :id => another_user.carts.last}
it { should respond_with :redirect }
end
end
Where is my problem?
Failure/Error: let(:user) { Factory(:user) }
Validation failed: Username has already been taken, Email has already been taken
It seems that there are records in your DB because fails
let(:user) { Factory(:user) }and notlet(:another_user) { Factory(:user) }so I see two possible solutions: addUser.delete_allin the top or manually clean DB