Sha256: 98c3315f279f292f7560183f5d07286dd4de950fe5fc61fd7cd2a6d5d204c55d

Contents?: true

Size: 1.02 KB

Versions: 59

Compression:

Stored size: 1.02 KB

Contents

module FactoryGirl
  module Syntax

    # Extends ActiveRecord::Base to provide a make class method, which is a
    # shortcut for FactoryGirl.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 = {})
            FactoryRunner.new(name.underscore, Strategy::Build, [overrides]).run
          end

          def make!(overrides = {})
            FactoryRunner.new(name.underscore, Strategy::Create, [overrides]).run
          end

        end

      end
    end
  end
end

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

Version data entries

59 entries across 59 versions & 4 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/make.rb
classiccms-0.7.4 vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/make.rb
classiccms-0.7.3 vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/make.rb
classiccms-0.7.2 vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/make.rb
classiccms-0.7.1 vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/make.rb
classiccms-0.7.0 vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/make.rb
classiccms-0.6.9 vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/make.rb
classiccms-0.6.8 vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/make.rb
classiccms-0.6.7 vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/make.rb
classiccms-0.6.6 vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/make.rb
classiccms-0.6.5 vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/make.rb
classiccms-0.6.4 vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/make.rb
classiccms-0.6.3 vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/make.rb
classiccms-0.6.2 vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/make.rb
classiccms-0.6.1 vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/make.rb
classiccms-0.6.0 vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/make.rb
classiccms-0.5.17 vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/make.rb
classiccms-0.5.16 vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/make.rb
classiccms-0.5.15 vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/make.rb
classiccms-0.5.14 vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/make.rb