Correct behavior of with_message with ensures_length_of and is_equal_to matchers
This commit is contained in:
parent
a6778f165b
commit
9d89839bbd
3
NEWS.md
3
NEWS.md
|
@ -1,5 +1,8 @@
|
||||||
# HEAD
|
# HEAD
|
||||||
|
|
||||||
|
* Fix `ensure_length_of` so that it uses the right message to validate when
|
||||||
|
`is_equal_to` is specified in conjunction with a custom message.
|
||||||
|
|
||||||
* Fix Rails/Test::Unit integration to ensure that the test case classes we are
|
* Fix Rails/Test::Unit integration to ensure that the test case classes we are
|
||||||
re-opening actually exist.
|
re-opening actually exist.
|
||||||
|
|
||||||
|
|
|
@ -68,7 +68,6 @@ module Shoulda # :nodoc:
|
||||||
end
|
end
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
alias_method :with_message, :with_short_message
|
|
||||||
|
|
||||||
def with_long_message(message)
|
def with_long_message(message)
|
||||||
if message
|
if message
|
||||||
|
@ -77,6 +76,14 @@ module Shoulda # :nodoc:
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def with_message(message)
|
||||||
|
if message
|
||||||
|
@short_message = message
|
||||||
|
@long_message = message
|
||||||
|
end
|
||||||
|
self
|
||||||
|
end
|
||||||
|
|
||||||
def description
|
def description
|
||||||
description = "ensure #{@attribute} has a length "
|
description = "ensure #{@attribute} has a length "
|
||||||
if @options.key?(:minimum) && @options.key?(:maximum)
|
if @options.key?(:minimum) && @options.key?(:maximum)
|
||||||
|
|
|
@ -98,6 +98,13 @@ describe Shoulda::Matchers::ActiveModel::EnsureLengthOfMatcher do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'an attribute with a custom equal validation' do
|
||||||
|
it 'accepts ensuring the correct exact length' do
|
||||||
|
validating_length(:is => 4, :message => 'foobar').
|
||||||
|
should ensure_length_of(:attr).is_equal_to(4).with_message(/foo/)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'an attribute without a length validation' do
|
context 'an attribute without a length validation' do
|
||||||
it 'rejects ensuring a minimum length' do
|
it 'rejects ensuring a minimum length' do
|
||||||
define_model(:example, :attr => :string).new.
|
define_model(:example, :attr => :string).new.
|
||||||
|
|
Loading…
Reference in New Issue