module Shoulda::Matchers::ActiveModel::Helpers

@private

Public Instance Methods

default_error_message(type, options = {}) click to toggle source
# File lib/shoulda/matchers/active_model/helpers.rb, line 27
def default_error_message(type, options = {})
  model_name = options.delete(:model_name)
  attribute = options.delete(:attribute)
  instance = options.delete(:instance)

  RailsShim.generate_validation_message(
    instance,
    attribute.to_sym,
    type,
    model_name,
    options
  )
end
pretty_error_messages(obj) click to toggle source
# File lib/shoulda/matchers/active_model/helpers.rb, line 6
def pretty_error_messages(obj)
  obj.errors.map do |attribute, message|
    full_message = message.dup.inspect
    parenthetical_parts = []

    unless attribute.to_sym == :base
      parenthetical_parts << "attribute: #{attribute}"

      if obj.respond_to?(attribute)
        parenthetical_parts << "value: #{obj.__send__(attribute).inspect}"
      end
    end

    if parenthetical_parts.any?
      full_message << " (#{parenthetical_parts.join(', ')})"
    end

    "* " + full_message
  end.join("\n")
end