Sha256: 0811e35964e0b47ad7f346ad3a0f583c37eefbbae1f58d66305f747a246d0f3b

Contents?: true

Size: 1.45 KB

Versions: 28

Compression:

Stored size: 1.45 KB

Contents

module Shoulda # :nodoc:
  module Matchers
    module ActiveModel # :nodoc:
      module Helpers
        def pretty_error_messages(obj) # :nodoc:
          obj.errors.map do |attribute, model|
            msg = "#{attribute} #{model}"
            msg << " (#{obj.send(attribute).inspect})" unless attribute.to_sym == :base
          end
        end

        # Helper method that determines the default error message used by Active
        # Record.  Works for both existing Rails 2.1 and Rails 2.2 with the newly
        # introduced I18n module used for localization.
        #
        #   default_error_message(:blank)
        #   default_error_message(:too_short, :count => 5)
        #   default_error_message(:too_long, :count => 60)
        #   default_error_message(:blank, :model_name => 'user', :attribute => 'name')
        def default_error_message(key, options = {})
          model_name = options.delete(:model_name)
          attribute = options.delete(:attribute)
          default_translation = [ :"activerecord.errors.models.#{model_name}.#{key}",
                                  :"activerecord.errors.messages.#{key}",
                                  :"errors.attributes.#{attribute}.#{key}",
                                  :"errors.messages.#{key}" ]
          I18n.translate(:"activerecord.errors.models.#{model_name}.attributes.#{attribute}.#{key}",
            { :default => default_translation }.merge(options))
        end
      end
    end
  end
end

Version data entries

28 entries across 20 versions & 4 rubygems

Version Path
challah-1.0.0.beta vendor/bundle/gems/shoulda-matchers-1.4.2/lib/shoulda/matchers/active_model/helpers.rb
challah-0.9.1.beta.3 vendor/bundle/gems/shoulda-matchers-1.4.2/lib/shoulda/matchers/active_model/helpers.rb
devise_sociable-0.1.0 vendor/bundle/gems/shoulda-matchers-1.4.2/lib/shoulda/matchers/active_model/helpers.rb
challah-0.9.1.beta vendor/bundle/gems/shoulda-matchers-1.4.2/lib/shoulda/matchers/active_model/helpers.rb
challah-0.9.0 vendor/bundle/gems/shoulda-matchers-1.4.2/lib/shoulda/matchers/active_model/helpers.rb
shoulda-matchers-1.4.2 lib/shoulda/matchers/active_model/helpers.rb
challah-rolls-0.2.0 vendor/bundle/gems/shoulda-matchers-1.4.1/lib/shoulda/matchers/active_model/helpers.rb
challah-rolls-0.2.0 vendor/bundle/gems/shoulda-matchers-1.3.0/lib/shoulda/matchers/active_model/helpers.rb
challah-rolls-0.2.0 vendor/bundle/gems/shoulda-matchers-1.2.0/lib/shoulda/matchers/active_model/helpers.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.3/vendor/bundle/gems/shoulda-matchers-1.4.1/lib/shoulda/matchers/active_model/helpers.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.0.pre/vendor/bundle/gems/shoulda-matchers-1.2.0/lib/shoulda/matchers/active_model/helpers.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.3/vendor/bundle/gems/shoulda-matchers-1.3.0/lib/shoulda/matchers/active_model/helpers.rb
challah-0.8.3 vendor/bundle/gems/shoulda-matchers-1.3.0/lib/shoulda/matchers/active_model/helpers.rb
challah-0.8.3 vendor/bundle/gems/shoulda-matchers-1.4.1/lib/shoulda/matchers/active_model/helpers.rb
shoulda-matchers-1.4.1 lib/shoulda/matchers/active_model/helpers.rb
shoulda-matchers-1.4.0 lib/shoulda/matchers/active_model/helpers.rb
challah-0.8.1 vendor/bundle/gems/shoulda-matchers-1.3.0/lib/shoulda/matchers/active_model/helpers.rb
challah-rolls-0.1.0 vendor/bundle/gems/challah-0.8.0.pre/vendor/bundle/gems/shoulda-matchers-1.2.0/lib/shoulda/matchers/active_model/helpers.rb
challah-rolls-0.1.0 vendor/bundle/gems/shoulda-matchers-1.2.0/lib/shoulda/matchers/active_model/helpers.rb
challah-rolls-0.1.0 vendor/bundle/gems/shoulda-matchers-1.3.0/lib/shoulda/matchers/active_model/helpers.rb