diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2016-08-25 04:22:48 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2016-08-25 04:22:48 -0300 |
commit | 0510208dd1ff23baa619884c0abcae4d141fae53 (patch) | |
tree | 1c2fdc58d710af54ee07fdfbb2ca00a23e16c2be | |
parent | 804f5b3c2af90b69a51209c56739a077f3fb632b (diff) | |
download | rails-0510208dd1ff23baa619884c0abcae4d141fae53.tar.gz rails-0510208dd1ff23baa619884c0abcae4d141fae53.tar.bz2 rails-0510208dd1ff23baa619884c0abcae4d141fae53.zip |
Add load hooks to all tests classes
Usually users extends tests classes doing something like:
ActionView::TestCase.include MyCustomTestHelpers
This is bad because it will load the ActionView::TestCase right aways
and this will load ActionController::Base making its on_load hooks to
execute early than it should.
One way to fix this is using the on_load hooks of the components like:
ActiveSupport.on_load(:action_view) do
ActionView::TestCase.include MyCustomTestHelpers
end
The problem with this approach is that the test extension will be only
load when ActionView::Base is loaded and this may happen too late in the
test.
To fix this we are adding hooks to people extend the test classes that
will be loaded exactly when the test classes are needed.
-rw-r--r-- | actionmailer/lib/action_mailer/test_case.rb | 1 | ||||
-rw-r--r-- | actionpack/lib/action_controller/test_case.rb | 1 | ||||
-rw-r--r-- | actionview/lib/action_view/test_case.rb | 1 | ||||
-rw-r--r-- | activejob/lib/active_job/test_case.rb | 2 |
4 files changed, 5 insertions, 0 deletions
diff --git a/actionmailer/lib/action_mailer/test_case.rb b/actionmailer/lib/action_mailer/test_case.rb index d3eded547c..1d09a4ee96 100644 --- a/actionmailer/lib/action_mailer/test_case.rb +++ b/actionmailer/lib/action_mailer/test_case.rb @@ -41,6 +41,7 @@ module ActionMailer setup :initialize_test_deliveries setup :set_expected_mail teardown :restore_test_deliveries + ActiveSupport.run_load_hooks(:action_mailer_test_case, self) end module ClassMethods diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index 11a6cf8e15..5b82951212 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -627,6 +627,7 @@ module ActionController include ActionDispatch::Assertions class_attribute :_controller_class setup :setup_controller_request_and_response + ActiveSupport.run_load_hooks(:action_view_test_case, self) end private diff --git a/actionview/lib/action_view/test_case.rb b/actionview/lib/action_view/test_case.rb index 2805cfe612..3eb1ac0826 100644 --- a/actionview/lib/action_view/test_case.rb +++ b/actionview/lib/action_view/test_case.rb @@ -152,6 +152,7 @@ module ActionView included do setup :setup_with_controller + ActiveSupport.run_load_hooks(:action_view_test_case, self) end private diff --git a/activejob/lib/active_job/test_case.rb b/activejob/lib/active_job/test_case.rb index 0d97e00bfa..a5ec45e4a7 100644 --- a/activejob/lib/active_job/test_case.rb +++ b/activejob/lib/active_job/test_case.rb @@ -3,5 +3,7 @@ require "active_support/test_case" module ActiveJob class TestCase < ActiveSupport::TestCase include ActiveJob::TestHelper + + ActiveSupport.run_load_hooks(:active_job_test_case, self) end end |