aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/modules_test.rb
diff options
context:
space:
mode:
authorAndrew White <andyw@pixeltrix.co.uk>2010-02-22 10:46:45 +0000
committerwycats <wycats@gmail.com>2010-03-28 23:43:28 -0700
commit67d1cec4c8a65846cc3b2779bc5eca7b8b73e6fc (patch)
tree861e8f3b51c78e2b0aee197cbaf5f189e77666ff /activerecord/test/cases/modules_test.rb
parent48c1d8c341e1fe09111424131f7d223ad032b7e1 (diff)
downloadrails-67d1cec4c8a65846cc3b2779bc5eca7b8b73e6fc.tar.gz
rails-67d1cec4c8a65846cc3b2779bc5eca7b8b73e6fc.tar.bz2
rails-67d1cec4c8a65846cc3b2779bc5eca7b8b73e6fc.zip
Add the ability to specify table_name_prefix on individual modules
Signed-off-by: wycats <wycats@gmail.com>
Diffstat (limited to 'activerecord/test/cases/modules_test.rb')
-rw-r--r--activerecord/test/cases/modules_test.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/activerecord/test/cases/modules_test.rb b/activerecord/test/cases/modules_test.rb
index d781a229f4..7209966bf8 100644
--- a/activerecord/test/cases/modules_test.rb
+++ b/activerecord/test/cases/modules_test.rb
@@ -82,4 +82,32 @@ class ModulesTest < ActiveRecord::TestCase
end
end
end
+
+ def test_module_table_name_prefix
+ assert_equal 'prefixed_companies', MyApplication::Business::Prefixed::Company.table_name, 'inferred table_name for ActiveRecord model in module with table_name_prefix'
+ assert_equal 'prefixed_companies', MyApplication::Business::Prefixed::Nested::Company.table_name, 'table_name for ActiveRecord model in nested module with a parent table_name_prefix'
+ assert_equal 'companies', MyApplication::Business::Prefixed::Firm.table_name, 'explicit table_name for ActiveRecord model in module with table_name_prefix should not be prefixed'
+ end
+
+ def test_module_table_name_prefix_with_global_prefix
+ classes = [ MyApplication::Business::Company,
+ MyApplication::Business::Firm,
+ MyApplication::Business::Client,
+ MyApplication::Business::Client::Contact,
+ MyApplication::Business::Developer,
+ MyApplication::Business::Project,
+ MyApplication::Business::Prefixed::Company,
+ MyApplication::Business::Prefixed::Nested::Company,
+ MyApplication::Billing::Account ]
+
+ ActiveRecord::Base.table_name_prefix = 'global_'
+ classes.each(&:reset_table_name)
+ assert_equal 'global_companies', MyApplication::Business::Company.table_name, 'inferred table_name for ActiveRecord model in module without table_name_prefix'
+ assert_equal 'prefixed_companies', MyApplication::Business::Prefixed::Company.table_name, 'inferred table_name for ActiveRecord model in module with table_name_prefix'
+ assert_equal 'prefixed_companies', MyApplication::Business::Prefixed::Nested::Company.table_name, 'table_name for ActiveRecord model in nested module with a parent table_name_prefix'
+ assert_equal 'companies', MyApplication::Business::Prefixed::Firm.table_name, 'explicit table_name for ActiveRecord model in module with table_name_prefix should not be prefixed'
+ ensure
+ ActiveRecord::Base.table_name_prefix = ''
+ classes.each(&:reset_table_name)
+ end
end