Sha256: 691fb550f26598ff7600f087b6a23547ddff945ff3a21ab07b4e225910569d47

Contents?: true

Size: 1.16 KB

Versions: 54

Compression:

Stored size: 1.16 KB

Contents

module FactoryGirl
  module Syntax

    # Extends ActiveRecord::Base to provide a make class method, which is an
    # alternate syntax for defining factories.
    #
    # Usage:
    #
    #   require 'factory_girl/syntax/blueprint'
    #
    #   User.blueprint do
    #     name  { 'Billy Bob'             }
    #     email { 'billy@bob.example.com' }
    #   end
    #
    #   FactoryGirl.create(:user, name: 'Johnny')
    #
    # This syntax was derived from Pete Yandell's machinist.
    module Blueprint
      module ActiveRecord #:nodoc:

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

        module ClassMethods #:nodoc:

          def blueprint(&block)
            ActiveSupport::Deprecation.warn "Model.blueprint is deprecated; use the FactoryGirl.define syntax instead", caller
            instance = Factory.new(name.underscore, class: self)
            proxy = FactoryGirl::DefinitionProxy.new(instance)
            proxy.instance_eval(&block)
            FactoryGirl.register_factory(instance)
          end

        end

      end
    end
  end
end

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

Version data entries

54 entries across 54 versions & 4 rubygems

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