Sha256: 26a023d3caab80e7e8836040b11baaa073aeae95228cc4acba169d9637ef89d8

Contents?: true

Size: 848 Bytes

Versions: 4

Compression:

Stored size: 848 Bytes

Contents

module UnitTests
  class Attribute
    attr_reader :name, :column_type, :column_options

    DEFAULT_COLUMN_TYPE = :string
    DEFAULT_COLUMN_OPTIONS = {
      null: false,
      array: false
    }

    def initialize(args)
      @args = args
    end

    def name
      args.fetch(:name)
    end

    def column_type
      args.fetch(:column_type, DEFAULT_COLUMN_TYPE)
    end

    def column_options
      DEFAULT_COLUMN_OPTIONS.
        merge(args.fetch(:column_options, {})).
        merge(type: column_type)
    end

    def array?
      column_options[:array]
    end

    def default_value
      args.fetch(:default_value) do
        if column_options[:null]
          nil
        else
          Shoulda::Matchers::Util.dummy_value_for(value_type, array: array?)
        end
      end
    end

    protected

    attr_reader :args
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
shoulda-matchers-3.1.3 spec/support/unit/attribute.rb
shoulda-matchers-3.1.2 spec/support/unit/attribute.rb
shoulda-matchers-3.1.1 spec/support/unit/attribute.rb
shoulda-matchers-3.1.0 spec/support/unit/attribute.rb