From 4a1e4ef3337c084f2347316b6dbea4d24f985a3d Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Thu, 7 Jan 2016 15:47:45 +0800 Subject: [PATCH] refactor user factories to handle codes better --- spec/factories/users.rb | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/spec/factories/users.rb b/spec/factories/users.rb index fb380e7c..91da1d1c 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -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 - factory :user do + factory :code_user, class: User do sequence(:name) { |n| "Cool User ##{n}" } sequence(:email) { |n| "cooluser#{n}@cooldomain.com" } - joinedwithcode { "qwertyui" } password 'omgwtfbbq' - transient do - validate false - end + factory :simple_user, aliases: [:user] do + joinedwithcode { "qwertyui" } + code { "qwertyui" } - # bypass validation of the joinedwithcode - to_create { |instance| instance.save(validate: instance.validate) } + transient do + validate false + end + + # bypass validation of the joinedwithcode + to_create { |instance| instance.save(validate: instance.validate) } + end end end