mirror of
https://github.com/thoughtbot/factory_bot.git
synced 2022-11-09 11:43:51 -05:00
![]() Instead of calling before_create, after_build, after_create, or after_stub, you can now call: before(:create) {|instance| instance.name = "overridden!" } after(:create) {|instance| instance.name = "overridden!" } after(:build) {|instance| instance.name = "overridden!" } after(:stub) {|instance| instance.name = "overridden!" } Additionally, you can declare callbacks longhand: callback(:after_stub) {|instance| instance.name = "overridden!" } This allows for custom callbacks to be defined: callback(:custom_callback) {|instance| instance.name = "overridden!" } Which can then be used from a custom strategy: class CustomStrategy def association(runner); end def result(evaluation) evaluation.object.tap do |instance| evaluation.notify(:custom_callback, instance) end end end FactoryGirl.register_strategy(:custom, CustomStrategy) This would allow for calling: FactoryGirl.custom(:user) Which would return the user instance but execute the :custom_callback callback on the user instance first. |
||
---|---|---|
.. | ||
syntax | ||
activesupport_instrumentation_spec.rb | ||
aliases_spec.rb | ||
attribute_aliases_spec.rb | ||
attribute_existing_on_object_spec.rb | ||
attributes_for_spec.rb | ||
attributes_from_instance_spec.rb | ||
attributes_ordered_spec.rb | ||
build_list_spec.rb | ||
build_spec.rb | ||
build_stubbed_spec.rb | ||
callbacks_spec.rb | ||
create_list_spec.rb | ||
create_spec.rb | ||
define_child_before_parent_spec.rb | ||
definition_spec.rb | ||
definition_without_block_spec.rb | ||
initialize_with_spec.rb | ||
modify_factories_spec.rb | ||
modify_inherited_spec.rb | ||
nested_attributes_spec.rb | ||
overrides_spec.rb | ||
parent_spec.rb | ||
register_strategies_spec.rb | ||
sequence_spec.rb | ||
skip_create_spec.rb | ||
stub_spec.rb | ||
syntax_methods_within_dynamic_attributes_spec.rb | ||
traits_spec.rb | ||
transient_attributes_spec.rb |