Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updating validates_exclusion_of to ActiveModel.

  • Loading branch information...
commit bf9bd1e414863a63607aa7c744bebe91879aa208 1 parent c9d55c9
@bryckbost bryckbost authored
View
1  UPGRADES
@@ -1,5 +1,6 @@
0.8 => ??
* [attribute]_before_typecast should become [attribute]_before_type_cast (note the extra _)
+ * Change validates_exclusion_of :within option to :in
0.7.6 => 0.8
* Proxy#owner has been removed in favor of Proxy#proxy_owner
View
2  lib/mongo_mapper/plugins/keys.rb
@@ -137,7 +137,7 @@ def create_validations_for(key)
end
if key.options[:not_in]
- validates_exclusion_of(attribute, :within => key.options[:not_in])
+ validates_exclusion_of(attribute, :in => key.options[:not_in])
end
if key.options[:length]
View
4 test/test_helper.rb
@@ -79,10 +79,10 @@ def drop_indexes(klass)
matcher.negative_failure_message = "#{receiver} had errors on #{attribute} #{receiver.errors.inspect}"
!receiver.errors[attribute].blank?
else
- actual = receiver.errors[:attribute]
+ actual = receiver.errors[attribute]
matcher.positive_failure_message = %Q(Expected error on #{attribute} to be "#{expected_message}" but was "#{actual}")
matcher.negative_failure_message = %Q(Expected error on #{attribute} not to be "#{expected_message}" but was "#{actual}")
- actual == expected_message
+ actual.include? expected_message
end
end
View
110 test/unit/test_validations.rb
@@ -157,59 +157,59 @@ class ValidationsTest < Test::Unit::TestCase
doc.should have_error_on(:name)
end
end
- #
- # context "validating exclusion of" do
- # should "throw error if enumerator not provided" do
- # @document.key :action, String
- # lambda {
- # @document.validates_exclusion_of :action
- # }.should raise_error(ArgumentError)
- # end
- #
- # should "work with validates_exclusion_of macro" do
- # @document.key :action, String
- # @document.validates_exclusion_of :action, :within => %w(kick run)
- #
- # doc = @document.new
- # doc.should_not have_error_on(:action)
- #
- # doc.action = 'fart'
- # doc.should_not have_error_on(:action)
- #
- # doc.action = 'kick'
- # doc.should have_error_on(:action, 'is reserved')
- # end
- #
- # should "work with :not_in shortcut on key definition" do
- # @document.key :action, String, :not_in => %w(kick run)
- #
- # doc = @document.new
- # doc.should_not have_error_on(:action)
- #
- # doc.action = 'fart'
- # doc.should_not have_error_on(:action)
- #
- # doc.action = 'kick'
- # doc.should have_error_on(:action, 'is reserved')
- # end
- #
- # should "not have error if allow nil is true and value is nil" do
- # @document.key :action, String
- # @document.validates_exclusion_of :action, :within => %w(kick run), :allow_nil => true
- #
- # doc = @document.new
- # doc.should_not have_error_on(:action)
- # end
- #
- # should "not have error if allow blank is true and value is blank" do
- # @document.key :action, String
- # @document.validates_exclusion_of :action, :within => %w(kick run), :allow_nil => true
- #
- # doc = @document.new(:action => '')
- # doc.should_not have_error_on(:action)
- # end
- # end
- #
+
+ context "validating exclusion of" do
+ should "throw error if enumerator not provided" do
+ @document.key :action, String
+ lambda {
+ @document.validates_exclusion_of :action
+ }.should raise_error(ArgumentError)
+ end
+
+ should "work with validates_exclusion_of macro" do
+ @document.key :action, String
+ @document.validates_exclusion_of :action, :in => %w(kick run)
+
+ doc = @document.new
+ doc.should_not have_error_on(:action)
+
+ doc.action = 'fart'
+ doc.should_not have_error_on(:action)
+
+ doc.action = 'kick'
+ doc.should have_error_on(:action, 'is reserved')
+ end
+
+ should "work with :not_in shortcut on key definition" do
+ @document.key :action, String, :not_in => %w(kick run)
+
+ doc = @document.new
+ doc.should_not have_error_on(:action)
+
+ doc.action = 'fart'
+ doc.should_not have_error_on(:action)
+
+ doc.action = 'kick'
+ doc.should have_error_on(:action, 'is reserved')
+ end
+
+ should "not have error if allow nil is true and value is nil" do
+ @document.key :action, String
+ @document.validates_exclusion_of :action, :in => %w(kick run), :allow_nil => true
+
+ doc = @document.new
+ doc.should_not have_error_on(:action)
+ end
+
+ should "not have error if allow blank is true and value is blank" do
+ @document.key :action, String
+ @document.validates_exclusion_of :action, :in => %w(kick run), :allow_nil => true
+
+ doc = @document.new(:action => '')
+ doc.should_not have_error_on(:action)
+ end
+ end
+
# context "validating inclusion of" do
# should "throw error if enumerator not provided" do
# @document.key :action, String
@@ -260,8 +260,8 @@ class ValidationsTest < Test::Unit::TestCase
# doc = @document.new(:action => '')
# doc.should_not have_error_on(:action)
# end
- # end
- #
+ # end
+
# end # End on a Document
#
# context "On an EmbeddedDocument" do
Please sign in to comment.
Something went wrong with that request. Please try again.