From 47c9a355062888feb2c7ea7c794e914a9b78f50c Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sat, 15 May 2010 18:53:47 +0100 Subject: [PATCH] Reset quoted_table_name after set_table_name [#4568 state:resolved] Signed-off-by: Pratik Naik --- activerecord/lib/active_record/base.rb | 2 +- activerecord/test/cases/base_test.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index e7319ce8b9..04c474c9a1 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -668,7 +668,6 @@ module ActiveRecord #:nodoc: name = "#{full_table_name_prefix}#{contained}#{undecorated_table_name(base.name)}#{table_name_suffix}" end - @quoted_table_name = nil set_table_name(name) name end @@ -702,6 +701,7 @@ module ActiveRecord #:nodoc: # set_table_name "project" # end def set_table_name(value = nil, &block) + @quoted_table_name = nil define_attr_method :table_name, value, &block end alias :table_name= :set_table_name diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index bbc4e543d5..b7ae619787 100755 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -1793,6 +1793,18 @@ class BasicsTest < ActiveRecord::TestCase assert_equal "bar", k.table_name end + def test_quoted_table_name_after_set_table_name + klass = Class.new(ActiveRecord::Base) + + klass.set_table_name "foo" + assert_equal "foo", klass.table_name + assert_equal klass.connection.quote_table_name("foo"), klass.quoted_table_name + + klass.set_table_name "bar" + assert_equal "bar", klass.table_name + assert_equal klass.connection.quote_table_name("bar"), klass.quoted_table_name + end + def test_set_table_name_with_block k = Class.new( ActiveRecord::Base ) k.set_table_name { "ks" }