1
0
Fork 0
mirror of https://github.com/thoughtbot/factory_bot.git synced 2022-11-09 11:43:51 -05:00
Commit graph

15 commits

Author SHA1 Message Date
Joshua Clayton
0c165ec993 Add DefinitionHierarchy to handle inheritance of some definition attributes
This includes #callbacks, #constructor, and #to_create. The reasoning
behind this is that we were mimicing an inheritance chain via methods;
now, we actually generate classes, which Factory maintains, who inherit
from their parent's hierarchy. We build the hierarchy during compilation
to conditionally define methods based on whether what we're dealing
with from the definition is actually meaningful. The base class
(DefinitionHierarchy) uses the defaults (an empty array for #callbacks
and the global #to_create and #constructor) so once we hit the top
level, if the definition doesn't set any overrides, we have a list of
sensible values.
2012-07-11 23:05:16 -04:00
Joshua Clayton
779eafccbd Fix various trait bugs so traits can be used within each other
The previous implementation of trait handling within the Definition
didn't account for when implicit traits were used within other traits.
This is useful if you have two different traits, but one depends on
another; for example, a refunded order and a completed order could both
have the attribute `completed_at` set, but refunded would additionally
have `refunded_at` set:

    FactoryGirl.define do
      factory :order do
        trait :completed do
          completed_at { 3.days.ago }
        end

        trait :refunded do
          completed
          refunded_at { 1.day.ago }
        end
      end
    end

This also tests to make sure that callbacks, custom constructors, and
creation overrides work correctly when implicit traits are used within
other traits.

Fixes #360
2012-06-15 20:08:42 -04:00
Joshua Clayton
0d4b5cb34e Fix initialize_with in the context of traits 2012-05-11 12:00:03 -04:00
Joshua Clayton
645afa9689 Fix to_create so it works when defined in a trait 2012-05-11 10:52:19 -04:00
Joshua Clayton
f1fd650048 Clean up documentation 2012-05-05 02:31:31 -04:00
Joshua Clayton
6c29b11477 Use 1.9 hash syntax 2012-03-16 16:43:23 -04:00
Joshua Clayton
7623531324 Remove default_strategy 2012-03-16 13:17:15 -04:00
Joshua Clayton
6cddb37ecb Move factory associations logic to evaluator_class
evaluator_class contains the fully-inherited list of attributes; this
includes parent classes, traits, etc. When calculating associations for
an individual factory, the factory should use inheritance to build the
list instead of merely accessing association attributes on itself.

Closes #293
2012-02-08 08:18:16 -05:00
Joshua Clayton
852eea84ff Minor code cleanup 2012-02-08 00:23:04 -05:00
Erik Ostrom
34c1bf9b70 Let Cucumber steps use inherited associations.
By making Factory#associations include the parent's associations.

https://github.com/thoughtbot/factory_girl/issues/292
2012-02-08 00:08:37 -05:00
Joshua Clayton
578036480f Implement initialize_with to allow overriding object instantiation
Factory Girl now allows factories to override object instantiation. This
means factories can use factory methods (e.g. methods other than new) as
well as pass arguments explicitly.

    factory :user do
      ignore do
        things { ["thing 1", "thing 2"] }
      end

      initialize_with { User.construct_with_things(things) }
    end

    factory :report_generator do
      ignore do
        name { "Generic Report" }
        data { {:foo => "bar", :baz => "buzz"} }
      end

      initialize_with { ReportGenerator.new(name, data) }
    end

Whitespace

Code recommendations
2012-01-20 15:37:36 -05:00
Joshua Clayton
f2e41389ea Factory evaluators use inheritance 2012-01-09 17:28:20 -05:00
Joshua Clayton
a1647ff988 NullObject's default strategy is create 2011-12-19 21:41:10 -05:00
Joshua Clayton
3114dcd935 Wrap up DeclarationList
DeclarationList knows how to generate an attribute
list, which never really made sense outside of being generated from
declarations. Now, the declaration list builds a list of attributes
which is combined in Factory#attributes with attributes from traits and
its parents.
2011-10-31 19:05:34 -04:00
Joshua Clayton
aee300aa90 Add NullFactory 2011-10-30 23:17:03 -04:00