Skip to content

Commit 5336ce2

Browse files
Merge tests about multiple validation contexts
1 parent abe6484 commit 5336ce2

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

activemodel/test/cases/validations/validations_context_test.rb

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
require 'models/topic'
55

66
class ValidationsContextTest < ActiveModel::TestCase
7-
87
def teardown
98
Topic.reset_callbacks(:validate)
109
Topic._validators.clear
@@ -37,19 +36,16 @@ def validate(record)
3736
assert topic.errors[:base].include?(ERROR_MESSAGE)
3837
end
3938

40-
test "with a class that adds errors on multiple contexts and validating a new model with no arguments" do
41-
Topic.validates_with(ValidatorThatAddsErrors, on: [:context1, :context2])
42-
topic = Topic.new
43-
assert topic.valid?, "Validation doesn't run when 'on' is set to context1 and context2"
44-
end
45-
4639
test "with a class that adds errors on multiple contexts and validating a new model" do
4740
Topic.validates_with(ValidatorThatAddsErrors, on: [:context1, :context2])
41+
4842
topic = Topic.new
49-
assert topic.invalid?(:context1), "Validation does run on context1 when 'on' is set to context1 and context2"
43+
assert topic.valid?, "Validation ran with no context given when 'on' is set to context1 and context2"
44+
45+
assert topic.invalid?(:context1), "Validation did not run on context1 when 'on' is set to context1 and context2"
5046
assert topic.errors[:base].include?(ERROR_MESSAGE)
51-
topic = Topic.new
52-
assert topic.invalid?(:context2), "Validation does run on context2 when 'on' is set to context1 and context2"
47+
48+
assert topic.invalid?(:context2), "Validation did not run on context2 when 'on' is set to context1 and context2"
5349
assert topic.errors[:base].include?(ERROR_MESSAGE)
5450
end
5551
end

0 commit comments

Comments
 (0)