@@ -37,28 +37,50 @@ def run_in_transaction?
37
37
module Fixtures
38
38
extend ActiveSupport ::Concern
39
39
40
+ # rubocop:disable Metrics/BlockLength
40
41
class_methods do
41
- def fixtures ( *args )
42
- orig_methods = private_instance_methods
43
- super . tap do
44
- new_methods = private_instance_methods - orig_methods
45
- new_methods . each do |method_name |
46
- proxy_method_warning_if_called_in_before_context_scope ( method_name )
42
+ if ::Rails . version . to_f >= 7.1
43
+ def fixtures ( *args )
44
+ super . tap do
45
+ fixture_sets . each_key do |fixture_name |
46
+ proxy_method_warning_if_called_in_before_context_scope ( fixture_name )
47
+ end
48
+ end
49
+ end
50
+
51
+ def proxy_method_warning_if_called_in_before_context_scope ( fixture_name )
52
+ define_method ( fixture_name ) do |*args , **kwargs , &blk |
53
+ if RSpec . current_scope == :before_context_hook
54
+ RSpec . warn_with ( "Calling fixture method in before :context " )
55
+ else
56
+ access_fixture ( fixture_name , *args , **kwargs , &blk )
57
+ end
58
+ end
59
+ end
60
+ else
61
+ def fixtures ( *args )
62
+ orig_methods = private_instance_methods
63
+ super . tap do
64
+ new_methods = private_instance_methods - orig_methods
65
+ new_methods . each do |method_name |
66
+ proxy_method_warning_if_called_in_before_context_scope ( method_name )
67
+ end
47
68
end
48
69
end
49
- end
50
70
51
- def proxy_method_warning_if_called_in_before_context_scope ( method_name )
52
- orig_implementation = instance_method ( method_name )
53
- define_method ( method_name ) do |*args , &blk |
54
- if RSpec . current_scope == :before_context_hook
55
- RSpec . warn_with ( "Calling fixture method in before :context " )
56
- else
57
- orig_implementation . bind ( self ) . call ( *args , &blk )
71
+ def proxy_method_warning_if_called_in_before_context_scope ( method_name )
72
+ orig_implementation = instance_method ( method_name )
73
+ define_method ( method_name ) do |*args , &blk |
74
+ if RSpec . current_scope == :before_context_hook
75
+ RSpec . warn_with ( "Calling fixture method in before :context " )
76
+ else
77
+ orig_implementation . bind ( self ) . call ( *args , &blk )
78
+ end
58
79
end
59
80
end
60
81
end
61
82
end
83
+ # rubocop:enable Metrics/BlockLength
62
84
end
63
85
end
64
86
end
0 commit comments