Skip to content

Commit

Permalink
Ensure that our load hooks really for real run after Rails
Browse files Browse the repository at this point in the history
While changing the code to be in an `on_load` hook fixed some of the issues
with load hook order, it didn't catch all of them. Rails runs its hooks in
initializers, meaning they'll be defined after our own hooks which are not in
an initializer.

Fixes #24
  • Loading branch information
sgrif committed Aug 11, 2016
1 parent b128f8f commit e56cee4
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions lib/rails-controller-testing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@
require 'rails/controller/testing/template_assertions'
require 'rails/controller/testing/version'

ActiveSupport.on_load(:action_controller) do
ActionController::TestCase.include Rails::Controller::Testing::TestProcess
ActionController::TestCase.include Rails::Controller::Testing::TemplateAssertions
class Rails::Controller::Testing::Railtie < Rails::Railtie

This comment has been minimized.

Copy link
@lucasmazza

lucasmazza Aug 15, 2016

Contributor

Moving this to inside a Railtie makes the gem unusable outside of a Rails app, should we provide an alternative way to auto included it or just document how to do these includes manually?

This comment has been minimized.

Copy link
@rafaelfranca

rafaelfranca Aug 15, 2016

Member

I'd add a install method that does define the hooks, call it in the railtie and document it so people can use in alternative setup.

This comment has been minimized.

Copy link
@lucasmazza

lucasmazza Aug 15, 2016

Contributor

Opened #26.

initializer "rails_controller_testing" do
ActiveSupport.on_load(:action_controller) do
ActionController::TestCase.include Rails::Controller::Testing::TestProcess
ActionController::TestCase.include Rails::Controller::Testing::TemplateAssertions

ActionDispatch::IntegrationTest.include Rails::Controller::Testing::TemplateAssertions
ActionDispatch::IntegrationTest.include Rails::Controller::Testing::Integration
ActionDispatch::IntegrationTest.include Rails::Controller::Testing::TestProcess
end
ActionDispatch::IntegrationTest.include Rails::Controller::Testing::TemplateAssertions
ActionDispatch::IntegrationTest.include Rails::Controller::Testing::Integration
ActionDispatch::IntegrationTest.include Rails::Controller::Testing::TestProcess

This comment has been minimized.

Copy link
@koenpunt

koenpunt Aug 12, 2016

Why are these not also wrapped in a ActiveSupport.on_load ? Because the integration test itself triggers a loadhook too (:action_dispatch_integration_test): https://github.com/rails/rails/blob/b326e82dc012d81e9698cb1f402502af1788c1e9/actionpack/lib/action_dispatch/testing/integration.rb#L719

This comment has been minimized.

Copy link
@rafaelfranca

rafaelfranca Aug 12, 2016

Member

They are. In the same hook that the lines above

This comment has been minimized.

Copy link
@koenpunt

koenpunt Aug 12, 2016

Yeah but that's the ActionController's, the IntegrationTest too has a loadhook. Don't know if that would make a difference though...

This comment has been minimized.

Copy link
@rafaelfranca

rafaelfranca via email Aug 12, 2016

Member
end

ActiveSupport.on_load(:action_view) do
ActionView::TestCase.include Rails::Controller::Testing::TemplateAssertions
ActiveSupport.on_load(:action_view) do
ActionView::TestCase.include Rails::Controller::Testing::TemplateAssertions
end
end
end

0 comments on commit e56cee4

Please sign in to comment.