Permalink
Browse files

allow_values_for checks for any message unless otherwise given [#90 s…

…tatus:resolved].
  • Loading branch information...
1 parent 9eb9cff commit 1c81305cf0185767f6e441169ece886096116725 @josevalim josevalim committed Aug 25, 2009
@@ -1,3 +1,5 @@
+* allow_values_for checks for any message unless otherwise given [#90]
+
* Allow booleans to be given to validate_inclusion_of [#89]
* Allow allow_values_for and allow_mass_assignment_of matchers to be executed in
@@ -11,7 +11,7 @@ class AllowValuesForMatcher < Remarkable::ActiveRecord::Base #:nodoc:
collection_assertions :is_valid?, :is_invalid?, :allow_nil?, :allow_blank?
- default_options :message => :invalid
+ default_options :message => /.*/
before_assert do
first_value = @options[:in].is_a?(Array) ? @options[:in].first : @options[:in]
@@ -62,14 +62,16 @@ def interpolation_options
end
- # Ensures that the attribute can be set to the given values.
+ # Ensures that the attribute can be set to the given values. It checks
+ # for any message in the given attribute unless a :message is explicitely
+ # given.
#
# == Options
#
# * <tt>:allow_nil</tt> - when supplied, validates if it allows nil or not.
# * <tt>:allow_blank</tt> - when supplied, validates if it allows blank or not.
# * <tt>:message</tt> - value the test expects to find in <tt>errors.on(:attribute)</tt>.
- # Regexp, string or symbol. Default = <tt>I18n.translate('activerecord.errors.messages.invalid')</tt>
+ # Regexp, string or symbol. Default = <tt>/.*/</tt>
#
# == Examples
#
@@ -81,17 +83,6 @@ def allow_values_for(attribute, *args, &block)
AllowValuesForMatcher.new(attribute, options.merge!(:in => args), &block).spec(self)
end
- # Deprecated. Use allow_values_for instead.
- #
- def validate_format_of(*args)
- if caller[0] =~ /\macros.rb/
- warn "[DEPRECATION] should_validate_format_of is deprecated, use should_allow_values_for instead."
- else
- warn "[DEPRECATION] validate_format_of is deprecated, use allow_values_for instead. Called from #{caller[0]}."
- end
- allow_values_for(*args)
- end
-
end
end
end
@@ -38,9 +38,9 @@ def define_and_validate(options={})
describe 'matchers' do
it { should define_and_validate(:with => /X|Y|Z/).in('X', 'Y', 'Z') }
- it { should_not define_and_validate(:with => /X|Y|Z/).in('A') }
- it { should define_and_validate(:with => /X|Y|Z/, :message => 'valid').in('X', 'Y', 'Z').message('valid') }
+ it { should_not define_and_validate(:with => /X|Y|Z/).in('A') }
+ it { should_not define_and_validate(:with => /X|Y|Z/, :message => 'invalid').in('A') }
create_optional_boolean_specs(:allow_nil, self, :with => /X|Y|Z/)
create_optional_boolean_specs(:allow_blank, self, :with => /X|Y|Z/)
@@ -51,11 +51,6 @@ def define_and_validate(options={})
should_allow_values_for :title, 'X'
should_not_allow_values_for :title, 'A'
-
- describe 'deprecation' do
- it { should validate_format_of(:title, 'X') }
- should_not_validate_format_of :title, 'A'
- end
end
describe 'failures' do

0 comments on commit 1c81305

Please sign in to comment.