diff options
author | Jenner LaFave <jenner@jfave.com> | 2014-05-02 18:00:53 -0700 |
---|---|---|
committer | Jenner LaFave <jenner@jfave.com> | 2014-05-05 12:41:26 -0700 |
commit | 5de7309b7b773a8c9eb5ef71ffdd9a79e08dda3c (patch) | |
tree | e380fd719ac1f68113b32772c0bf82b2ddfd61ed /activerecord/test | |
parent | 4efb0f373047c44249bc6542fdf9969e4c63dd88 (diff) | |
download | rails-5de7309b7b773a8c9eb5ef71ffdd9a79e08dda3c.tar.gz rails-5de7309b7b773a8c9eb5ef71ffdd9a79e08dda3c.tar.bz2 rails-5de7309b7b773a8c9eb5ef71ffdd9a79e08dda3c.zip |
Add support for module-level table_suffix in models
This makes table_name_suffix work the same as table_name_prefix when
using namespaced models. Pretty much the same as 67d1cec.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/modules_test.rb | 28 | ||||
-rw-r--r-- | activerecord/test/models/company_in_module.rb | 18 |
2 files changed, 46 insertions, 0 deletions
diff --git a/activerecord/test/cases/modules_test.rb b/activerecord/test/cases/modules_test.rb index f7db195521..e87773df94 100644 --- a/activerecord/test/cases/modules_test.rb +++ b/activerecord/test/cases/modules_test.rb @@ -112,6 +112,34 @@ class ModulesTest < ActiveRecord::TestCase classes.each(&:reset_table_name) end + def test_module_table_name_suffix + assert_equal 'companies_suffixed', MyApplication::Business::Suffixed::Company.table_name, 'inferred table_name for ActiveRecord model in module with table_name_suffix' + assert_equal 'companies_suffixed', MyApplication::Business::Suffixed::Nested::Company.table_name, 'table_name for ActiveRecord model in nested module with a parent table_name_suffix' + assert_equal 'companies', MyApplication::Business::Suffixed::Firm.table_name, 'explicit table_name for ActiveRecord model in module with table_name_suffix should not be suffixed' + end + + def test_module_table_name_suffix_with_global_suffix + classes = [ MyApplication::Business::Company, + MyApplication::Business::Firm, + MyApplication::Business::Client, + MyApplication::Business::Client::Contact, + MyApplication::Business::Developer, + MyApplication::Business::Project, + MyApplication::Business::Suffixed::Company, + MyApplication::Business::Suffixed::Nested::Company, + MyApplication::Billing::Account ] + + ActiveRecord::Base.table_name_suffix = '_global' + classes.each(&:reset_table_name) + assert_equal 'companies_global', MyApplication::Business::Company.table_name, 'inferred table_name for ActiveRecord model in module without table_name_suffix' + assert_equal 'companies_suffixed', MyApplication::Business::Suffixed::Company.table_name, 'inferred table_name for ActiveRecord model in module with table_name_suffix' + assert_equal 'companies_suffixed', MyApplication::Business::Suffixed::Nested::Company.table_name, 'table_name for ActiveRecord model in nested module with a parent table_name_suffix' + assert_equal 'companies', MyApplication::Business::Suffixed::Firm.table_name, 'explicit table_name for ActiveRecord model in module with table_name_suffix should not be suffixed' + ensure + ActiveRecord::Base.table_name_suffix = '' + classes.each(&:reset_table_name) + end + def test_compute_type_can_infer_class_name_of_sibling_inside_module old = ActiveRecord::Base.store_full_sti_class ActiveRecord::Base.store_full_sti_class = true diff --git a/activerecord/test/models/company_in_module.rb b/activerecord/test/models/company_in_module.rb index 38b0b6aafa..dae102d12b 100644 --- a/activerecord/test/models/company_in_module.rb +++ b/activerecord/test/models/company_in_module.rb @@ -46,6 +46,24 @@ module MyApplication end end end + + module Suffixed + def self.table_name_suffix + '_suffixed' + end + + class Company < ActiveRecord::Base + end + + class Firm < Company + self.table_name = 'companies' + end + + module Nested + class Company < ActiveRecord::Base + end + end + end end module Billing |