Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #11019 from tkhr/test_case_for_issue_10393

Add test case for issue #10393 and fix warning message
  • Loading branch information...
commit 63d4894a58825e9d1fb520ec6ac663e4d8529596 2 parents cacfa8e + 839efc5
Yves Senn senny authored
5 activerecord/CHANGELOG.md
View
@@ -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.
2  activerecord/lib/active_record/model_schema.rb
View
@@ -159,7 +159,7 @@ def full_table_name_prefix #:nodoc:
# 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
23 activerecord/test/cases/inheritance_test.rb
View
@@ -290,3 +290,26 @@ def test_instantiation_doesnt_try_to_require_corresponding_file
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
Please sign in to comment.
Something went wrong with that request. Please try again.