У меня есть эта настройка на фабриках.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
Когда я создавал два экземпляра Фабрики (: users), я получал ошибку уникальности.
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
Где моя проблема?
Failure/Error: let(:user) { Factory(:user) }
Validation failed: Username has already been taken, Email has already been taken