diff options
author | Yves Senn <yves.senn@gmail.com> | 2013-06-25 23:42:35 -0700 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2013-06-25 23:42:35 -0700 |
commit | 63d4894a58825e9d1fb520ec6ac663e4d8529596 (patch) | |
tree | f2648ea726d1096975b0470f7ca1d70947899982 | |
parent | cacfa8e3fb2cff59956a39a2640c8e3ade4b54c6 (diff) | |
parent | 839efc5b6d754697682d5b2bd34ef28b2c5d2adf (diff) | |
download | rails-63d4894a58825e9d1fb520ec6ac663e4d8529596.tar.gz rails-63d4894a58825e9d1fb520ec6ac663e4d8529596.tar.bz2 rails-63d4894a58825e9d1fb520ec6ac663e4d8529596.zip |
Merge pull request #11019 from tkhr/test_case_for_issue_10393
Add test case for issue #10393 and fix warning message
-rw-r--r-- | activerecord/CHANGELOG.md | 5 | ||||
-rw-r--r-- | activerecord/lib/active_record/model_schema.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/inheritance_test.rb | 23 |
3 files changed, 29 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index c673a278f6..3c38b47d2e 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -5,6 +5,11 @@ *Janko Marohnić* +* Fix a bug that prevented the use of the default STI inheritance column + (ActiveRecord::Base.inheritance_column = 'some_column'.) + + *chapmajs + Takehiro Adachi* + * Fix mysql2 adapter raises the correct exception when executing a query on a closed connection. diff --git a/activerecord/lib/active_record/model_schema.rb b/activerecord/lib/active_record/model_schema.rb index e10e6b4aa8..40cc8dcd69 100644 --- a/activerecord/lib/active_record/model_schema.rb +++ b/activerecord/lib/active_record/model_schema.rb @@ -159,7 +159,7 @@ module ActiveRecord # The name of the column containing the object's class when Single Table Inheritance is used def inheritance_column if self == Base - 'type' + (@inheritance_column ||= nil) || 'type' else (@inheritance_column ||= nil) || superclass.inheritance_column end diff --git a/activerecord/test/cases/inheritance_test.rb b/activerecord/test/cases/inheritance_test.rb index 54c9152c06..99a252a389 100644 --- a/activerecord/test/cases/inheritance_test.rb +++ b/activerecord/test/cases/inheritance_test.rb @@ -290,3 +290,26 @@ class InheritanceComputeTypeTest < ActiveRecord::TestCase ActiveRecord::Base.store_full_sti_class = true end end + + +class GlobalInheritanceColumnTest < ActiveRecord::TestCase + fixtures :companies + + setup do + @inheritance_column = ActiveRecord::Base.inheritance_column + end + + teardown do + ActiveRecord::Base.inheritance_column = @inheritance_column + end + + def test_changing_global_inheritance_column + ActiveRecord::Base.inheritance_column = 'ruby_type' + + firm = Firm.create('name' => 'FirmWithAltInheritanceColumn') + assert_equal 'Firm', firm.ruby_type + + assert_equal 'ruby_type', Company.inheritance_column + assert_equal 'ruby_type', Firm.inheritance_column + end +end |