1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge tests about multiple validation contexts

This commit is contained in:
Carlos Antonio da Silva 2014-01-27 08:17:20 -02:00
parent abe648452f
commit 5336ce265a

View file

@ -4,7 +4,6 @@ require 'cases/helper'
require 'models/topic'
class ValidationsContextTest < ActiveModel::TestCase
def teardown
Topic.reset_callbacks(:validate)
Topic._validators.clear
@ -37,19 +36,16 @@ class ValidationsContextTest < ActiveModel::TestCase
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.valid?, "Validation ran with no context given when 'on' is set to context1 and context2"
assert topic.invalid?(:context1), "Validation did not 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.invalid?(:context2), "Validation did not run on context2 when 'on' is set to context1 and context2"
assert topic.errors[:base].include?(ERROR_MESSAGE)
end
end