diff options
author | Vince Puzzella <vincepuz@gmail.com> | 2014-01-18 11:34:38 -0500 |
---|---|---|
committer | Vince Puzzella <vincepuz@gmail.com> | 2014-01-27 03:26:27 -0500 |
commit | 8855163bdbce23fa539be2c1ef2a49f1aabc6458 (patch) | |
tree | 3429079077006499431452eaadc42737d28f6997 /activemodel/test | |
parent | 5540dfccd88c809c2922f21f4c1558465bce26dd (diff) | |
download | rails-8855163bdbce23fa539be2c1ef2a49f1aabc6458.tar.gz rails-8855163bdbce23fa539be2c1ef2a49f1aabc6458.tar.bz2 rails-8855163bdbce23fa539be2c1ef2a49f1aabc6458.zip |
Ability to specify multiple contexts when defining a validation.
Example:
validates_presence_of :name, on: [:update, :custom_validation_context]
Diffstat (limited to 'activemodel/test')
-rw-r--r-- | activemodel/test/cases/validations/validations_context_test.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/activemodel/test/cases/validations/validations_context_test.rb b/activemodel/test/cases/validations/validations_context_test.rb index 5f99b320a6..a3daace4a8 100644 --- a/activemodel/test/cases/validations/validations_context_test.rb +++ b/activemodel/test/cases/validations/validations_context_test.rb @@ -36,4 +36,20 @@ class ValidationsContextTest < ActiveModel::TestCase assert topic.invalid?(:create), "Validation does run on create if 'on' is set to create" assert topic.errors[:base].include?(ERROR_MESSAGE) end + + test "with a class that adds errors on multiple contexts and validating a new model with no arguments" do + Topic.validates_with(ValidatorThatAddsErrors, on: [:context1, :context2]) + topic = Topic.new + assert topic.valid?, "Validation doesn't run when 'on' is set to context1 and context2" + end + + test "with a class that adds errors on multiple contexts and validating a new model" do + Topic.validates_with(ValidatorThatAddsErrors, on: [:context1, :context2]) + topic = Topic.new + assert topic.invalid?(:context1), "Validation does run on context1 when 'on' is set to context1 and context2" + assert topic.errors[:base].include?(ERROR_MESSAGE) + topic = Topic.new + assert topic.invalid?(:context2), "Validation does run on context2 when 'on' is set to context1 and context2" + assert topic.errors[:base].include?(ERROR_MESSAGE) + end end |