Sha256: ce59d344d50f504408bd95dfcd15d7cf7567bcdf0d358b845bae5a953d3a4a07

Contents?: true

Size: 867 Bytes

Versions: 10

Compression:

Stored size: 867 Bytes

Contents

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

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
shoulda-matchers-6.4.0 lib/shoulda/matchers/active_model/helpers.rb
shoulda-matchers-6.3.1 lib/shoulda/matchers/active_model/helpers.rb
shoulda-matchers-6.3.0 lib/shoulda/matchers/active_model/helpers.rb
shoulda-matchers-6.2.0 lib/shoulda/matchers/active_model/helpers.rb
shoulda-matchers-6.1.0 lib/shoulda/matchers/active_model/helpers.rb
shoulda-matchers-6.0.0 lib/shoulda/matchers/active_model/helpers.rb
shoulda-matchers-5.3.0 lib/shoulda/matchers/active_model/helpers.rb
shoulda-matchers-5.2.0 lib/shoulda/matchers/active_model/helpers.rb
shoulda-matchers-5.1.0 lib/shoulda/matchers/active_model/helpers.rb
shoulda-matchers-5.0.0 lib/shoulda/matchers/active_model/helpers.rb