Skip to content

Instantly share code, notes, and snippets.

@wasabhi
Last active August 29, 2015 14:08
Show Gist options
  • Save wasabhi/9409cd164e672a96f2c5 to your computer and use it in GitHub Desktop.
Save wasabhi/9409cd164e672a96f2c5 to your computer and use it in GitHub Desktop.
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :account do
name "MyString"
factory :account_with_projects do
transient do
projects_count 2
end
after(:create) do |account, evaluator|
create_list(:project, evaluator.projects_count, account: account)
end
end
end
end
 Failure/Error: let(:user) { FactoryGirl.create :user }
 NoMethodError:
   undefined method `projects_count' for #<FactoryGirl::SyntaxRunner:0x007fb36a4a78b8>
FactoryGirl.define do
factory :user do
name 'MyString'
email 'email@email.com'
password 'password'
after(:build) do |user|
user.password_confirmation = user.password
user.confirm!
end
account_with_projects
end
end
@matt-wratt
Copy link

# Read about factories at https://github.com/thoughtbot/factory_girl

FactoryGirl.define do
  factory :account do
    name "MyString"
    trait :with_projects do
      transient do
        projects_count 2
      end

      after(:create) do |account, evaluator|
        create_list(:project, evaluator.projects_count, account: account)
      end
    end

    factory :account_with_projects, traits: [:with_projects]
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment