diff options
author | Rodrigo Kochenburger <divoxx@gmail.com> | 2008-04-11 12:35:09 -0300 |
---|---|---|
committer | rick <technoweenie@gmail.com> | 2008-05-13 15:04:11 -0700 |
commit | bca8751e40a5594c4de2ca58e089b8d98e44632b (patch) | |
tree | 34a89b57cdf2ac2092c103975eeb2fa0f51c03e8 /activerecord/test | |
parent | 2d372d704987e05712ccd937e78d8dbd41242efe (diff) | |
download | rails-bca8751e40a5594c4de2ca58e089b8d98e44632b.tar.gz rails-bca8751e40a5594c4de2ca58e089b8d98e44632b.tar.bz2 rails-bca8751e40a5594c4de2ca58e089b8d98e44632b.zip |
Add ActiveRecord option to store the full class name on STI's type column, allowing one to have STI subclasses in different namespaces [#114]
Signed-off-by: rick <technoweenie@gmail.com>
Diffstat (limited to 'activerecord/test')
-rwxr-xr-x | activerecord/test/cases/inheritance_test.rb | 28 | ||||
-rwxr-xr-x | activerecord/test/models/company.rb | 4 |
2 files changed, 32 insertions, 0 deletions
diff --git a/activerecord/test/cases/inheritance_test.rb b/activerecord/test/cases/inheritance_test.rb index c9eb83e371..27394924a1 100755 --- a/activerecord/test/cases/inheritance_test.rb +++ b/activerecord/test/cases/inheritance_test.rb @@ -5,6 +5,34 @@ require 'models/subscriber' class InheritanceTest < ActiveRecord::TestCase fixtures :companies, :projects, :subscribers, :accounts + + def test_should_store_demodulized_class_name_with_store_full_sti_class_option_disabled + old = ActiveRecord::Base.store_full_sti_class + ActiveRecord::Base.store_full_sti_class = false + item = Namespaced::Company.new + assert_equal 'Company', item[:type] + ensure + ActiveRecord::Base.store_full_sti_class = old + end + + def test_should_store_full_class_name_with_store_full_sti_class_option_enabled + old = ActiveRecord::Base.store_full_sti_class + ActiveRecord::Base.store_full_sti_class = true + item = Namespaced::Company.new + assert_equal 'Namespaced::Company', item[:type] + ensure + ActiveRecord::Base.store_full_sti_class = old + end + + def test_different_namespace_subclass_should_load_correctly_with_store_full_sti_class_option + old = ActiveRecord::Base.store_full_sti_class + ActiveRecord::Base.store_full_sti_class = true + item = Namespaced::Company.create :name => "Wolverine 2" + assert_not_nil Company.find(item.id) + assert_not_nil Namespaced::Company.find(item.id) + ensure + ActiveRecord::Base.store_full_sti_class = old + end def test_company_descends_from_active_record assert_raise(NoMethodError) { ActiveRecord::Base.descends_from_active_record? } diff --git a/activerecord/test/models/company.rb b/activerecord/test/models/company.rb index 3d76dfd398..f637490c59 100755 --- a/activerecord/test/models/company.rb +++ b/activerecord/test/models/company.rb @@ -15,6 +15,10 @@ class Company < AbstractCompany end end +module Namespaced + class Company < ::Company + end +end class Firm < Company has_many :clients, :order => "id", :dependent => :destroy, :counter_sql => |