1
0
Fork 0
mirror of https://github.com/thoughtbot/shoulda-matchers.git synced 2022-11-09 12:01:38 -05:00
thoughtbot--shoulda-matchers/lib/shoulda/matchers/active_model/helpers.rb

36 lines
867 B
Ruby
Raw Normal View History

module Shoulda
2010-12-15 17:34:19 -05:00
module Matchers
module ActiveModel
# @private
2010-12-15 17:34:19 -05:00
module Helpers
def pretty_error_messages(object)
format_validation_errors(object.errors)
end
def format_validation_errors(errors)
list_items = errors.to_hash.keys.map do |attribute|
messages = errors[attribute]
"* #{attribute}: #{messages}"
end
list_items.join("\n")
2010-12-15 17:34:19 -05:00
end
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,
)
2010-12-15 17:34:19 -05:00
end
end
end
end
end