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

20 commits

Author SHA1 Message Date
Avielle
c716ce01b4 Replace 'girl' with 'bot' everywhere (#1051)
Also: add a deprecation warning to factory_girl, asking users to switch to
factory_bot

https://github.com/thoughtbot/factory_girl/issues/921
2017-10-20 15:20:28 -04:00
Waldyr
ec491192e5
Fix #aggregate_from_traits_and_self's complexity 2016-10-07 15:16:50 -04:00
Joshua Clayton
ed598ec54c Update repo to follow thoughtbot guide for whitespace in blocks 2013-12-14 22:33:15 -05:00
Potapov Sergey
664c426bd0 Fix memory leak: do not add trait duplications to @defined_traits
Closes #588
2013-12-13 15:12:48 -05:00
Joshua Clayton
36cb43e9b0 Add global callbacks
This allows callbacks (after :build, :create, etc.) to be defined at the
FactoryGirl level; this means that the callback will be invoked for all
factories. This is primarily to maintain consistency and follow the
principle of least surprise.

As usual, callbacks are applied from the lowest component to the
highest, meaning that global callbacks will be run after factory and
trait callbacks are run.

    FactoryGirl.define do
      after(:build) {|object| puts "Built #{object}" }

      factory :user
      # ...
    end

Closes #481
Closes #486
2013-02-08 11:24:35 -05: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
f7efc610fd Allow to_create defined for all factories
This allows users to define to_create for every factory run through
factory_girl.

    FactoryGirl.define do
      to_create {|instance| instance.persist! }
    end

If you want to override this default, set it per factory or in a trait
(and include the trait).

Closes #341
2012-05-12 18:10:02 -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
7e41f4f327 Allow checking if definition uses a custom to_create 2012-05-06 16:09:53 -04:00
Joshua Clayton
8ff5fc274a Move constructor to definition 2012-05-06 03:05:31 -04:00
Joshua Clayton
f1fd650048 Clean up documentation 2012-05-05 02:31:31 -04:00
Joshua Clayton
5b9aa488f6 Use Ruby 1.9's stabby lambdas 2012-04-20 16:59:39 -04:00
Joshua Clayton
6c29b11477 Use 1.9 hash syntax 2012-03-16 16:43:23 -04: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
065c6c1789 Fix issues with inline traits not taking precedence
Closes #242
2012-01-18 10:14:21 -05:00
Joshua Clayton
5bbbcb9edf Move logic of what to do to create an instance to the definition where it belongs 2011-11-25 18:07:06 -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
0124d42bf1 Fix callback handling from implicit traits 2011-10-30 23:17:03 -04:00
Joshua Clayton
41bc3ac5ff Add FactoryGirl::Definition
Both Factory and Trait have similar methods and interact with a
DefinitionProxy. The idea here is to move the interface DefinitionProxy
expects to a separate class and both Factory and Trait can delegate to
an instance of Definition.
2011-10-30 23:17:03 -04:00