refactor user factories to handle codes better
This commit is contained in:
parent
4469b29ec2
commit
4a1e4ef333
1 changed files with 21 additions and 7 deletions
|
@ -1,15 +1,29 @@
|
||||||
|
#
|
||||||
|
# This file supports three factories, because code and joinedwithcode
|
||||||
|
# make things complicated!
|
||||||
|
#
|
||||||
|
# Generally, use :simple_user to generate users. It's simplest.
|
||||||
|
#
|
||||||
|
# If you want to test code generation, or need a setup with users that
|
||||||
|
# have actual codes, you'll need to specify one simple_user and then you
|
||||||
|
# can specify other :code_user users based on the pre-existing user's code.
|
||||||
|
|
||||||
FactoryGirl.define do
|
FactoryGirl.define do
|
||||||
factory :user do
|
factory :code_user, class: User do
|
||||||
sequence(:name) { |n| "Cool User ##{n}" }
|
sequence(:name) { |n| "Cool User ##{n}" }
|
||||||
sequence(:email) { |n| "cooluser#{n}@cooldomain.com" }
|
sequence(:email) { |n| "cooluser#{n}@cooldomain.com" }
|
||||||
joinedwithcode { "qwertyui" }
|
|
||||||
password 'omgwtfbbq'
|
password 'omgwtfbbq'
|
||||||
|
|
||||||
transient do
|
factory :simple_user, aliases: [:user] do
|
||||||
validate false
|
joinedwithcode { "qwertyui" }
|
||||||
end
|
code { "qwertyui" }
|
||||||
|
|
||||||
# bypass validation of the joinedwithcode
|
transient do
|
||||||
to_create { |instance| instance.save(validate: instance.validate) }
|
validate false
|
||||||
|
end
|
||||||
|
|
||||||
|
# bypass validation of the joinedwithcode
|
||||||
|
to_create { |instance| instance.save(validate: instance.validate) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue