Correct behavior of with_message with ensures_length_of and is_equal_to matchers

This commit is contained in:
joekur 2013-10-11 14:36:25 -05:00 committed by Elliot Winkler
parent a6778f165b
commit 9d89839bbd
3 changed files with 18 additions and 1 deletions

View File

@ -1,5 +1,8 @@
# 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
re-opening actually exist.

View File

@ -68,7 +68,6 @@ module Shoulda # :nodoc:
end
self
end
alias_method :with_message, :with_short_message
def with_long_message(message)
if message
@ -77,6 +76,14 @@ module Shoulda # :nodoc:
self
end
def with_message(message)
if message
@short_message = message
@long_message = message
end
self
end
def description
description = "ensure #{@attribute} has a length "
if @options.key?(:minimum) && @options.key?(:maximum)

View File

@ -98,6 +98,13 @@ describe Shoulda::Matchers::ActiveModel::EnsureLengthOfMatcher do
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
it 'rejects ensuring a minimum length' do
define_model(:example, :attr => :string).new.