Sha256: c56601bd15af01096cdc0670e7b68f177bdb8a46a732ec74b6ca3f18f9227687

Contents?: true

Size: 1.2 KB

Versions: 2

Compression:

Stored size: 1.2 KB

Contents

module FactoryGirl

  # Raised when defining an invalid attribute:
  # * Defining an attribute which has a name ending in "="
  # * Defining an attribute with both a static and lazy value
  # * Defining an attribute twice in the same factory
  class AttributeDefinitionError < RuntimeError
  end

  class Attribute #:nodoc:
    include Comparable

    attr_reader :name, :ignored

    def initialize(name)
      @name = name.to_sym
      @ignored = false
      ensure_non_attribute_writer!
    end

    def ignore
      @ignored = true
    end

    def add_to(proxy)
    end

    def association?
      false
    end

    def priority
      1
    end

    def aliases_for?(attr)
      FactoryGirl.aliases_for(attr).include?(name)
    end

    def <=>(another)
      return nil unless another.is_a? Attribute
      self.priority <=> another.priority
    end

    def ==(another)
      self.object_id == another.object_id
    end

    private

    def ensure_non_attribute_writer!
      if @name.to_s =~ /=$/
        attribute_name = $`
        raise AttributeDefinitionError,
          "factory_girl uses 'f.#{attribute_name} value' syntax " +
          "rather than 'f.#{attribute_name} = value'"
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
factory_girl-2.1.2 lib/factory_girl/attribute.rb
factory_girl-2.1.0 lib/factory_girl/attribute.rb