0
@@ -42,22 +42,74 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
0
uses_mocha 'ActiveRecord::Errors' do
0
def test_errors_generate_message_translates_custom_model_attribute_key
0
- global_scope = [:activerecord, :errors, :messages]
0
- custom_scope = global_scope + [:custom, 'topic', :title]
0
- I18n.expects(:translate).with(:topic, {:count => 1, :default => ['Topic'], :scope => [:activerecord, :models]}).returns('Topic')
0
- I18n.expects(:translate).with(:'topic.title', {:count => 1, :default => ['Title'], :scope => [:activerecord, :attributes]}).returns('Title')
0
- I18n.expects(:translate).with(:"custom.topic.title.invalid", :value => nil, :scope => global_scope, :default => [:"custom.topic.invalid", 'default from class def error 1', :invalid], :attribute => "Title", :model => "Topic").returns('default from class def error 1')
0
+ I18n.expects(:translate).with(
0
+ :default => ['Topic'],
0
+ :scope => [:activerecord, :models]
0
+ I18n.expects(:translate).with(
0
+ :default => ['Title'],
0
+ :scope => [:activerecord, :attributes]
0
+ I18n.expects(:translate).with(
0
+ :"models.topic.attributes.title.invalid",
0
+ :scope => [:activerecord, :errors],
0
+ :"models.topic.invalid",
0
+ 'default from class def error 1',
0
+ :attribute => "Title",
0
+ ).returns('default from class def error 1')
0
@topic.errors.generate_message :title, :invalid, :default => 'default from class def error 1'
0
def test_errors_generate_message_translates_custom_model_attribute_keys_with_sti
0
- custom_scope = [:activerecord, :errors, :custom, 'topic', :title]
0
- I18n.expects(:translate).with(:reply, {:count => 1, :default => [:topic, 'Reply'], :scope => [:activerecord, :models]}).returns('Reply')
0
- I18n.expects(:translate).with(:'reply.title', {:count => 1, :default => [:'topic.title', 'Title'], :scope => [:activerecord, :attributes]}).returns('Title')
0
- I18n.expects(:translate).with(:"custom.reply.title.invalid", :value => nil, :scope => [:activerecord, :errors, :messages], :default => [:"custom.reply.invalid", :"custom.topic.title.invalid", :"custom.topic.invalid", 'default from class def', :invalid], :model => 'Reply', :attribute => 'Title').returns("default from class def")
0
+ I18n.expects(:translate).with(
0
+ :default => [:topic, 'Reply'],
0
+ :scope => [:activerecord, :models]
0
+ I18n.expects(:translate).with(
0
+ :default => [:'topic.title', 'Title'],
0
+ :scope => [:activerecord, :attributes]
0
+ I18n.expects(:translate).with(
0
+ :"models.reply.attributes.title.invalid",
0
+ :scope => [:activerecord, :errors],
0
+ :"models.reply.invalid",
0
+ :"models.topic.attributes.title.invalid",
0
+ :"models.topic.invalid",
0
+ 'default from class def',
0
+ ).returns("default from class def")
0
Reply.new.errors.generate_message :title, :invalid, :default => 'default from class def'
0
def test_errors_add_on_empty_generates_message
0
@@ -347,7 +399,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
0
# validates_confirmation_of w/o mocha
0
def test_validates_confirmation_of_finds_custom_model_key_translation
0
- I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:m
essages => {:custom => {:topic => {:title => {:confirmation => 'custom message'}}}}}}
0
+ I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:m
odels => {:topic => {:attributes => {:title => {:confirmation => 'custom message'}}}}}}
0
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:confirmation => 'global message'}}}
0
Topic.validates_confirmation_of :title
0
@@ -368,7 +420,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
0
# validates_acceptance_of w/o mocha
0
def test_validates_acceptance_of_finds_custom_model_key_translation
0
- I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:m
essages => {:custom => {:topic => {:title => {:accepted => 'custom message'}}}}}}
0
+ I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:m
odels => {:topic => {:attributes => {:title => {:accepted => 'custom message'}}}}}}
0
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:accepted => 'global message'}}}
0
Topic.validates_acceptance_of :title, :allow_nil => false
0
@@ -387,7 +439,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
0
# validates_presence_of w/o mocha
0
def test_validates_presence_of_finds_custom_model_key_translation
0
- I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:m
essages => {:custom => {:topic => {:title => {:blank => 'custom message'}}}}}}
0
+ I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:m
odels => {:topic => {:attributes => {:title => {:blank => 'custom message'}}}}}}
0
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:blank => 'global message'}}}
0
Topic.validates_presence_of :title
0
@@ -406,7 +458,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
0
# validates_length_of :within w/o mocha
0
def test_validates_length_of_within_finds_custom_model_key_translation
0
- I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:m
essages => {:custom => {:topic => {:title => {:too_short => 'custom message'}}}}}}
0
+ I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:m
odels => {:topic => {:attributes => {:title => {:too_short => 'custom message'}}}}}}
0
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:too_short => 'global message'}}}
0
Topic.validates_length_of :title, :within => 3..5
0
@@ -425,7 +477,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
0
# validates_length_of :is w/o mocha
0
def test_validates_length_of_within_finds_custom_model_key_translation
0
- I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:m
essages => {:custom => {:topic => {:title => {:wrong_length => 'custom message'}}}}}}
0
+ I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:m
odels => {:topic => {:attributes => {:title => {:wrong_length => 'custom message'}}}}}}
0
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:wrong_length => 'global message'}}}
0
Topic.validates_length_of :title, :is => 5
0
@@ -444,7 +496,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
0
# validates_uniqueness_of w/o mocha
0
def test_validates_length_of_within_finds_custom_model_key_translation
0
- I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:m
essages => {:custom => {:topic => {:title => {:wrong_length => 'custom message'}}}}}}
0
+ I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:m
odels => {:topic => {:attributes => {:title => {:wrong_length => 'custom message'}}}}}}
0
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:wrong_length => 'global message'}}}
0
Topic.validates_length_of :title, :is => 5
0
@@ -464,7 +516,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
0
# validates_format_of w/o mocha
0
def test_validates_format_of_finds_custom_model_key_translation
0
- I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:m
essages => {:custom => {:topic => {:title => {:invalid => 'custom message'}}}}}}
0
+ I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:m
odels => {:topic => {:attributes => {:title => {:invalid => 'custom message'}}}}}}
0
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:invalid => 'global message'}}}
0
Topic.validates_format_of :title, :with => /^[1-9][0-9]*$/
0
@@ -483,7 +535,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
0
# validates_inclusion_of w/o mocha
0
def test_validates_inclusion_of_finds_custom_model_key_translation
0
- I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:m
essages => {:custom => {:topic => {:title => {:inclusion => 'custom message'}}}}}}
0
+ I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:m
odels => {:topic => {:attributes => {:title => {:inclusion => 'custom message'}}}}}}
0
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:inclusion => 'global message'}}}
0
Topic.validates_inclusion_of :title, :in => %w(a b c)
0
@@ -502,7 +554,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
0
# validates_exclusion_of w/o mocha
0
def test_validates_exclusion_of_finds_custom_model_key_translation
0
- I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:m
essages => {:custom => {:topic => {:title => {:exclusion => 'custom message'}}}}}}
0
+ I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:m
odels => {:topic => {:attributes => {:title => {:exclusion => 'custom message'}}}}}}
0
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:exclusion => 'global message'}}}
0
Topic.validates_exclusion_of :title, :in => %w(a b c)
0
@@ -523,7 +575,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
0
# validates_numericality_of without :only_integer w/o mocha
0
def test_validates_numericality_of_finds_custom_model_key_translation
0
- I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:m
essages => {:custom => {:topic => {:title => {:not_a_number => 'custom message'}}}}}}
0
+ I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:m
odels => {:topic => {:attributes => {:title => {:not_a_number => 'custom message'}}}}}}
0
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:not_a_number => 'global message'}}}
0
Topic.validates_numericality_of :title
0
@@ -544,7 +596,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
0
# validates_numericality_of with :only_integer w/o mocha
0
def test_validates_numericality_of_only_integer_finds_custom_model_key_translation
0
- I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:m
essages => {:custom => {:topic => {:title => {:not_a_number => 'custom message'}}}}}}
0
+ I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:m
odels => {:topic => {:attributes => {:title => {:not_a_number => 'custom message'}}}}}}
0
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:not_a_number => 'global message'}}}
0
Topic.validates_numericality_of :title, :only_integer => true
0
@@ -565,7 +617,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
0
# validates_numericality_of :odd w/o mocha
0
def test_validates_numericality_of_odd_finds_custom_model_key_translation
0
- I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:m
essages => {:custom => {:topic => {:title => {:odd => 'custom message'}}}}}}
0
+ I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:m
odels => {:topic => {:attributes => {:title => {:odd => 'custom message'}}}}}}
0
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:odd => 'global message'}}}
0
Topic.validates_numericality_of :title, :only_integer => true, :odd => true
0
@@ -586,7 +638,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
0
# validates_numericality_of :less_than w/o mocha
0
def test_validates_numericality_of_less_than_finds_custom_model_key_translation
0
- I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:m
essages => {:custom => {:topic => {:title => {:less_than => 'custom message'}}}}}}
0
+ I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:m
odels => {:topic => {:attributes => {:title => {:less_than => 'custom message'}}}}}}
0
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:less_than => 'global message'}}}
0
Topic.validates_numericality_of :title, :only_integer => true, :less_than => 0
0
@@ -608,7 +660,7 @@ class ActiveRecordValidationsI18nTests < Test::Unit::TestCase
0
# validates_associated w/o mocha
0
def test_validates_associated_finds_custom_model_key_translation
0
- I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:m
essages => {:custom => {:topic => {:replies => {:invalid => 'custom message'}}}}}}
0
+ I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:m
odels => {:topic => {:attributes => {:replies => {:invalid => 'custom message'}}}}}}
0
I18n.backend.store_translations 'en-US', :activerecord => {:errors => {:messages => {:invalid => 'global message'}}}
0
Topic.validates_associated :replies