diff options
author | Alex Robbin <alex.robbin@meyouhealth.com> | 2015-03-26 13:26:19 -0400 |
---|---|---|
committer | Alex Robbin <alex.robbin@meyouhealth.com> | 2015-05-11 09:02:48 -0400 |
commit | cbd66b430b6553e468bcdaa94af661a2d8b69d81 (patch) | |
tree | fbd365f821265d2d3eccaa5a3908814609543f29 /activerecord/test | |
parent | db0e649aba7135133154a35549219cffe968eaf6 (diff) | |
download | rails-cbd66b430b6553e468bcdaa94af661a2d8b69d81.tar.gz rails-cbd66b430b6553e468bcdaa94af661a2d8b69d81.tar.bz2 rails-cbd66b430b6553e468bcdaa94af661a2d8b69d81.zip |
allow setting of a demodulized class name when using STI
If your STI class looks like this:
```ruby
class Company < ActiveRecord::Base
self.store_full_sti_class = false
class GoodCo < Company
end
class BadCo < Company
end
end
```
The expectation (which is valid) is that the `type` in the database is saved as
`GoodCo` or `BadCo`. However, another expectation should be that setting `type`
to `GoodCo` would correctly instantiate the object as a `Company::GoodCo`. That
second expectation is what this should fix.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/inheritance_test.rb | 8 | ||||
-rw-r--r-- | activerecord/test/models/company.rb | 3 |
2 files changed, 11 insertions, 0 deletions
diff --git a/activerecord/test/cases/inheritance_test.rb b/activerecord/test/cases/inheritance_test.rb index 278fa63e04..9199066072 100644 --- a/activerecord/test/cases/inheritance_test.rb +++ b/activerecord/test/cases/inheritance_test.rb @@ -217,6 +217,14 @@ class InheritanceTest < ActiveRecord::TestCase assert_nothing_raised { Client.new(type: 'VerySpecialClient') } end + def test_new_without_storing_full_sti_class + without_store_full_sti_class do + Company::SpecialCo # force autoloading + item = Company.new(type: 'SpecialCo') + assert_instance_of Company::SpecialCo, item + end + end + def test_new_with_autoload_paths path = File.expand_path('../../models/autoloadable', __FILE__) ActiveSupport::Dependencies.autoload_paths << path diff --git a/activerecord/test/models/company.rb b/activerecord/test/models/company.rb index 6961f8fd6f..67936e8e5d 100644 --- a/activerecord/test/models/company.rb +++ b/activerecord/test/models/company.rb @@ -26,6 +26,9 @@ class Company < AbstractCompany def private_method "I am Jack's innermost fears and aspirations" end + + class SpecialCo < Company + end end module Namespaced |