Sha256: 1cd6e9f82975dfcfebcf9eff52fee4b7d976d46e36beb5117c1f52f1a3b4286f

Contents?: true

Size: 959 Bytes

Versions: 3

Compression:

Stored size: 959 Bytes

Contents

require_relative 'helpers/model_builder'

module UnitTests
  class RecordValidatingConfirmationBuilder
    include ModelBuilder

    def initialize(options)
      @options = options
    end

    def model
      @_model ||= create_model
    end

    def model_name
      'Example'
    end

    def record
      model.new
    end

    def message=(message)
      options[:message] = message
    end

    def attribute_to_confirm
      :attribute_to_confirm
    end
    alias_method :attribute, :attribute_to_confirm

    def confirmation_attribute
      :"#{attribute_to_confirm}_confirmation"
    end

    def attribute_that_receives_error
      confirmation_attribute
    end

    protected

    attr_reader :options

    private

    def create_model
      _attribute = attribute_to_confirm
      _options = options

      define_model(model_name, _attribute => :string) do
        validates_confirmation_of(_attribute, _options)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
shoulda-matchers-3.0.1 spec/support/unit/record_validating_confirmation_builder.rb
shoulda-matchers-3.0.0 spec/support/unit/record_validating_confirmation_builder.rb
shoulda-matchers-3.0.0.rc1 spec/support/unit/record_validating_confirmation_builder.rb