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
ryu-sato 7663821cff
renew deprecated methods (#1444)
* renew deprecated methods

* replace "attribute_names" with the methods that exist in the Rails 5.2 and 6.0 APIs
2021-06-12 15:41:26 -03:00

35 lines
867 B
Ruby

module Shoulda
module Matchers
module ActiveModel
# @private
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")
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,
)
end
end
end
end
end