Add `failure_message_for_should_not` to `validate_numericality_of`
As well as to its submatchers: * OnlyIntegerMatcher * OddEvenNumberMatcher
This commit is contained in:
parent
d680e7d47b
commit
3cfa565e52
3
NEWS.md
3
NEWS.md
|
@ -1,5 +1,8 @@
|
|||
# HEAD
|
||||
|
||||
* Add missing `failure_message_for_should_not` implementations to
|
||||
`validate_numericality_of` and its submatchers
|
||||
|
||||
* Support validation contexts for testing validations `on: :create` and when using custom contexts like `model.valid?(:my_context)`.
|
||||
|
||||
* Fix a bug in validations with autosaved models.
|
||||
|
|
|
@ -37,6 +37,10 @@ module Shoulda # :nodoc:
|
|||
def failure_message_for_should
|
||||
@disallow_value_matcher.failure_message_for_should
|
||||
end
|
||||
|
||||
def failure_message_for_should_not
|
||||
@disallow_value_matcher.failure_message_for_should_not
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -27,6 +27,10 @@ module Shoulda # :nodoc:
|
|||
def failure_message_for_should
|
||||
@disallow_value_matcher.failure_message_for_should
|
||||
end
|
||||
|
||||
def failure_message_for_should_not
|
||||
@disallow_value_matcher.failure_message_for_should_not
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -64,7 +64,11 @@ module Shoulda # :nodoc:
|
|||
end
|
||||
|
||||
def failure_message_for_should
|
||||
submatcher_failure_messages.last
|
||||
submatcher_failure_messages_for_should.last
|
||||
end
|
||||
|
||||
def failure_message_for_should_not
|
||||
submatcher_failure_messages_for_should_not.last
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -85,10 +89,14 @@ module Shoulda # :nodoc:
|
|||
failing_submatchers.empty?
|
||||
end
|
||||
|
||||
def submatcher_failure_messages
|
||||
def submatcher_failure_messages_for_should
|
||||
failing_submatchers.map(&:failure_message_for_should)
|
||||
end
|
||||
|
||||
def submatcher_failure_messages_for_should_not
|
||||
failing_submatchers.map(&:failure_message_for_should_not)
|
||||
end
|
||||
|
||||
def failing_submatchers
|
||||
@failing_submatchers ||= @submatchers.select { |matcher| !matcher.matches?(@subject) }
|
||||
end
|
||||
|
|
|
@ -22,6 +22,14 @@ describe Shoulda::Matchers::ActiveModel::ValidateNumericalityOfMatcher do
|
|||
define_model(:example, :attr => :string).new.should_not matcher
|
||||
end
|
||||
|
||||
it 'rejects with the ActiveRecord :not_a_number message' do
|
||||
the_matcher = matcher
|
||||
|
||||
the_matcher.matches?(define_model(:example, :attr => :string).new)
|
||||
|
||||
the_matcher.failure_message_for_should_not.should include 'Did not expect errors to include "is not a number"'
|
||||
end
|
||||
|
||||
it 'rejects with the ActiveRecord :not_an_integer message' do
|
||||
the_matcher = matcher.only_integer
|
||||
|
||||
|
|
Loading…
Reference in New Issue