As opposed to providing all the data in the call, I just make my factories dynamic by using sequences to give me unique data.
FactoryGirl.define do
factory :mail_user do
mail_domain
account
sequence :userid do |n|
"mailuser-#{n}"
end
passwd "This!sADecentPassword11212"
active :true
filter :false
end
end
or by using traits / inheritance to give me the exact user data I need
FactoryGirl.define do
factory :administrator do
isp
sequence :email do |n|
"user#{n}@example.com"
end
active true
name "Random Awesome Admin"
password '123Abc#$1'
password_confirmation '123Abc#$1'
trait :inactive do
active false
end
trait :system do
roles [:system_admin]
end
trait :admin do
roles [:admin ]
end
trait :realm do
roles [:realm_admin]
end
trait :helpdesk do
roles [ :helpdesk ]
end
trait :dns do
roles [ :dns_admin ]
end
factory :inactive_administrator, traits: [:inactive]
factory :helpdesk_admin, traits: [:helpdesk]
factory :system_admin, traits: [:system]
factory :admin, traits: [:admin]
factory :realm_admin, traits: [:realm]
factory :dns_admin, traits: [:dns]
end
end
Since in most cases I don't care about the actual username, or the like. just that it passes validation. So I would look at sequences/traits/dependent attributes. So that you rely less on hardcoded data.