Retain stubs on subject for submatchers.

This commit is contained in:
Dimitrij Denissenko 2013-07-10 18:05:41 +01:00 committed by Jason Draper
parent e40f778515
commit fce5ee6777
2 changed files with 14 additions and 1 deletions

View File

@ -122,7 +122,7 @@ module Shoulda # :nodoc:
end
def failing_submatchers
@failing_submatchers ||= @submatchers.select { |matcher| !matcher.matches?(@subject.dup) }
@failing_submatchers ||= @submatchers.select { |matcher| !matcher.matches?(@subject) }
end
def allowed_types

View File

@ -121,6 +121,19 @@ describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher do
end
end
context 'when the subject is stubbed' do
it 'retains stubs on submatchers' do
subject = define_model :example, :attr => :string do
validates_numericality_of :attr, :odd => true
before_validation :set_attr!
def set_attr!; self.attr = 5 end
end.new
subject.stubs(:set_attr!)
subject.should matcher.odd
end
end
def validating_numericality(options = {})
define_model :example, :attr => :string do
validates_numericality_of :attr, options