Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Example factories.rb file

Ponomarev Nikolay edited this page · 7 revisions

Here's a sample test/factories.rb:

FactoryGirl.define do
  sequence(:email) { |n| "person-#{n}@example.com" }
  sequence(:count)

  factory :user do
    name "Regular Doe"

    trait(:male)   { gender "Male" }
    trait(:female) { gender "Female" }
    trait(:admin)  { admin  true }
  end

  factory :article do
    sequence(:title) { |n| "Title #{n}" }
    comments_allowed false
    styles           "styles here"

    factory :unpublished_article do
      published false
    end

    factory :article_with_comments do
      ignore do
        comments_count 3
      end

      after(:create) do |article, evaluator|
        FactoryGirl.create_list(:comment, evaluator.comments_count, :article => article)
      end
    end
  end

  factory :page do
    sequence(:title) { |n| "Page #{n}" }
    body             { Forgery::LoremIpsum.paragraphs(5) }
    styles           "styles here"
  end

  factory :comment do
    article
    email
    body { Forgery::LoremIpsum.sentence }
    full_name "Commenter Bob"
  end
end
Something went wrong with that request. Please try again.