Sha256: 872122bf44b6b1c4efccea669912113789ac858fb5e9e63e96958abbc9623eaa

Contents?: true

Size: 919 Bytes

Versions: 3

Compression:

Stored size: 919 Bytes

Contents

module FactoryGirl
  module Syntax

    # Extends ActiveRecord::Base to provide a make class method, which is a
    # shortcut for Factory.create.
    #
    # Usage:
    #
    #   require 'factory_girl/syntax/make'
    #
    #   FactoryGirl.define do
    #     factory :user do
    #       name 'Billy Bob'
    #       email 'billy@bob.example.com'
    #     end
    #   end
    #
    #   User.make(:name => 'Johnny')
    #
    # This syntax was derived from Pete Yandell's machinist.
    module Make
      module ActiveRecord #:nodoc:

        def self.included(base) # :nodoc:
          base.extend ClassMethods
        end

        module ClassMethods #:nodoc:

          def make(overrides = {})
            FactoryGirl.factory_by_name(name.underscore).run(Proxy::Create, overrides)
          end

        end

      end
    end
  end
end

ActiveRecord::Base.send(:include, FactoryGirl::Syntax::Make::ActiveRecord)

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
vitalish-factory_girl-1.2.5 lib/factory_girl/syntax/make.rb
vitalish-factory_girl-1.2.4 lib/factory_girl/syntax/make.rb
factory_girl-2.0.0.beta1 lib/factory_girl/syntax/make.rb