i have a problem with Autotest. In my user model are the username & email address unique. When i start Autotest everything works fine. In the secound round, from autotest, i have a
Validation failed: Email has already been taken, Username has already been taken
error in only two test. I dont understand why, i use factorygirl with an sequenze and this should generate everytime a new username.
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
The 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
The only two test that are not working are in the "unique values" context. All other test works without an error.
Thanks