diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb index 9220eae..7f34f6b 100644 --- a/activerecord/lib/active_record/validations.rb +++ b/activerecord/lib/active_record/validations.rb @@ -706,6 +706,7 @@ module ActiveRecord configuration.update(attr_names.extract_options!) validates_each(attr_names,configuration) do |record, attr_name, value| + next unless record.send("#{attr_name}_changed?".to_sym) # The check for an existing value should be run from a class that # isn't abstract. This means working down from the current class # (self), to the first non-abstract class. Since classes don't know diff --git a/activerecord/test/cases/validations_test.rb b/activerecord/test/cases/validations_test.rb index c049659..aa1311f 100644 --- a/activerecord/test/cases/validations_test.rb +++ b/activerecord/test/cases/validations_test.rb @@ -362,6 +362,15 @@ class ValidationsTest < ActiveRecord::TestCase t2.title = "Now Im really also unique" assert t2.save, "Should now save t2 as unique" + + t2.content = "Title still unique and untouched since last modification" + assert_queries(1) do + t2.save + end + t2.title = "Title changed, but unque" + assert_queries(2) do + t2.save + end end def test_validates_uniquness_with_newline_chars