File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed
lib/rails_console_commands Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ class << self
88 def fork
99 Environment . fork do
1010 setup_for_test
11- yield
11+ disable_reloading { yield }
1212 end
1313
1414 reset_active_record
@@ -21,9 +21,19 @@ def setup_for_test
2121 add_test_dir_to_load_path
2222 end
2323
24+ # Code should not be reloaded while tests are running, as this tends
25+ # to cause Active Record connection errors, and causes unreliable test runs.
26+ # `reload_classes` will ensure that the code is reloaded before tests commence.
27+ def disable_reloading
28+ was = Rails . application . reloader . check
29+ Rails . application . reloader . check = lambda { false }
30+
31+ yield
32+ ensure
33+ Rails . application . reloader . check = was
34+ end
35+
2436 def reload_classes
25- # Overwrite the default config.cache_classes = true,
26- # so we can change classes in the test session.
2737 if ActiveSupport ::Dependencies . respond_to? ( :mechanism= ) # Rails < 7
2838 ActiveSupport ::Dependencies . mechanism = :load
2939 end
You can’t perform that action at this time.
0 commit comments