diff options
-rwxr-xr-x | activerecord/lib/active_record/validations.rb | 2 | ||||
-rwxr-xr-x | activerecord/test/cases/validations_test.rb | 8 | ||||
-rw-r--r-- | activerecord/test/models/guid.rb | 2 | ||||
-rw-r--r-- | activerecord/test/schema/schema.rb | 4 |
4 files changed, 15 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb index d25e8cd0da..b3a75121ed 100755 --- a/activerecord/lib/active_record/validations.rb +++ b/activerecord/lib/active_record/validations.rb @@ -640,7 +640,7 @@ module ActiveRecord results = finder_class.with_exclusive_scope do connection.select_all( construct_finder_sql( - :select => "#{attr_name}", + :select => "#{connection.quote_column_name(attr_name)}", :from => "#{finder_class.quoted_table_name}", :conditions => [condition_sql, *condition_params] ) diff --git a/activerecord/test/cases/validations_test.rb b/activerecord/test/cases/validations_test.rb index e3ca8660ac..a4d9da4806 100755 --- a/activerecord/test/cases/validations_test.rb +++ b/activerecord/test/cases/validations_test.rb @@ -5,6 +5,7 @@ require 'models/reply' require 'models/person' require 'models/developer' require 'models/warehouse_thing' +require 'models/guid' # The following methods in Topic are used in test_conditional_validation_* class Topic @@ -493,6 +494,13 @@ class ValidationsTest < ActiveRecord::TestCase end end + def test_validate_uniqueness_with_columns_which_are_sql_keywords + Guid.validates_uniqueness_of :key + g = Guid.new + g.key = "foo" + assert_nothing_raised { !g.valid? } + end + def test_validate_straight_inheritance_uniqueness w1 = IneptWizard.create(:name => "Rincewind", :city => "Ankh-Morpork") assert w1.valid?, "Saving w1" diff --git a/activerecord/test/models/guid.rb b/activerecord/test/models/guid.rb new file mode 100644 index 0000000000..9208dc28fa --- /dev/null +++ b/activerecord/test/models/guid.rb @@ -0,0 +1,2 @@ +class Guid < ActiveRecord::Base +end
\ No newline at end of file diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb index 818237f076..423929fd55 100644 --- a/activerecord/test/schema/schema.rb +++ b/activerecord/test/schema/schema.rb @@ -403,6 +403,10 @@ ActiveRecord::Schema.define do create_table(t, :force => true) { } end + create_table :guids, :force => true do |t| + t.column :key, :string + end + except 'SQLite' do # fk_test_has_fk should be before fk_test_has_pk create_table :fk_test_has_fk, :force => true do |t| |