Module: TestProf::FactoryDefault::FabricationPatch::DefaultExt
- Defined in:
- lib/test_prof/factory_default/fabrication_patch.rb
Instance Method Summary collapse
- #create(name, overrides = {}, &block) ⇒ Object
- #create_default(name, overrides = {}, &block) ⇒ Object
- #get_fabricate_default(name, **overrides) ⇒ Object
- #set_fabricate_default(name, obj, **opts) ⇒ Object
- #skip_fabricate_default(&block) ⇒ Object
Instance Method Details
#create(name, overrides = {}, &block) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/test_prof/factory_default/fabrication_patch.rb', line 29 def create(name, overrides = {}, &block) self.fabrication_depth += 1 # We do not support defaults for objects created with attribute blocks return super if block return super if fabrication_depth < 2 FactoryDefault.get(name, nil, overrides, **{}) || FactoryDefault.profiler.instrument(name, nil, overrides) { super } ensure self.fabrication_depth -= 1 end |
#create_default(name, overrides = {}, &block) ⇒ Object
7 8 9 10 |
# File 'lib/test_prof/factory_default/fabrication_patch.rb', line 7 def create_default(name, overrides = {}, &block) obj = ::Fabricate.create(name, overrides, &block) set_fabricate_default(name, obj) end |
#get_fabricate_default(name, **overrides) ⇒ Object
21 22 23 |
# File 'lib/test_prof/factory_default/fabrication_patch.rb', line 21 def get_fabricate_default(name, **overrides) FactoryDefault.get(name, nil, overrides, skip_stats: true) end |
#set_fabricate_default(name, obj, **opts) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/test_prof/factory_default/fabrication_patch.rb', line 12 def set_fabricate_default(name, obj, **opts) FactoryDefault.register( name, obj, preserve_attributes: FactoryDefault.config.preserve_attributes, preserve_traits: FactoryDefault.config.preserve_traits, **opts ) end |
#skip_fabricate_default(&block) ⇒ Object
25 26 27 |
# File 'lib/test_prof/factory_default/fabrication_patch.rb', line 25 def skip_fabricate_default(&block) FactoryDefault.disable!(&block) end |