Class: Pickle::Adapter::FactoryBot
- Inherits:
-
Pickle::Adapter
- Object
- Pickle::Adapter
- Pickle::Adapter::FactoryBot
- Defined in:
- lib/pickle/adapter.rb
Overview
factory-girl adapter
Instance Attribute Summary
Attributes inherited from Pickle::Adapter
Class Method Summary collapse
Instance Method Summary collapse
- #build(attrs = {}) ⇒ Object
- #create(attrs = {}) ⇒ Object
-
#initialize(factory, factory_name) ⇒ FactoryBot
constructor
A new instance of FactoryBot.
Methods inherited from Pickle::Adapter
column_names, create_model, find_all_models, find_first_model, get_model, model_classes
Constructor Details
#initialize(factory, factory_name) ⇒ FactoryBot
Returns a new instance of FactoryBot.
116 117 118 119 120 121 122 |
# File 'lib/pickle/adapter.rb', line 116 def initialize(factory, factory_name) if defined? ::FactoryBot @klass, @name = factory.build_class, factory_name.to_s else @klass, @name = factory.build_class, factory.factory_name.to_s end end |
Class Method Details
.factories ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/pickle/adapter.rb', line 102 def self.factories if defined? ::FactoryBot factories = [] ::FactoryBot.factories.each do |factory| factory.names.each do |name| factories << new(factory, name) end end factories else (::Factory.factories.values rescue []).map {|factory| new(factory)} end end |
Instance Method Details
#build(attrs = {}) ⇒ Object
132 133 134 135 136 137 138 |
# File 'lib/pickle/adapter.rb', line 132 def build(attrs = {}) if defined? ::FactoryBot ::FactoryBot.build(@name, attrs) else Factory.build(@name, attrs) end end |
#create(attrs = {}) ⇒ Object
124 125 126 127 128 129 130 |
# File 'lib/pickle/adapter.rb', line 124 def create(attrs = {}) if defined? ::FactoryBot ::FactoryBot.create(@name, attrs) else Factory(@name, attrs) end end |