mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #42239 from eileencodes/fix-primary-abstract-class-in-lazy-loaded-env
Fix primary_abstract_class in lazy loaded envs
This commit is contained in:
commit
5ddff2beb1
2 changed files with 21 additions and 1 deletions
|
@ -209,7 +209,6 @@ module ActiveRecord
|
|||
self == Base.application_record_class
|
||||
else
|
||||
if defined?(ApplicationRecord) && self == ApplicationRecord
|
||||
Base.application_record_class = self
|
||||
true
|
||||
end
|
||||
end
|
||||
|
|
|
@ -79,6 +79,27 @@ class PrimaryClassTest < ActiveRecord::TestCase
|
|||
Object.send(:remove_const, :ApplicationRecord)
|
||||
end
|
||||
|
||||
def test_setting_primary_abstract_class_explicitly_wins_over_application_record_set_implicitly
|
||||
Object.const_set(:ApplicationRecord, ApplicationRecord)
|
||||
|
||||
assert_predicate ApplicationRecord, :primary_class?
|
||||
assert_predicate ApplicationRecord, :application_record_class?
|
||||
assert_predicate ApplicationRecord, :abstract_class?
|
||||
|
||||
PrimaryClassTest::PrimaryAppRecord.primary_abstract_class
|
||||
|
||||
assert_predicate PrimaryClassTest::PrimaryAppRecord, :primary_class?
|
||||
assert_predicate PrimaryClassTest::PrimaryAppRecord, :application_record_class?
|
||||
assert_predicate PrimaryClassTest::PrimaryAppRecord, :abstract_class?
|
||||
|
||||
assert_not_predicate ApplicationRecord, :primary_class?
|
||||
assert_not_predicate ApplicationRecord, :application_record_class?
|
||||
assert_predicate ApplicationRecord, :abstract_class?
|
||||
ensure
|
||||
ActiveRecord::Base.application_record_class = nil
|
||||
Object.send(:remove_const, :ApplicationRecord)
|
||||
end
|
||||
|
||||
unless in_memory_db?
|
||||
def test_application_record_shares_a_connection_with_active_record_by_default
|
||||
Object.const_set(:ApplicationRecord, ApplicationRecord)
|
||||
|
|
Loading…
Reference in a new issue