Created
December 6, 2012 04:01
-
-
Save emarthinsen/4221682 to your computer and use it in GitHub Desktop.
Traits in Associations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(rdb:1) p FactoryGirl.build(:user, :pro, :active) | |
ArgumentError Exception: Factory not registered: [:subscription, :pro] | |
(rdb:1) p FactoryGirl.build(:subscription, :pro) | |
#<Subscription id: nil, user_id: nil, plan: "pro", renew_on: "2012-12-13", charge_on: "2012-12-13", failures: 0, created_at: nil, updated_at: nil> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FactoryGirl.define do | |
factory :subscription do | |
plan 'free' | |
renew_on { 1.week.from_now.to_date } | |
charge_on { 1.week.from_now.to_date } | |
failures 0 | |
trait :pro do | |
plan 'pro' | |
end | |
trait :trial do | |
plan 'trial' | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SPEC_DEFAULT_PASSWORD = 'super-secret' | |
FactoryGirl.define do | |
factory :user do | |
account_type 'free' | |
sequence(:email) {|n| "user_#{n}@example.com" } | |
password SPEC_DEFAULT_PASSWORD | |
password_confirmation { password } | |
listing { create(:listing, :with_images) } | |
trait :active do | |
active true | |
end | |
trait :pro do | |
account_type 'pro' | |
listing { create(:listing, :with_images, image_count: 6) } | |
credit_card | |
association :subscription, factory: [:subscription, :pro] | |
end | |
trait :trial do | |
account_type 'trial' | |
listing { create(:listing, :with_images, image_count: 6) } | |
credit_card | |
association :subscription, factory: [:subscription, :trial] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line 19 in user_factory.rb is unable to find the factory.