Sha256: 26476d27d8a779bbcba7f9f9ad1119779a52dcf8c31323c04e0289da3e423ad8

Contents?: true

Size: 1.38 KB

Versions: 72

Compression:

Stored size: 1.38 KB

Contents

module FactoryGirl
  module Syntax

    # Adds a Sham module, which provides an alternate interface to
    # FactoryGirl::Sequence.
    #
    # Usage:
    #
    #   require 'factory_girl/syntax/sham'
    #
    #   Sham.email {|n| "somebody#{n}@example.com" }
    #
    #   FactoryGirl.define do
    #     factory :user do
    #       email
    #     end
    #   end
    #
    # Note that you can also use Faker, but it is recommended that you simply
    # use a sequence as in the above example, as factory_girl does not provide
    # protection against duplication in randomized sequences, and a randomized
    # value does not provide any tangible benefits over an ascending sequence.
    #
    # This syntax was derived from Pete Yandell's machinist.
    # @api private
    module Sham
      module Sham
        def self.method_missing(name, *args, &block)
          if block_given?
            ActiveSupport::Deprecation.warn 'Sham.sequence is deprecated; use the FactoryGirl.define syntax instead', caller
            start_value = args.first
            FactoryGirl.register_sequence(Sequence.new(name, start_value || 1, &block))
          else
            FactoryGirl.sequence_by_name(name).next
          end
        end

        # overrides name on Module
        def self.name(&block)
          method_missing('name', &block)
        end
      end
    end
  end
end

include FactoryGirl::Syntax::Sham

Version data entries

72 entries across 69 versions & 5 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/syntax/sham.rb
classiccms-0.7.4 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/syntax/sham.rb
classiccms-0.7.3 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/syntax/sham.rb
classiccms-0.7.2 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/syntax/sham.rb
classiccms-0.7.1 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/syntax/sham.rb
classiccms-0.7.0 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/syntax/sham.rb
classiccms-0.6.9 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/syntax/sham.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.0.pre/vendor/bundle/gems/factory_girl-3.6.1/lib/factory_girl/syntax/sham.rb
challah-rolls-0.2.0 vendor/bundle/gems/factory_girl-3.6.1/lib/factory_girl/syntax/sham.rb
classiccms-0.6.8 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/syntax/sham.rb
classiccms-0.6.7 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/syntax/sham.rb
factory_girl-3.6.2 lib/factory_girl/syntax/sham.rb
classiccms-0.6.6 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/syntax/sham.rb
classiccms-0.6.5 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/syntax/sham.rb
classiccms-0.6.4 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/syntax/sham.rb
classiccms-0.6.3 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/syntax/sham.rb
classiccms-0.6.2 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/syntax/sham.rb
classiccms-0.6.1 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/syntax/sham.rb
classiccms-0.6.0 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/syntax/sham.rb
classiccms-0.5.17 vendor/bundle/gems/factory_girl-3.3.0/lib/factory_girl/syntax/sham.rb