mirror of
https://github.com/thoughtbot/shoulda-matchers.git
synced 2022-11-09 12:01:38 -05:00
Fix a bug in the pretty_error_messages helper.
* Fixes an issue where matchers would fail on models with an autosaved belongs_to association.
This commit is contained in:
parent
f1364514fa
commit
d1dc606cea
3 changed files with 19 additions and 1 deletions
2
NEWS.md
2
NEWS.md
|
@ -1,5 +1,7 @@
|
|||
# HEAD
|
||||
|
||||
* Fix a bug in validations with autosaved models.
|
||||
|
||||
* Fix maximum value detection for the `ensure_inclusion_of` and
|
||||
`ensure_exclusion_of` matchers.
|
||||
|
||||
|
|
|
@ -5,7 +5,10 @@ module Shoulda # :nodoc:
|
|||
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
|
||||
if attribute.to_sym != :base && obj.respond_to?(attribute)
|
||||
msg << " (#{obj.send(attribute).inspect})"
|
||||
end
|
||||
msg
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -70,6 +70,19 @@ describe Shoulda::Matchers::ActiveModel::ValidationMessageFinder do
|
|||
|
||||
description.should == 'no errors'
|
||||
end
|
||||
|
||||
it 'should not fetch attribute values for errors that were copied from an autosaved belongs_to association' do
|
||||
instance = define_model(:example) do
|
||||
validate do |record|
|
||||
record.errors.add('association.association_attribute', 'is invalid')
|
||||
end
|
||||
end.new
|
||||
finder = Shoulda::Matchers::ActiveModel::ValidationMessageFinder.new(instance, :attribute)
|
||||
|
||||
expected_messages = ['association.association_attribute is invalid']
|
||||
finder.messages_description.should == "errors: #{expected_messages}"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context '#source_description' do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue