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
3
3
extend ActiveSupport ::Concern
4
4
5
5
module ClassMethods
6
- def configs_from ( application )
6
+ def configs_from ( mod )
7
7
app_model = self
8
8
9
- application . singleton_class . instance_eval do
9
+ mod . singleton_class . instance_eval do
10
10
define_method ( :application_model ) { app_model }
11
11
end
12
12
13
13
define_singleton_method ( :configs_from_application ) { application }
14
14
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
15
29
end
16
30
end
17
31
end
Original file line number Diff line number Diff line change @@ -815,7 +815,7 @@ def after_teardown
815
815
self . use_transactional_fixtures = true
816
816
self . use_instantiated_fixtures = false
817
817
self . pre_loaded_fixtures = false
818
- self . config = ActiveRecord ::Base
818
+ self . config = ActiveRecord ::Base . application_model
819
819
820
820
self . fixture_class_names = Hash . new do |h , fixture_set_name |
821
821
h [ fixture_set_name ] = ActiveRecord ::FixtureSet . default_fixture_model_name ( fixture_set_name , self . config )
@@ -919,7 +919,7 @@ def run_in_transaction?
919
919
!self . class . uses_transaction? ( method_name )
920
920
end
921
921
922
- def setup_fixtures ( config = ActiveRecord :: Base )
922
+ def setup_fixtures
923
923
if pre_loaded_fixtures && !use_transactional_fixtures
924
924
raise RuntimeError , 'pre_loaded_fixtures requires use_transactional_fixtures'
925
925
end
@@ -928,6 +928,7 @@ def setup_fixtures(config = ActiveRecord::Base)
928
928
@fixture_connections = [ ]
929
929
@@already_loaded_fixtures ||= { }
930
930
931
+ config = ActiveRecord ::Base . application_model
931
932
# Load fixtures once and begin transaction.
932
933
if run_in_transaction?
933
934
if @@already_loaded_fixtures [ self . class ]
Original file line number Diff line number Diff line change 3
3
require 'active_record/base'
4
4
5
5
module ActiveRecord
6
- class SchemaMigration < ActiveRecord :: Base
6
+ class SchemaMigration < ApplicationModel
7
7
class << self
8
8
9
9
def table_name
Original file line number Diff line number Diff line change 1
1
class ApplicationModel < ActiveRecord::Base
2
2
self.abstract_class = true
3
- configs_from Rails.application
4
3
end
Original file line number Diff line number Diff line change @@ -99,7 +99,7 @@ def test_should_not_eager_load_model_for_rake
99
99
end
100
100
101
101
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" ,
103
103
Dir . chdir ( app_path ) { `rake stats` }
104
104
end
105
105
You can’t perform that action at this time.
0 commit comments