Sha256: ca3c565450fbbfe5d7725322a5bed93d977f9d2a5d1c48d71f7983b2d7379fde

Contents?: true

Size: 665 Bytes

Versions: 7

Compression:

Stored size: 665 Bytes

Contents

# frozen_string_literal: true

FactoryBot.define do
  factory :use, class: Cookbook::Use do
    use_in { pick_from_models(%w[Recipe HowTo]) }
    use_of { pick_from_models(%w[Ingredient Supply Tool]) }
    quantity_minimum { 1.5 }
    quantity_maximum { 3 }
    unit { ['cups', nil, 'grams', 'pinches'].sample }
    sort { 1 }
    note { ['for', %w[health fun wisdom].sample].join(' ') }
    preparation { ['crushed', nil, 'boiled', 'greased'].sample }
  end
end

def pick_from_models(model_names)
  model_name = model_names.sample
  pick_item_from(model_name)
end

def pick_item_from(model_name)
  model = model_name.constantize
  model.find(model.ids.sample)
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
cookbook-0.1.6 spec/factories/uses.rb
cookbook-0.1.5 spec/factories/uses.rb
cookbook-0.1.4 spec/factories/uses.rb
cookbook-0.1.3 spec/factories/uses.rb
cookbook-0.1.2 spec/factories/uses.rb
cookbook-0.1.1 spec/factories/uses.rb
cookbook-0.1.0 spec/factories/uses.rb