File tree Expand file tree Collapse file tree 5 files changed +21
-7
lines changed
activerecord/lib/active_record
lib/rails/generators/rails/app/templates/app/models Expand file tree Collapse file tree 5 files changed +21
-7
lines changed Original file line number Diff line number Diff line change @@ -3,15 +3,29 @@ module ApplicationConfiguration
33 extend ActiveSupport ::Concern
44
55 module ClassMethods
6- def configs_from ( application )
6+ def configs_from ( mod )
77 app_model = self
88
9- application . singleton_class . instance_eval do
9+ mod . singleton_class . instance_eval do
1010 define_method ( :application_model ) { app_model }
1111 end
1212
1313 define_singleton_method ( :configs_from_application ) { application }
1414 end
15+
16+ def application_model ( klass = nil )
17+ return ActiveRecord ::Base unless klass
18+
19+ klass = klass . class unless klass . respond_to? ( :parents )
20+
21+ if klass . respond_to? ( :application_model )
22+ klass . application_model
23+ elsif app_model = klass . parents . detect { |p | p . respond_to? ( :application_model ) }
24+ app_model
25+ else
26+ ActiveRecord ::Base
27+ end
28+ end
1529 end
1630 end
1731end
Original file line number Diff line number Diff line change @@ -837,7 +837,7 @@ def after_teardown
837837 self . use_transactional_fixtures = true
838838 self . use_instantiated_fixtures = false
839839 self . pre_loaded_fixtures = false
840- self . config = ActiveRecord ::Base
840+ self . config = ActiveRecord ::Base . application_model
841841
842842 self . fixture_class_names = Hash . new do |h , fixture_set_name |
843843 h [ fixture_set_name ] = ActiveRecord ::FixtureSet . default_fixture_model_name ( fixture_set_name , self . config )
@@ -916,7 +916,7 @@ def run_in_transaction?
916916 !self . class . uses_transaction? ( method_name )
917917 end
918918
919- def setup_fixtures ( config = ActiveRecord :: Base )
919+ def setup_fixtures
920920 if pre_loaded_fixtures && !use_transactional_fixtures
921921 raise RuntimeError , 'pre_loaded_fixtures requires use_transactional_fixtures'
922922 end
@@ -925,6 +925,7 @@ def setup_fixtures(config = ActiveRecord::Base)
925925 @fixture_connections = [ ]
926926 @@already_loaded_fixtures ||= { }
927927
928+ config = ActiveRecord ::Base . application_model
928929 # Load fixtures once and begin transaction.
929930 if run_in_transaction?
930931 if @@already_loaded_fixtures [ self . class ]
Original file line number Diff line number Diff line change 33require 'active_record/base'
44
55module ActiveRecord
6- class SchemaMigration < ActiveRecord :: Base
6+ class SchemaMigration < ApplicationModel
77 class << self
88 def primary_key
99 nil
Original file line number Diff line number Diff line change 11class ApplicationModel < ActiveRecord::Base
22 self.abstract_class = true
3- configs_from Rails.application
43end
Original file line number Diff line number Diff line change @@ -99,7 +99,7 @@ def test_should_not_eager_load_model_for_rake
9999 end
100100
101101 def test_code_statistics_sanity
102- assert_match "Code LOC: 9 Test LOC: 0 Code to Test Ratio: 1:0.0" ,
102+ assert_match "Code LOC: 8 Test LOC: 0 Code to Test Ratio: 1:0.0" ,
103103 Dir . chdir ( app_path ) { `rake stats` }
104104 end
105105
You can’t perform that action at this time.
0 commit comments