Created
August 27, 2012 10:59
-
-
Save danbronsema/3487459 to your computer and use it in GitHub Desktop.
RailsKit Factories
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 :account do | |
sequence(:name) {|n| "Hat Store #{n}"} | |
sequence(:full_domain) {|n| "hatstore#{n}"} | |
admin | |
subscription | |
end | |
factory :user do | |
sequence(:name) {|n| "John Doe#{n}"} | |
sequence(:email) { |n| "johndoe#{n}@example.com" } | |
password "password" | |
password_confirmation "password" | |
admin false | |
factory :admin do | |
admin true | |
end | |
end | |
factory :subscription do | |
subscription_plan | |
subscriber :account | |
next_renewal_at "#{1.day.ago.to_s(:db)}" | |
user_limit 3 | |
amount 10 | |
billing_id 'foo' | |
card_number 'XXXX-XXXX-XXXX-1111' | |
card_expiration '05-2012' | |
end | |
factory :subscription_plan do | |
name 'Free' | |
amount 10 | |
user_limit 3 | |
end | |
end | |
# 1) User has a valid factory | |
# Failure/Error: FactoryGirl.create(:account) | |
# NoMethodError: | |
# undefined method `primary_key' for String:Class | |
# ./spec/models/user_spec.rb:8:in `block (2 levels) in <top (required)>' | |
# ---------- UPDATE ---------- | |
FactoryGirl.define do | |
factory :account do | |
admin | |
sequence(:name) {|n| "Hat Store #{n}"} | |
sequence(:domain) {|n| "hatstore#{n}"} | |
association :plan, factory: :subscription_plan | |
end | |
factory :user do | |
admin false | |
sequence(:name) {|n| "John Doe#{n}"} | |
sequence(:email) { |n| "johndoe#{n}@example.com" } | |
password "password" | |
password_confirmation "password" | |
factory :admin do | |
admin true | |
end | |
end | |
factory :subscription_plan do | |
name 'Free' | |
amount 10 | |
user_limit 3 | |
end | |
end | |
# Note: This seems to work now with the updated factories. Does this seem correct? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment