Permalink
Browse files

make set_table_name take effect immediately

  • Loading branch information...
1 parent ac86923 commit 9643243204fab063630380f42fcd4b8160044104 @janx janx committed with tenderlove Feb 3, 2011
@@ -636,6 +636,9 @@ def reset_sequence_name #:nodoc:
def set_table_name(value = nil, &block)
@quoted_table_name = nil
define_attr_method :table_name, value, &block
+
+ @arel_table = Arel::Table.new(table_name, :engine => arel_engine)
+ @relation = Relation.new(self, arel_table)
end
alias :table_name= :set_table_name
@@ -20,6 +20,7 @@
require 'models/parrot'
require 'models/loose_person'
require 'models/edge'
+require 'models/joke'
require 'rexml/document'
require 'active_support/core_ext/exception'
@@ -1156,6 +1157,16 @@ def test_set_table_name_with_value
assert_equal "bar", k.table_name
end
+ def test_switching_between_table_name
+ assert_difference("GoodJoke.count") do
+ Joke.set_table_name "cold_jokes"
+ Joke.create
+
+ Joke.set_table_name "funny_jokes"
+ Joke.create
+ end
+ end
+
def test_quoted_table_name_after_set_table_name
klass = Class.new(ActiveRecord::Base)
@@ -1,3 +1,7 @@
class Joke < ActiveRecord::Base
set_table_name 'funny_jokes'
end
+
+class GoodJoke < ActiveRecord::Base
+ set_table_name 'funny_jokes'
+end
@@ -229,6 +229,10 @@ def create_table(*args, &block)
t.string :name
end
+ create_table :cold_jokes, :force => true do |t|
+ t.string :name
+ end
+
create_table :goofy_string_id, :force => true, :id => false do |t|
t.string :id, :null => false
t.string :info

0 comments on commit 9643243

Please sign in to comment.