diff options
author | Yves Senn <yves.senn@gmail.com> | 2015-12-02 17:02:11 +0100 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2015-12-02 17:14:45 +0100 |
commit | 72b92e817281ddc74e587295fcaa5422cdca01f8 (patch) | |
tree | 058633bbc19c62ce6008afb2a13ed65757974ba8 /activerecord/test | |
parent | 4294a7eebf52759be61ed57908436d6324f26120 (diff) | |
download | rails-72b92e817281ddc74e587295fcaa5422cdca01f8.tar.gz rails-72b92e817281ddc74e587295fcaa5422cdca01f8.tar.bz2 rails-72b92e817281ddc74e587295fcaa5422cdca01f8.zip |
don't rely on the columns hash to get defaults. follow-up to #17169.
This will also get the defaults from attribute definitions like:
attribute :type, :string, default: "SomethingElse"
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/inheritance_test.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/activerecord/test/cases/inheritance_test.rb b/activerecord/test/cases/inheritance_test.rb index 2ad8b30eae..03bce547da 100644 --- a/activerecord/test/cases/inheritance_test.rb +++ b/activerecord/test/cases/inheritance_test.rb @@ -500,3 +500,27 @@ class InheritanceComputeTypeTest < ActiveRecord::TestCase Company.reset_column_information end end + +class InheritanceAttributeTest < ActiveRecord::TestCase + + class Company < ActiveRecord::Base + self.table_name = 'companies' + attribute :type, :string, default: "InheritanceAttributeTest::Startup" + end + + class Startup < Company + end + + class Empire < Company + end + + def test_inheritance_new_with_subclass_as_default + startup = Company.new # without arguments + assert_equal 'InheritanceAttributeTest::Startup', startup.type + assert_instance_of Startup, startup + + empire = Company.new(type: 'InheritanceAttributeTest::Empire') # without arguments + assert_equal 'InheritanceAttributeTest::Empire', empire.type + assert_instance_of Empire, empire + end +end |