I have a problem with Autotest. My user model has a unique username and email address. When I run Autotest, everything works fine. In the fourth round, from the autotest, I have
Verification failed: email has already been done, username has already been completed
error in only two tests. I do not understand why, I use factorygirl with sequenze, and this should generate a new username each time.
This is my rspec2 file:
describe User do
specify { Factory.build(:user).should be_valid }
context "unique values" do
before :all do
@user = Factory.create(:user)
end
it "should have an unique email address" do
Factory.build(:user, :email => @user.email).should_not be_valid
end
it "should have an unique username" do
Factory.build(:user, :username => @user.username).should_not be_valid
end
end
context "required attributes" do
it "should be invalid without an email address" do
Factory.build(:user, :email => nil).should_not be_valid
end
it "should be invalid without an username" do
Factory.build(:user, :username => nil).should_not be_valid
end
it "should be invalid without an password" do
Factory.build(:user, :password => nil).should_not be_valid
end
it "should be invalid without an address" do
Factory.build(:user, :address => nil).should_not be_valid
end
end
end
Factory:
Factory.sequence :username do |n|
"Outfit#{n}er"
end
Factory.sequence :email do |n|
"user#{n}@example.com"
end
Factory.define :user do |u|
u.username { Factory.next :username }
u.email { Factory.next :email }
u.password 'secret'
u.phone_number '02214565854'
u.association :address, :factory => :address
end
Factory.define :confirmed_user, :parent => :user do |u|
u.after_build { |user| user.confirm! }
end
Only two tests that do not work are in the context of "unique values". All other tests work without errors.
thank
source
share