diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index b487f442b323bd103837185c0b153e8ef46f3d40..c7526beb831529b7242692578b5eaaea3eaebdd0 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Fixed that validations didn't respecting custom setting for too_short, too_long messages #1437 [Marcel Molina] + * Fixed that clear_association_cache doesn't delete new associations on new records (so you can safely place new records in the session with Action Pack without having new associations wiped) #1494 [cluon] * Fixed that calling Model.find([]) returns [] and doesn't throw an exception #1379 diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb index d58502e98bd9300b4a46b890fa7a746d4032ca55..e42b306e109a8f66ee7db62419d2ea4544edded2 100755 --- a/activerecord/lib/active_record/validations.rb +++ b/activerecord/lib/active_record/validations.rb @@ -213,12 +213,6 @@ module ClassMethods :message => nil }.freeze - DEFAULT_SIZE_VALIDATION_OPTIONS = DEFAULT_VALIDATION_OPTIONS.merge( - :too_long => ActiveRecord::Errors.default_error_messages[:too_long], - :too_short => ActiveRecord::Errors.default_error_messages[:too_short], - :wrong_length => ActiveRecord::Errors.default_error_messages[:wrong_length] - ).freeze - ALL_RANGE_OPTIONS = [ :is, :within, :in, :minimum, :maximum ].freeze def validate(*methods, &block) @@ -404,7 +398,9 @@ def validates_presence_of(*attr_names) # method, proc or string should return or evaluate to a true or false value. def validates_length_of(*attrs) # Merge given options with defaults. - options = DEFAULT_SIZE_VALIDATION_OPTIONS.dup + options = {:too_long => ActiveRecord::Errors.default_error_messages[:too_long], + :too_short => ActiveRecord::Errors.default_error_messages[:too_short], + :wrong_length => ActiveRecord::Errors.default_error_messages[:wrong_length]}.merge(DEFAULT_VALIDATION_OPTIONS) options.update(attrs.pop.symbolize_keys) if attrs.last.is_a?(Hash) # Ensure that one and only one range option is specified. diff --git a/activerecord/test/validations_test.rb b/activerecord/test/validations_test.rb index 2cce21597ab94c84dc4c34a501d7029c360bd14a..2ff618b0e6bdf774f94cb00f863f7d06ce67bc1a 100755 --- a/activerecord/test/validations_test.rb +++ b/activerecord/test/validations_test.rb @@ -493,6 +493,15 @@ def test_validates_length_of_using_bignum end end + def test_validates_length_with_globaly_modified_error_message + ActiveRecord::Errors.default_error_messages[:too_short] = 'tu est trops petit hombre %d' + Topic.validates_length_of :title, :minimum => 10 + t = Topic.create(:title => 'too short') + assert !t.valid? + + assert_equal 'tu est trops petit hombre 10', t.errors['title'] + end + def test_validates_size_of_association assert_nothing_raised { Topic.validates_size_of :replies, :minimum => 1 } t = Topic.new('title' => 'noreplies', 'content' => 'whatever')