aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/test
diff options
context:
space:
mode:
authorGabriel Sobrinho <gabriel.sobrinho@gmail.com>2012-08-12 17:38:22 -0300
committerGabriel Sobrinho <gabriel.sobrinho@gmail.com>2012-08-24 15:26:17 -0300
commit2f3eb484f2712ba1833fea758ee85e49c374fc5b (patch)
tree119c197b8f2b746ed55e6cac2ab2f3d562a2659c /activemodel/test
parent2c571b3f0544a6457db4818e752f4cd4bacd48b4 (diff)
downloadrails-2f3eb484f2712ba1833fea758ee85e49c374fc5b.tar.gz
rails-2f3eb484f2712ba1833fea758ee85e49c374fc5b.tar.bz2
rails-2f3eb484f2712ba1833fea758ee85e49c374fc5b.zip
Accept a symbol for `:in` option on inclusion and exclusion validators
Diffstat (limited to 'activemodel/test')
-rw-r--r--activemodel/test/cases/validations/exclusion_validation_test.rb22
-rw-r--r--activemodel/test/cases/validations/inclusion_validation_test.rb22
2 files changed, 44 insertions, 0 deletions
diff --git a/activemodel/test/cases/validations/exclusion_validation_test.rb b/activemodel/test/cases/validations/exclusion_validation_test.rb
index baccf72ecb..9f916dbfdd 100644
--- a/activemodel/test/cases/validations/exclusion_validation_test.rb
+++ b/activemodel/test/cases/validations/exclusion_validation_test.rb
@@ -64,4 +64,26 @@ class ExclusionValidationTest < ActiveModel::TestCase
t.title = "wasabi"
assert t.valid?
end
+
+ def test_validates_inclusion_of_with_symbol
+ Person.validates_exclusion_of :karma, :in => :reserved_karmas
+
+ p = Person.new
+ p.karma = "abe"
+
+ def p.reserved_karmas
+ %w(abe)
+ end
+
+ assert p.invalid?
+ assert_equal ["is reserved"], p.errors[:karma]
+
+ def p.reserved_karmas
+ %w()
+ end
+
+ assert p.valid?
+ ensure
+ Person.reset_callbacks(:validate)
+ end
end
diff --git a/activemodel/test/cases/validations/inclusion_validation_test.rb b/activemodel/test/cases/validations/inclusion_validation_test.rb
index c57fa75faf..92638f8e70 100644
--- a/activemodel/test/cases/validations/inclusion_validation_test.rb
+++ b/activemodel/test/cases/validations/inclusion_validation_test.rb
@@ -96,4 +96,26 @@ class InclusionValidationTest < ActiveModel::TestCase
t.title = "elephant"
assert t.valid?
end
+
+ def test_validates_inclusion_of_with_symbol
+ Person.validates_inclusion_of :karma, :in => :available_karmas
+
+ p = Person.new
+ p.karma = "Lifo"
+
+ def p.available_karmas
+ %w()
+ end
+
+ assert p.invalid?
+ assert_equal ["is not included in the list"], p.errors[:karma]
+
+ def p.available_karmas
+ %w(Lifo)
+ end
+
+ assert p.valid?
+ ensure
+ Person.reset_callbacks(:validate)
+ end
end