Sha256: 6eb3191b9309a3ac1d69f5ecc24d3a9f0859685c6a90968b089c0ff6800b8642

Contents?: true

Size: 567 Bytes

Versions: 1

Compression:

Stored size: 567 Bytes

Contents

FactoryBot.define do
  factory :book do
    title { Faker::Company.catch_phrase }
    transient do
      author { Author.order("RANDOM()").first }
    end
    # the after(:create) yields two values; the user instance itself and the
    # evaluator, which stores all values from the factory, including transient
    # attributes; `create_list`'s second argument is the number of records
    # to create and we make sure the user is associated properly to the post
    after(:create) do |book, evaluator|
      evaluator.author.add_role(:author, book)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
friendly_id-method_scopes-0.3.7 spec/factories/book.rb