Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Commits on Jun 8, 2012
  1. @joshuaclayton
Commits on May 18, 2012
  1. @joshuaclayton

    Optionally disable duplicate assignment of attributes in initialize_with

    joshuaclayton authored
    By setting:
    
        FactoryGirl.duplicate_attribute_assignment_from_initialize_with =
    false
    
    This turns off duplicate assignment of attributes accessed from
    initialize_with. This means any attributes accessed from the factory and
    assigned in the initialize_with block won't be subsequently set after
    the object has been instantiated.
    
    This will be the default functionality in 4.0.
    
    Closes #345
Commits on May 12, 2012
  1. @joshuaclayton

    Allow initialize_with defined for all factories

    joshuaclayton authored
    This allows users to define initialize_with for every factory run through
    factory_girl.
    
        FactoryGirl.define do
          initialize_with { new("John Doe") }
        end
    
    If you want to override this default, set it per factory or in a trait
    (and include the trait).
    
    Closes #342
  2. @joshuaclayton

    Allow to_create defined for all factories

    joshuaclayton authored
    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
Commits on May 4, 2012
  1. @joshuaclayton

    Introduce new callback syntax

    Josh Clayton and Jason Draper authored joshuaclayton committed
    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.
Commits on Apr 24, 2012
  1. @joshuaclayton
  2. @joshuaclayton
  3. @joshuaclayton
  4. @joshuaclayton

    Fix dashes

    joshuaclayton authored
  5. @joshuaclayton
  6. @joshuaclayton
  7. @joshuaclayton
Commits on Apr 20, 2012
  1. @joshuaclayton

    Add documentation to using syntax methods inside dynamic attributes

    Ben Zhang and Josh Clayton authored joshuaclayton committed
    Closes #355
Commits on Apr 19, 2012
  1. @mark-rushakoff
Commits on Apr 6, 2012
  1. @joshuaclayton

    Clean up

    joshuaclayton authored
  2. @kristianmandrup @joshuaclayton
Commits on Mar 31, 2012
  1. @joshuaclayton
  2. @joshuaclayton
Commits on Mar 27, 2012
  1. @subelsky
Commits on Mar 16, 2012
  1. @joshuaclayton

    Remove Rails 2 support

    joshuaclayton authored
Commits on Feb 17, 2012
  1. @joshuaclayton
  2. @joshuaclayton
  3. @joshuaclayton
Commits on Feb 10, 2012
  1. @joshuaclayton

    Proxy => Strategy

    joshuaclayton authored
Commits on Feb 8, 2012
  1. @weppos @joshuaclayton
Commits on Jan 29, 2012
  1. @carlosantoniodasilva
Commits on Jan 23, 2012
  1. @jferris
Commits on Jan 20, 2012
  1. @joshuaclayton

    Implement initialize_with to allow overriding object instantiation

    joshuaclayton authored
    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
Commits on Jan 13, 2012
  1. @dasch @joshuaclayton
Commits on Nov 18, 2011
  1. @joshuaclayton

    Traits can be added to factories when the factory creates an instance

    joshuaclayton authored
    This allows for traits to be used with normal factories without having
    to name every single factory that uses one (or many) traits.
    
    So, instead of creating male_admin and female_admin factories:
    
        FactoryGirl.define do
          factory :user do
            trait(:admin)  { admin true }
            trait(:male)   { gender "Male" }
            trait(:female) { gender "Female" }
    
            factory :male_admin,   :traits => [:male, :admin]
            factory :female_admin, :traits => [:admin, :female]
          end
        end
    
        FactoryGirl.create(:male_admin)
        FactoryGirl.create(:female_admin)
    
    You could just create a user with those traits assigned:
    
        FactoryGirl.create(:user, :admin, :male)
        FactoryGirl.create(:user, :admin, :female)
    
    This can be combined with attribute overrides as expected.
    
        FactoryGirl.create(:user, :admin, :male,   :name => "John Doe")
        FactoryGirl.create(:user, :admin, :female, :name => "Jane Doe")
Commits on Nov 9, 2011
  1. @gabebw

    Use correct module in docs.

    gabebw authored
Commits on Oct 31, 2011
  1. @agronemann @joshuaclayton

    Fixing typo in GETTING_STARTED.md

    agronemann authored joshuaclayton committed
Commits on Oct 14, 2011
  1. @justinko @joshuaclayton
Commits on Oct 9, 2011
  1. @joshuaclayton

    Change syntax for ignoring attributes to use block syntax instead of

    joshuaclayton authored
    calling ignore on individual declarations.
    
    Old syntax:
    
        factory :user do
          rockstar(true).ignore
          four { 2 + 2 }.ignore
    
          name { "John Doe#{" - Rockstar" if rockstar}" }
        end
    
    New syntax:
    
        factory :user do
          ignore do
            rockstar true
            four     { 2 + 2 }
          end
    
          name { "John Doe#{" - Rockstar" if rockstar}" }
        end
Commits on Sep 23, 2011
  1. @joshuaclayton

    Introduce declarations

    Joe Ferris and Josh Clayton authored joshuaclayton committed
    Declarations are another layer of abstraction between defining the
    factories via the DSL and compiling the factories and their attributes.
    
    Declarations know how to return their attribute(s), and running a
    factory compiles the declarations before building all attributes on the
    factory. This moves all the attribute compilation logic into one
    centralized location on the Factory instance, which means traits (and
    potentially other features down the road) can have individual attributes
    overridden within child factories or through FactoryGirl.modify
    
    Closes #205
Something went wrong with that request. Please try again.