diff options
author | Nick Sutterer <apotonick@gmail.com> | 2013-05-13 13:59:28 +1000 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-05-23 10:00:44 -0300 |
commit | 7d84c3a2f7ede0e8d04540e9c0640de7378e9b3a (patch) | |
tree | ef7f47142b07726fc2c7a954d400a9c1ef7558e5 /activemodel/test/cases | |
parent | 30d28b19584783218e842ce2fd7bfe2bc1dccf66 (diff) | |
download | rails-7d84c3a2f7ede0e8d04540e9c0640de7378e9b3a.tar.gz rails-7d84c3a2f7ede0e8d04540e9c0640de7378e9b3a.tar.bz2 rails-7d84c3a2f7ede0e8d04540e9c0640de7378e9b3a.zip |
deprecate Validator#setup (to get rid of a respond_to call). validators do their setup in their constructor now.
Diffstat (limited to 'activemodel/test/cases')
-rw-r--r-- | activemodel/test/cases/validations/with_validation_test.rb | 24 | ||||
-rw-r--r-- | activemodel/test/cases/validations_test.rb | 21 |
2 files changed, 22 insertions, 23 deletions
diff --git a/activemodel/test/cases/validations/with_validation_test.rb b/activemodel/test/cases/validations/with_validation_test.rb index efe16d9aa9..93716f1433 100644 --- a/activemodel/test/cases/validations/with_validation_test.rb +++ b/activemodel/test/cases/validations/with_validation_test.rb @@ -100,35 +100,13 @@ class ValidatesWithTest < ActiveModel::TestCase test "passes all configuration options to the validator class" do topic = Topic.new validator = mock() - validator.expects(:new).with(foo: :bar, if: "1 == 1").returns(validator) + validator.expects(:new).with(foo: :bar, if: "1 == 1", class: Topic).returns(validator) validator.expects(:validate).with(topic) Topic.validates_with(validator, if: "1 == 1", foo: :bar) assert topic.valid? end - test "calls setup method of validator passing in self when validator has setup method" do - topic = Topic.new - validator = stub_everything - validator.stubs(:new).returns(validator) - validator.stubs(:validate) - validator.stubs(:respond_to?).with(:setup).returns(true) - validator.expects(:setup).with(Topic).once - Topic.validates_with(validator) - assert topic.valid? - end - - test "doesn't call setup method of validator when validator has no setup method" do - topic = Topic.new - validator = stub_everything - validator.stubs(:new).returns(validator) - validator.stubs(:validate) - validator.stubs(:respond_to?).with(:setup).returns(false) - validator.expects(:setup).with(Topic).never - Topic.validates_with(validator) - assert topic.valid? - end - test "validates_with with options" do Topic.validates_with(ValidatorThatValidatesOptions, field: :first_name) topic = Topic.new diff --git a/activemodel/test/cases/validations_test.rb b/activemodel/test/cases/validations_test.rb index 3e84297cc2..039b6b8872 100644 --- a/activemodel/test/cases/validations_test.rb +++ b/activemodel/test/cases/validations_test.rb @@ -373,4 +373,25 @@ class ValidationsTest < ActiveModel::TestCase assert topic.invalid? assert duped.valid? end + + # validator test: + def test_setup_is_deprecated_but_still_receives_klass # TODO: remove me in 4.2. + validator_class = Class.new(ActiveModel::Validator) do + def setup(klass) + @old_klass = klass + end + + def validate(*) + @old_klass == Topic or raise "#setup didn't work" + end + end + + assert_deprecated do + Topic.validates_with validator_class + end + + t = Topic.new + t.valid? + end + end |