Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

rather cosmetic improvements of test coverage

  • Loading branch information...
commit 0dddba41fcfcd28de2ce1a88a23514fbde53afcf 1 parent 3533dc6
@svenfuchs svenfuchs authored
View
2  actionpack/lib/action_view/helpers/number_helper.rb
@@ -70,7 +70,7 @@ def number_to_phone(number, options = {})
# # => 1234567890,50 £
def number_to_currency(number, options = {})
options = options.symbolize_keys
-
+
locale = options[:locale]
locale ||= self.locale if respond_to?(:locale)
View
8 activerecord/lib/active_record/validations.rb
@@ -21,8 +21,8 @@ class Errors
class << self
def default_error_messages
- # ActiveSupport::Deprecation.warn("ActiveRecord::Errors.default_error_messages has been deprecated. Please use :'active_record.error_messages'.t.")
- :'active_record.error_messages'.t
+ ActiveSupport::Deprecation.warn("ActiveRecord::Errors.default_error_messages has been deprecated. Please use 'active_record.error_messages'.t.")
+ 'active_record.error_messages'.t
end
end
@@ -163,7 +163,7 @@ def full_messages(options = {})
@errors.each_key do |attr|
@errors[attr].each do |message|
next unless message
-
+
if attr == "base"
full_messages << message
else
@@ -872,7 +872,7 @@ def validates_numericality_of(*attr_names)
end
raw_value = raw_value.to_i
else
- begin
+ begin
raw_value = Kernel.Float(raw_value.to_s)
rescue ArgumentError, TypeError
message = record.errors.generate_message(attr_name, :not_a_number, :value => raw_value, :default => configuration[:message])
View
62 activerecord/test/cases/validations_i18n_test.rb
@@ -34,6 +34,12 @@ def reset_callbacks(*models)
end
end
+ def test_default_error_messages_is_deprecated
+ assert_deprecated('ActiveRecord::Errors.default_error_messages') do
+ ActiveRecord::Errors.default_error_messages
+ end
+ end
+
# ActiveRecord::Errors
def test_errors_generate_message_translates_custom_model_attribute_key
@@ -182,18 +188,32 @@ def test_validates_presence_of_finds_global_default_translation
# validates_length_of :within
- def test_validates_length_of_within_generates_message
+ def test_validates_length_of_within_generates_message_with_title_too_short
Topic.validates_length_of :title, :within => 3..5
@topic.errors.expects(:generate_message).with(:title, :too_short, {:count => 3, :default => nil})
@topic.valid?
end
- def test_validates_length_of_within_generates_message_with_custom_default_message
+ def test_validates_length_of_within_generates_message_with_title_too_short_and_custom_default_message
Topic.validates_length_of :title, :within => 3..5, :too_short => 'custom'
@topic.errors.expects(:generate_message).with(:title, :too_short, {:count => 3, :default => 'custom'})
@topic.valid?
end
+ def test_validates_length_of_within_generates_message_with_title_too_long
+ Topic.validates_length_of :title, :within => 3..5
+ @topic.title = 'this title is too long'
+ @topic.errors.expects(:generate_message).with(:title, :too_long, {:count => 5, :default => nil})
+ @topic.valid?
+ end
+
+ def test_validates_length_of_within_generates_message_with_title_too_long_and_custom_default_message
+ Topic.validates_length_of :title, :within => 3..5, :too_long => 'custom'
+ @topic.title = 'this title is too long'
+ @topic.errors.expects(:generate_message).with(:title, :too_long, {:count => 5, :default => 'custom'})
+ @topic.valid?
+ end
+
def test_validates_length_of_within_finds_custom_model_key_translation
I18n.backend.store_translations 'en-US', :active_record => {:error_messages => {:custom => {:topic => {:title => {:too_short => 'custom message'}}}}}
I18n.backend.store_translations 'en-US', :active_record => {:error_messages => {:too_short => 'global message'}}
@@ -382,7 +402,43 @@ def test_validates_exclusion_of_finds_global_default_translation
end
- # validates_numericality_of :only_integer
+ # validates_numericality_of without :only_integer
+
+ def test_validates_numericality_of_generates_message
+ Topic.validates_numericality_of :title
+ @topic.title = 'a'
+ @topic.errors.expects(:generate_message).with(:title, :not_a_number, {:value => 'a', :default => nil})
+ @topic.valid?
+ end
+
+ def test_validates_numericality_of_generates_message_with_custom_default_message
+ Topic.validates_numericality_of :title, :message => 'custom'
+ @topic.title = 'a'
+ @topic.errors.expects(:generate_message).with(:title, :not_a_number, {:value => 'a', :default => 'custom'})
+ @topic.valid?
+ end
+
+ def test_validates_numericality_of_finds_custom_model_key_translation
+ I18n.backend.store_translations 'en-US', :active_record => {:error_messages => {:custom => {:topic => {:title => {:not_a_number => 'custom message'}}}}}
+ I18n.backend.store_translations 'en-US', :active_record => {:error_messages => {:not_a_number => 'global message'}}
+
+ Topic.validates_numericality_of :title
+ @topic.title = 'a'
+ @topic.valid?
+ assert_equal 'custom message', @topic.errors.on(:title)
+ end
+
+ def test_validates_numericality_of_finds_global_default_translation
+ I18n.backend.store_translations 'en-US', :active_record => {:error_messages => {:not_a_number => 'global message'}}
+
+ Topic.validates_numericality_of :title, :only_integer => true
+ @topic.title = 'a'
+ @topic.valid?
+ assert_equal 'global message', @topic.errors.on(:title)
+ end
+
+
+ # validates_numericality_of with :only_integer
def test_validates_numericality_of_only_integer_generates_message
Topic.validates_numericality_of :title, :only_integer => true
Please sign in to comment.
Something went wrong with that request. Please try again.