diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-05-01 18:31:33 -0700 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-05-01 18:31:33 -0700 |
commit | b3a74a14a3d6efa22a07116c4cb26aadc479fb41 (patch) | |
tree | f5e7fe3933183c796cf82d2bada32417eb0b65e8 /activemodel/test/cases/validations/with_validation_test.rb | |
parent | dd1f36078eff18721eed76d236796c8d26d81e58 (diff) | |
parent | eebb9ddf9ba559a510975c486fe59a4edc9da97d (diff) | |
download | rails-b3a74a14a3d6efa22a07116c4cb26aadc479fb41.tar.gz rails-b3a74a14a3d6efa22a07116c4cb26aadc479fb41.tar.bz2 rails-b3a74a14a3d6efa22a07116c4cb26aadc479fb41.zip |
Merge pull request #10408 from patricksrobertson/convert_activemodel_to_new_hash_syntax
Convert ActiveModel to 1.9 hash syntax.
Diffstat (limited to 'activemodel/test/cases/validations/with_validation_test.rb')
-rw-r--r-- | activemodel/test/cases/validations/with_validation_test.rb | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/activemodel/test/cases/validations/with_validation_test.rb b/activemodel/test/cases/validations/with_validation_test.rb index daa7a8d5c4..efe16d9aa9 100644 --- a/activemodel/test/cases/validations/with_validation_test.rb +++ b/activemodel/test/cases/validations/with_validation_test.rb @@ -72,26 +72,26 @@ class ValidatesWithTest < ActiveModel::TestCase end test "with if statements that return false" do - Topic.validates_with(ValidatorThatAddsErrors, :if => "1 == 2") + Topic.validates_with(ValidatorThatAddsErrors, if: "1 == 2") topic = Topic.new assert topic.valid? end test "with if statements that return true" do - Topic.validates_with(ValidatorThatAddsErrors, :if => "1 == 1") + Topic.validates_with(ValidatorThatAddsErrors, if: "1 == 1") topic = Topic.new assert topic.invalid? assert topic.errors[:base].include?(ERROR_MESSAGE) end test "with unless statements that return true" do - Topic.validates_with(ValidatorThatAddsErrors, :unless => "1 == 1") + Topic.validates_with(ValidatorThatAddsErrors, unless: "1 == 1") topic = Topic.new assert topic.valid? end test "with unless statements that returns false" do - Topic.validates_with(ValidatorThatAddsErrors, :unless => "1 == 2") + Topic.validates_with(ValidatorThatAddsErrors, unless: "1 == 2") topic = Topic.new assert topic.invalid? assert topic.errors[:base].include?(ERROR_MESSAGE) @@ -100,10 +100,10 @@ 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").returns(validator) validator.expects(:validate).with(topic) - Topic.validates_with(validator, :if => "1 == 1", :foo => :bar) + Topic.validates_with(validator, if: "1 == 1", foo: :bar) assert topic.valid? end @@ -130,15 +130,15 @@ class ValidatesWithTest < ActiveModel::TestCase end test "validates_with with options" do - Topic.validates_with(ValidatorThatValidatesOptions, :field => :first_name) + Topic.validates_with(ValidatorThatValidatesOptions, field: :first_name) topic = Topic.new assert topic.invalid? assert topic.errors[:base].include?(ERROR_MESSAGE) end test "validates_with each validator" do - Topic.validates_with(ValidatorPerEachAttribute, :attributes => [:title, :content]) - topic = Topic.new :title => "Title", :content => "Content" + Topic.validates_with(ValidatorPerEachAttribute, attributes: [:title, :content]) + topic = Topic.new title: "Title", content: "Content" assert topic.invalid? assert_equal ["Value is Title"], topic.errors[:title] assert_equal ["Value is Content"], topic.errors[:content] @@ -146,7 +146,7 @@ class ValidatesWithTest < ActiveModel::TestCase test "each validator checks validity" do assert_raise RuntimeError do - Topic.validates_with(ValidatorCheckValidity, :attributes => [:title]) + Topic.validates_with(ValidatorCheckValidity, attributes: [:title]) end end @@ -157,25 +157,25 @@ class ValidatesWithTest < ActiveModel::TestCase end test "each validator skip nil values if :allow_nil is set to true" do - Topic.validates_with(ValidatorPerEachAttribute, :attributes => [:title, :content], :allow_nil => true) - topic = Topic.new :content => "" + Topic.validates_with(ValidatorPerEachAttribute, attributes: [:title, :content], allow_nil: true) + topic = Topic.new content: "" assert topic.invalid? assert topic.errors[:title].empty? assert_equal ["Value is "], topic.errors[:content] end test "each validator skip blank values if :allow_blank is set to true" do - Topic.validates_with(ValidatorPerEachAttribute, :attributes => [:title, :content], :allow_blank => true) - topic = Topic.new :content => "" + Topic.validates_with(ValidatorPerEachAttribute, attributes: [:title, :content], allow_blank: true) + topic = Topic.new content: "" assert topic.valid? assert topic.errors[:title].empty? assert topic.errors[:content].empty? end test "validates_with can validate with an instance method" do - Topic.validates :title, :with => :my_validation + Topic.validates :title, with: :my_validation - topic = Topic.new :title => "foo" + topic = Topic.new title: "foo" assert topic.valid? assert topic.errors[:title].empty? @@ -185,9 +185,9 @@ class ValidatesWithTest < ActiveModel::TestCase end test "optionally pass in the attribute being validated when validating with an instance method" do - Topic.validates :title, :content, :with => :my_validation_with_arg + Topic.validates :title, :content, with: :my_validation_with_arg - topic = Topic.new :title => "foo" + topic = Topic.new title: "foo" assert !topic.valid? assert topic.errors[:title].empty? assert_equal ['is missing'], topic.errors[:content] |