Class: FactoryGirlWeb::Fixture
- Inherits:
-
Object
- Object
- FactoryGirlWeb::Fixture
- Includes:
- ActiveModel::Model
- Defined in:
- app/models/factory_girl_web/fixture.rb
Instance Attribute Summary collapse
-
#amount ⇒ Object
Returns the value of attribute amount.
-
#name ⇒ Object
Returns the value of attribute name.
-
#traits ⇒ Object
Returns the value of attribute traits.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#amount ⇒ Object
Returns the value of attribute amount.
5 6 7 |
# File 'app/models/factory_girl_web/fixture.rb', line 5 def amount @amount end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'app/models/factory_girl_web/fixture.rb', line 5 def name @name end |
#traits ⇒ Object
Returns the value of attribute traits.
5 6 7 |
# File 'app/models/factory_girl_web/fixture.rb', line 5 def traits @traits end |
Class Method Details
.all ⇒ Object
38 39 40 |
# File 'app/models/factory_girl_web/fixture.rb', line 38 def all factories.keys.map { |name| new(name: name, amount: 1) } end |
.factories ⇒ Object
42 43 44 45 46 47 48 |
# File 'app/models/factory_girl_web/fixture.rb', line 42 def factories @factories ||= begin FactoryGirl.factories.sort_by(&:name).each_with_object(HashWithIndifferentAccess.new) do |factory, h| h[factory.name] = factory.defined_traits.map(&:name) end end end |
Instance Method Details
#create ⇒ Object
14 15 16 17 18 19 20 |
# File 'app/models/factory_girl_web/fixture.rb', line 14 def create return unless valid? ActiveRecord::Base.transaction do FactoryGirl.create_list(name.to_sym, amount.to_i, *formatted_traits) end end |
#defined_traits ⇒ Object
26 27 28 |
# File 'app/models/factory_girl_web/fixture.rb', line 26 def defined_traits factories[name] || [] end |
#name_i18n ⇒ Object
22 23 24 |
# File 'app/models/factory_girl_web/fixture.rb', line 22 def name_i18n name.to_s.classify.safe_constantize.try(:model_name).try(:human) || name end |