diff options
author | Jason Rush <diminish7@gmail.com> | 2012-04-05 13:21:48 -0600 |
---|---|---|
committer | Andrew White <andyw@pixeltrix.co.uk> | 2012-11-29 05:50:34 +0000 |
commit | 89b5b31cc4f8407f648a2447665ef23f9024e8a5 (patch) | |
tree | 721b47a8f33bf70851736164bf4a80cdd7c59e94 /activerecord/test/cases/inheritance_test.rb | |
parent | eba430aecbce963f5b2d91ef6a9c36aec8c824bb (diff) | |
download | rails-89b5b31cc4f8407f648a2447665ef23f9024e8a5.tar.gz rails-89b5b31cc4f8407f648a2447665ef23f9024e8a5.tar.bz2 rails-89b5b31cc4f8407f648a2447665ef23f9024e8a5.zip |
Added STI support to init and building associations
Allows you to do BaseClass.new(:type => "SubClass") as well as
parent.children.build(:type => "SubClass") or parent.build_child
to initialize an STI subclass. Ensures that the class name is a
valid class and that it is in the ancestors of the super class
that the association is expecting.
Diffstat (limited to 'activerecord/test/cases/inheritance_test.rb')
-rw-r--r-- | activerecord/test/cases/inheritance_test.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/activerecord/test/cases/inheritance_test.rb b/activerecord/test/cases/inheritance_test.rb index aab7aa51dd..2466a764f6 100644 --- a/activerecord/test/cases/inheritance_test.rb +++ b/activerecord/test/cases/inheritance_test.rb @@ -156,6 +156,29 @@ class InheritanceTest < ActiveRecord::TestCase assert_kind_of Cabbage, savoy end + def test_inheritance_new_with_default_class + company = Company.new + assert_equal company.class, Company + end + + def test_inheritance_new_with_base_class + company = Company.new(:type => 'Company') + assert_equal company.class, Company + end + + def test_inheritance_new_with_subclass + firm = Company.new(:type => 'Firm') + assert_equal firm.class, Firm + end + + def test_new_with_invalid_type + assert_raise(ActiveRecord::SubclassNotFound) { Company.new(:type => 'InvalidType') } + end + + def test_new_with_unrelated_type + assert_raise(ActiveRecord::SubclassNotFound) { Company.new(:type => 'Account') } + end + def test_inheritance_condition assert_equal 10, Company.count assert_equal 2, Firm.count |