Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Change key validation shortcut :within to :in, and add test to ensure…

… it works on embedded documents.
  • Loading branch information...
commit 15b01ade90238a41e3576cf1bd32704203539ecd 1 parent e671452
@chanks chanks authored jnunemaker committed
Showing with 18 additions and 5 deletions.
  1. +2 −2 lib/mongo_mapper/plugins/keys.rb
  2. +16 −3 test/unit/test_validations.rb
View
4 lib/mongo_mapper/plugins/keys.rb
@@ -122,8 +122,8 @@ def create_validations_for(key)
validates_format_of(attribute, :with => key.options[:format])
end
- if key.options[:within]
- validates_inclusion_of(attribute, :within => key.options[:within])
+ if key.options[:in]
+ validates_inclusion_of(attribute, :within => key.options[:in])
end
if key.options[:length]
View
19 test/unit/test_validations.rb
@@ -215,8 +215,8 @@ class ValidationsTest < Test::Unit::TestCase
doc.should_not have_error_on(:action)
end
- should "work with :within shortcut on key definition" do
- @document.key :action, String, :within => %w(kick run)
+ should "work with :in shortcut on key definition" do
+ @document.key :action, String, :in => %w(kick run)
doc = @document.new
doc.should have_error_on(:action, 'is not in the list')
@@ -459,7 +459,20 @@ class ValidationsTest < Test::Unit::TestCase
doc.action = 'kick'
doc.should_not have_error_on(:action)
end
-
+
+ should "work with :in shortcut on key definition" do
+ @embedded_doc.key :action, String, :in => %w(kick run)
+
+ doc = @embedded_doc.new
+ doc.should have_error_on(:action, 'is not in the list')
+
+ doc.action = 'fart'
+ doc.should have_error_on(:action, 'is not in the list')
+
+ doc.action = 'kick'
+ doc.should_not have_error_on(:action)
+ end
+
should "not have error if allow nil is true and value is nil" do
@embedded_doc.key :action, String
@embedded_doc.validates_inclusion_of :action, :within => %w(kick run), :allow_nil => true
Please sign in to comment.
Something went wrong with that request. Please try again.