Skip to content

Commit

Permalink
Merge pull request #556 from amatsuda/run_railtie_in_tests
Browse files Browse the repository at this point in the history
Run Railtie from the tests so that we can detect bugs inside Railtie
  • Loading branch information
amatsuda committed Jan 17, 2024
2 parents aa5a272 + 5af3835 commit 3875613
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
8 changes: 5 additions & 3 deletions lib/jbuilder/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ module ApiRendering
end
end

ActiveSupport.on_load :action_controller_api do
include ActionController::Helpers
include ActionController::ImplicitRender
ActiveSupport.on_load :action_controller do
if name == 'ActionController::API'
include ActionController::Helpers
include ActionController::ImplicitRender
end
end
end
end
Expand Down
11 changes: 10 additions & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
require "active_support/cache/memory_store"
require "active_support/json"
require "active_model"
require 'action_controller/railtie'
require 'action_view/railtie'

require "active_support/testing/autorun"
require "mocha/minitest"
Expand Down Expand Up @@ -35,4 +37,11 @@ class Racer < Struct.new(:id, :name)
include ActiveModel::Conversion
end

ActionView::Template.register_template_handler :jbuilder, JbuilderHandler
# Instantiate an Application in order to trigger the initializers
Class.new(Rails::Application) do
config.secret_key_base = 'secret'
config.eager_load = false
end.initialize!

# Touch AV::Base in order to trigger :action_view on_load hook before running the tests
ActionView::Base.inspect

0 comments on commit 3875613

Please sign in to comment.