提交 79c8b104 编写于 作者: S Sven Fuchs 提交者: Jeremy Kemper

change activerecord validation tests to not use the deprecated interpolation syntax any more

Signed-off-by: NJeremy Kemper <jeremy@bitsweat.net>
上级 70a4f6c2
...@@ -605,7 +605,7 @@ def test_validate_format_numeric ...@@ -605,7 +605,7 @@ def test_validate_format_numeric
end end
def test_validate_format_with_formatted_message def test_validate_format_with_formatted_message
Topic.validates_format_of(:title, :with => /^Valid Title$/, :message => "can't be %s") Topic.validates_format_of(:title, :with => /^Valid Title$/, :message => "can't be {{value}}")
t = Topic.create(:title => 'Invalid title') t = Topic.create(:title => 'Invalid title')
assert_equal "can't be Invalid title", t.errors.on(:title) assert_equal "can't be Invalid title", t.errors.on(:title)
end end
...@@ -666,7 +666,7 @@ def test_validates_length_of_with_allow_blank ...@@ -666,7 +666,7 @@ def test_validates_length_of_with_allow_blank
end end
def test_validates_inclusion_of_with_formatted_message def test_validates_inclusion_of_with_formatted_message
Topic.validates_inclusion_of( :title, :in => %w( a b c d e f g ), :message => "option %s is not in the list" ) Topic.validates_inclusion_of( :title, :in => %w( a b c d e f g ), :message => "option {{value}} is not in the list" )
assert Topic.create("title" => "a", "content" => "abc").valid? assert Topic.create("title" => "a", "content" => "abc").valid?
...@@ -691,7 +691,7 @@ def test_validates_exclusion_of ...@@ -691,7 +691,7 @@ def test_validates_exclusion_of
end end
def test_validates_exclusion_of_with_formatted_message def test_validates_exclusion_of_with_formatted_message
Topic.validates_exclusion_of( :title, :in => %w( abe monkey ), :message => "option %s is restricted" ) Topic.validates_exclusion_of( :title, :in => %w( abe monkey ), :message => "option {{value}} is restricted" )
assert Topic.create("title" => "something", "content" => "abc") assert Topic.create("title" => "something", "content" => "abc")
...@@ -791,7 +791,7 @@ def test_optionally_validates_length_of_using_within ...@@ -791,7 +791,7 @@ def test_optionally_validates_length_of_using_within
end end
def test_optionally_validates_length_of_using_within_on_create def test_optionally_validates_length_of_using_within_on_create
Topic.validates_length_of :title, :content, :within => 5..10, :on => :create, :too_long => "my string is too long: %d" Topic.validates_length_of :title, :content, :within => 5..10, :on => :create, :too_long => "my string is too long: {{count}}"
t = Topic.create("title" => "thisisnotvalid", "content" => "whatever") t = Topic.create("title" => "thisisnotvalid", "content" => "whatever")
assert !t.save assert !t.save
...@@ -812,7 +812,7 @@ def test_optionally_validates_length_of_using_within_on_create ...@@ -812,7 +812,7 @@ def test_optionally_validates_length_of_using_within_on_create
end end
def test_optionally_validates_length_of_using_within_on_update def test_optionally_validates_length_of_using_within_on_update
Topic.validates_length_of :title, :content, :within => 5..10, :on => :update, :too_short => "my string is too short: %d" Topic.validates_length_of :title, :content, :within => 5..10, :on => :update, :too_short => "my string is too short: {{count}}"
t = Topic.create("title" => "vali", "content" => "whatever") t = Topic.create("title" => "vali", "content" => "whatever")
assert !t.save assert !t.save
...@@ -875,7 +875,7 @@ def test_validates_length_of_using_bignum ...@@ -875,7 +875,7 @@ def test_validates_length_of_using_bignum
def test_validates_length_with_globally_modified_error_message def test_validates_length_with_globally_modified_error_message
ActiveSupport::Deprecation.silence do ActiveSupport::Deprecation.silence do
ActiveRecord::Errors.default_error_messages[:too_short] = 'tu est trops petit hombre %d' ActiveRecord::Errors.default_error_messages[:too_short] = 'tu est trops petit hombre {{count}}'
end end
Topic.validates_length_of :title, :minimum => 10 Topic.validates_length_of :title, :minimum => 10
t = Topic.create(:title => 'too short') t = Topic.create(:title => 'too short')
...@@ -919,7 +919,7 @@ def test_validates_length_of_nasty_params ...@@ -919,7 +919,7 @@ def test_validates_length_of_nasty_params
end end
def test_validates_length_of_custom_errors_for_minimum_with_message def test_validates_length_of_custom_errors_for_minimum_with_message
Topic.validates_length_of( :title, :minimum=>5, :message=>"boo %d" ) Topic.validates_length_of( :title, :minimum=>5, :message=>"boo {{count}}" )
t = Topic.create("title" => "uhoh", "content" => "whatever") t = Topic.create("title" => "uhoh", "content" => "whatever")
assert !t.valid? assert !t.valid?
assert t.errors.on(:title) assert t.errors.on(:title)
...@@ -927,7 +927,7 @@ def test_validates_length_of_custom_errors_for_minimum_with_message ...@@ -927,7 +927,7 @@ def test_validates_length_of_custom_errors_for_minimum_with_message
end end
def test_validates_length_of_custom_errors_for_minimum_with_too_short def test_validates_length_of_custom_errors_for_minimum_with_too_short
Topic.validates_length_of( :title, :minimum=>5, :too_short=>"hoo %d" ) Topic.validates_length_of( :title, :minimum=>5, :too_short=>"hoo {{count}}" )
t = Topic.create("title" => "uhoh", "content" => "whatever") t = Topic.create("title" => "uhoh", "content" => "whatever")
assert !t.valid? assert !t.valid?
assert t.errors.on(:title) assert t.errors.on(:title)
...@@ -935,7 +935,7 @@ def test_validates_length_of_custom_errors_for_minimum_with_too_short ...@@ -935,7 +935,7 @@ def test_validates_length_of_custom_errors_for_minimum_with_too_short
end end
def test_validates_length_of_custom_errors_for_maximum_with_message def test_validates_length_of_custom_errors_for_maximum_with_message
Topic.validates_length_of( :title, :maximum=>5, :message=>"boo %d" ) Topic.validates_length_of( :title, :maximum=>5, :message=>"boo {{count}}" )
t = Topic.create("title" => "uhohuhoh", "content" => "whatever") t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
assert !t.valid? assert !t.valid?
assert t.errors.on(:title) assert t.errors.on(:title)
...@@ -943,7 +943,7 @@ def test_validates_length_of_custom_errors_for_maximum_with_message ...@@ -943,7 +943,7 @@ def test_validates_length_of_custom_errors_for_maximum_with_message
end end
def test_validates_length_of_custom_errors_for_maximum_with_too_long def test_validates_length_of_custom_errors_for_maximum_with_too_long
Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo %d" ) Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo {{count}}" )
t = Topic.create("title" => "uhohuhoh", "content" => "whatever") t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
assert !t.valid? assert !t.valid?
assert t.errors.on(:title) assert t.errors.on(:title)
...@@ -951,7 +951,7 @@ def test_validates_length_of_custom_errors_for_maximum_with_too_long ...@@ -951,7 +951,7 @@ def test_validates_length_of_custom_errors_for_maximum_with_too_long
end end
def test_validates_length_of_custom_errors_for_is_with_message def test_validates_length_of_custom_errors_for_is_with_message
Topic.validates_length_of( :title, :is=>5, :message=>"boo %d" ) Topic.validates_length_of( :title, :is=>5, :message=>"boo {{count}}" )
t = Topic.create("title" => "uhohuhoh", "content" => "whatever") t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
assert !t.valid? assert !t.valid?
assert t.errors.on(:title) assert t.errors.on(:title)
...@@ -959,7 +959,7 @@ def test_validates_length_of_custom_errors_for_is_with_message ...@@ -959,7 +959,7 @@ def test_validates_length_of_custom_errors_for_is_with_message
end end
def test_validates_length_of_custom_errors_for_is_with_wrong_length def test_validates_length_of_custom_errors_for_is_with_wrong_length
Topic.validates_length_of( :title, :is=>5, :wrong_length=>"hoo %d" ) Topic.validates_length_of( :title, :is=>5, :wrong_length=>"hoo {{count}}" )
t = Topic.create("title" => "uhohuhoh", "content" => "whatever") t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
assert !t.valid? assert !t.valid?
assert t.errors.on(:title) assert t.errors.on(:title)
...@@ -1025,7 +1025,7 @@ def test_optionally_validates_length_of_using_within_utf8 ...@@ -1025,7 +1025,7 @@ def test_optionally_validates_length_of_using_within_utf8
def test_optionally_validates_length_of_using_within_on_create_utf8 def test_optionally_validates_length_of_using_within_on_create_utf8
with_kcode('UTF8') do with_kcode('UTF8') do
Topic.validates_length_of :title, :within => 5..10, :on => :create, :too_long => "長すぎます: %d" Topic.validates_length_of :title, :within => 5..10, :on => :create, :too_long => "長すぎます: {{count}}"
t = Topic.create("title" => "一二三四五六七八九十A", "content" => "whatever") t = Topic.create("title" => "一二三四五六七八九十A", "content" => "whatever")
assert !t.save assert !t.save
...@@ -1048,7 +1048,7 @@ def test_optionally_validates_length_of_using_within_on_create_utf8 ...@@ -1048,7 +1048,7 @@ def test_optionally_validates_length_of_using_within_on_create_utf8
def test_optionally_validates_length_of_using_within_on_update_utf8 def test_optionally_validates_length_of_using_within_on_update_utf8
with_kcode('UTF8') do with_kcode('UTF8') do
Topic.validates_length_of :title, :within => 5..10, :on => :update, :too_short => "短すぎます: %d" Topic.validates_length_of :title, :within => 5..10, :on => :update, :too_short => "短すぎます: {{count}}"
t = Topic.create("title" => "一二三4", "content" => "whatever") t = Topic.create("title" => "一二三4", "content" => "whatever")
assert !t.save assert !t.save
...@@ -1083,7 +1083,7 @@ def test_validates_length_of_using_is_utf8 ...@@ -1083,7 +1083,7 @@ def test_validates_length_of_using_is_utf8
end end
def test_validates_length_of_with_block def test_validates_length_of_with_block
Topic.validates_length_of :content, :minimum => 5, :too_short=>"Your essay must be at least %d words.", Topic.validates_length_of :content, :minimum => 5, :too_short=>"Your essay must be at least {{count}} words.",
:tokenizer => lambda {|str| str.scan(/\w+/) } :tokenizer => lambda {|str| str.scan(/\w+/) }
t = Topic.create!(:content => "this content should be long enough") t = Topic.create!(:content => "this content should be long enough")
assert t.valid? assert t.valid?
...@@ -1234,7 +1234,7 @@ def test_validates_associated_with_custom_message_using_quotes ...@@ -1234,7 +1234,7 @@ def test_validates_associated_with_custom_message_using_quotes
def test_if_validation_using_method_true def test_if_validation_using_method_true
# When the method returns true # When the method returns true
Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo %d", :if => :condition_is_true ) Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo {{count}}", :if => :condition_is_true )
t = Topic.create("title" => "uhohuhoh", "content" => "whatever") t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
assert !t.valid? assert !t.valid?
assert t.errors.on(:title) assert t.errors.on(:title)
...@@ -1243,7 +1243,7 @@ def test_if_validation_using_method_true ...@@ -1243,7 +1243,7 @@ def test_if_validation_using_method_true
def test_unless_validation_using_method_true def test_unless_validation_using_method_true
# When the method returns true # When the method returns true
Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo %d", :unless => :condition_is_true ) Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo {{count}}", :unless => :condition_is_true )
t = Topic.create("title" => "uhohuhoh", "content" => "whatever") t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
assert t.valid? assert t.valid?
assert !t.errors.on(:title) assert !t.errors.on(:title)
...@@ -1251,7 +1251,7 @@ def test_unless_validation_using_method_true ...@@ -1251,7 +1251,7 @@ def test_unless_validation_using_method_true
def test_if_validation_using_method_false def test_if_validation_using_method_false
# When the method returns false # When the method returns false
Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo %d", :if => :condition_is_true_but_its_not ) Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo {{count}}", :if => :condition_is_true_but_its_not )
t = Topic.create("title" => "uhohuhoh", "content" => "whatever") t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
assert t.valid? assert t.valid?
assert !t.errors.on(:title) assert !t.errors.on(:title)
...@@ -1259,7 +1259,7 @@ def test_if_validation_using_method_false ...@@ -1259,7 +1259,7 @@ def test_if_validation_using_method_false
def test_unless_validation_using_method_false def test_unless_validation_using_method_false
# When the method returns false # When the method returns false
Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo %d", :unless => :condition_is_true_but_its_not ) Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo {{count}}", :unless => :condition_is_true_but_its_not )
t = Topic.create("title" => "uhohuhoh", "content" => "whatever") t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
assert !t.valid? assert !t.valid?
assert t.errors.on(:title) assert t.errors.on(:title)
...@@ -1268,7 +1268,7 @@ def test_unless_validation_using_method_false ...@@ -1268,7 +1268,7 @@ def test_unless_validation_using_method_false
def test_if_validation_using_string_true def test_if_validation_using_string_true
# When the evaluated string returns true # When the evaluated string returns true
Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo %d", :if => "a = 1; a == 1" ) Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo {{count}}", :if => "a = 1; a == 1" )
t = Topic.create("title" => "uhohuhoh", "content" => "whatever") t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
assert !t.valid? assert !t.valid?
assert t.errors.on(:title) assert t.errors.on(:title)
...@@ -1277,7 +1277,7 @@ def test_if_validation_using_string_true ...@@ -1277,7 +1277,7 @@ def test_if_validation_using_string_true
def test_unless_validation_using_string_true def test_unless_validation_using_string_true
# When the evaluated string returns true # When the evaluated string returns true
Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo %d", :unless => "a = 1; a == 1" ) Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo {{count}}", :unless => "a = 1; a == 1" )
t = Topic.create("title" => "uhohuhoh", "content" => "whatever") t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
assert t.valid? assert t.valid?
assert !t.errors.on(:title) assert !t.errors.on(:title)
...@@ -1285,7 +1285,7 @@ def test_unless_validation_using_string_true ...@@ -1285,7 +1285,7 @@ def test_unless_validation_using_string_true
def test_if_validation_using_string_false def test_if_validation_using_string_false
# When the evaluated string returns false # When the evaluated string returns false
Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo %d", :if => "false") Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo {{count}}", :if => "false")
t = Topic.create("title" => "uhohuhoh", "content" => "whatever") t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
assert t.valid? assert t.valid?
assert !t.errors.on(:title) assert !t.errors.on(:title)
...@@ -1293,7 +1293,7 @@ def test_if_validation_using_string_false ...@@ -1293,7 +1293,7 @@ def test_if_validation_using_string_false
def test_unless_validation_using_string_false def test_unless_validation_using_string_false
# When the evaluated string returns false # When the evaluated string returns false
Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo %d", :unless => "false") Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo {{count}}", :unless => "false")
t = Topic.create("title" => "uhohuhoh", "content" => "whatever") t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
assert !t.valid? assert !t.valid?
assert t.errors.on(:title) assert t.errors.on(:title)
...@@ -1302,7 +1302,7 @@ def test_unless_validation_using_string_false ...@@ -1302,7 +1302,7 @@ def test_unless_validation_using_string_false
def test_if_validation_using_block_true def test_if_validation_using_block_true
# When the block returns true # When the block returns true
Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo %d", Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo {{count}}",
:if => Proc.new { |r| r.content.size > 4 } ) :if => Proc.new { |r| r.content.size > 4 } )
t = Topic.create("title" => "uhohuhoh", "content" => "whatever") t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
assert !t.valid? assert !t.valid?
...@@ -1312,7 +1312,7 @@ def test_if_validation_using_block_true ...@@ -1312,7 +1312,7 @@ def test_if_validation_using_block_true
def test_unless_validation_using_block_true def test_unless_validation_using_block_true
# When the block returns true # When the block returns true
Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo %d", Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo {{count}}",
:unless => Proc.new { |r| r.content.size > 4 } ) :unless => Proc.new { |r| r.content.size > 4 } )
t = Topic.create("title" => "uhohuhoh", "content" => "whatever") t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
assert t.valid? assert t.valid?
...@@ -1321,7 +1321,7 @@ def test_unless_validation_using_block_true ...@@ -1321,7 +1321,7 @@ def test_unless_validation_using_block_true
def test_if_validation_using_block_false def test_if_validation_using_block_false
# When the block returns false # When the block returns false
Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo %d", Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo {{count}}",
:if => Proc.new { |r| r.title != "uhohuhoh"} ) :if => Proc.new { |r| r.title != "uhohuhoh"} )
t = Topic.create("title" => "uhohuhoh", "content" => "whatever") t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
assert t.valid? assert t.valid?
...@@ -1330,7 +1330,7 @@ def test_if_validation_using_block_false ...@@ -1330,7 +1330,7 @@ def test_if_validation_using_block_false
def test_unless_validation_using_block_false def test_unless_validation_using_block_false
# When the block returns false # When the block returns false
Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo %d", Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo {{count}}",
:unless => Proc.new { |r| r.title != "uhohuhoh"} ) :unless => Proc.new { |r| r.title != "uhohuhoh"} )
t = Topic.create("title" => "uhohuhoh", "content" => "whatever") t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
assert !t.valid? assert !t.valid?
...@@ -1507,13 +1507,13 @@ def test_validates_numericality_with_greater_than_less_than_and_even ...@@ -1507,13 +1507,13 @@ def test_validates_numericality_with_greater_than_less_than_and_even
end end
def test_validates_numericality_with_numeric_message def test_validates_numericality_with_numeric_message
Topic.validates_numericality_of :approved, :less_than => 4, :message => "smaller than %d" Topic.validates_numericality_of :approved, :less_than => 4, :message => "smaller than {{count}}"
topic = Topic.new("title" => "numeric test", "approved" => 10) topic = Topic.new("title" => "numeric test", "approved" => 10)
assert !topic.valid? assert !topic.valid?
assert_equal "smaller than 4", topic.errors.on(:approved) assert_equal "smaller than 4", topic.errors.on(:approved)
Topic.validates_numericality_of :approved, :greater_than => 4, :message => "greater than %d" Topic.validates_numericality_of :approved, :greater_than => 4, :message => "greater than {{count}}"
topic = Topic.new("title" => "numeric test", "approved" => 1) topic = Topic.new("title" => "numeric test", "approved" => 1)
assert !topic.valid? assert !topic.valid?
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册