Module: Ubazu::Rspec::Matchers::ActiveRecord::Helpers
- Defined in:
- lib/ubazu/rspec/matchers/active_record/helpers.rb
Instance Method Summary collapse
-
#default_error_message(key, values = {}) ⇒ Object
Helper method that determines the default error message used by Active Record.
-
#pretty_error_messages(obj) ⇒ Object
:nodoc:.
Instance Method Details
#default_error_message(key, values = {}) ⇒ Object
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.
(:blank)
(:too_short, :count => 5)
(:too_long, :count => 60)
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/ubazu/rspec/matchers/active_record/helpers.rb', line 20 def (key, values = {}) if Object.const_defined?(:I18n) # Rails >= 2.2 result = I18n.translate("activerecord.errors.messages.#{key}", values) if result =~ /^translation missing/ I18n.translate("errors.messages.#{key}", values) else result end else # Rails <= 2.1.x ::ActiveRecord::Errors.[key] % values[:count] end end |
#pretty_error_messages(obj) ⇒ Object
:nodoc:
6 7 8 9 10 11 |
# File 'lib/ubazu/rspec/matchers/active_record/helpers.rb', line 6 def (obj) # :nodoc: obj.errors.map do |a, m| msg = "#{a} #{m}" msg << " (#{obj.send(a).inspect})" unless a.to_sym == :base end end |