Sha256: 7684b0a8ad6e51390df3dfae9c779c2245da87c1ded73beeee1c444b273b5bc6

Contents?: true

Size: 1.04 KB

Versions: 56

Compression:

Stored size: 1.04 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)
            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

56 entries across 51 versions & 5 rubygems

Version Path
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/factory_girl-2.6.4/lib/factory_girl/syntax/blueprint.rb
challah-0.6.2 vendor/bundle/gems/factory_girl-2.6.1/lib/factory_girl/syntax/blueprint.rb
challah-0.6.1 vendor/bundle/gems/factory_girl-2.6.1/lib/factory_girl/syntax/blueprint.rb
challah-0.6.1 vendor/bundle/gems/factory_girl-2.5.1/lib/factory_girl/syntax/blueprint.rb
challah-0.6.0 vendor/bundle/gems/factory_girl-2.6.1/lib/factory_girl/syntax/blueprint.rb
challah-0.6.0 vendor/bundle/gems/factory_girl-2.5.1/lib/factory_girl/syntax/blueprint.rb
challah-0.5.4 vendor/bundle/gems/factory_girl-2.6.1/lib/factory_girl/syntax/blueprint.rb
challah-0.5.4 vendor/bundle/gems/factory_girl-2.5.1/lib/factory_girl/syntax/blueprint.rb
challah-0.5.3 vendor/bundle/gems/factory_girl-2.6.1/lib/factory_girl/syntax/blueprint.rb
challah-0.5.3 vendor/bundle/gems/factory_girl-2.5.1/lib/factory_girl/syntax/blueprint.rb
challah-0.5.2 vendor/bundle/gems/factory_girl-2.5.1/lib/factory_girl/syntax/blueprint.rb
challah-0.5.2 vendor/bundle/gems/factory_girl-2.6.1/lib/factory_girl/syntax/blueprint.rb
factory_girl-2.6.4 lib/factory_girl/syntax/blueprint.rb
factory_girl-2.6.3 lib/factory_girl/syntax/blueprint.rb
factory_girl-2.6.2 lib/factory_girl/syntax/blueprint.rb
challah-0.5.1 vendor/bundle/gems/factory_girl-2.6.1/lib/factory_girl/syntax/blueprint.rb
factory_girl-2.6.1 lib/factory_girl/syntax/blueprint.rb
challah-0.5.0 vendor/bundle/gems/factory_girl-2.5.1/lib/factory_girl/syntax/blueprint.rb
factory_girl-2.6.0 lib/factory_girl/syntax/blueprint.rb
factory_girl-2.5.2 lib/factory_girl/syntax/blueprint.rb