Skip to content

Commit

Permalink
Make sure annotate_rendered_view_with_filenames is configured
Browse files Browse the repository at this point in the history
Action View is setup to copy the configuration from the application after
initialization is finished, using `ActiveSupport.on_load(:action_view)`
to make sure it only happens when `ActionView::Base` is loaded.

We need to add our on_load hook after that, so we're also putting it in
an after_initialize. Typically apps load all Rails railties before
requiring gems with Bundler, so our after_initialize should always run
after the one from Action View.
  • Loading branch information
etiennebarrie committed Mar 19, 2024
1 parent e050e08 commit 4dea811
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/better_html/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ module BetterHtml
class Railtie < Rails::Railtie
initializer "better_html.better_erb.initialization" do
BetterHtml::BetterErb.prepend!
end

config.after_initialize do
ActiveSupport.on_load(:action_view) do
BetterHtml.config.annotate_rendered_view_with_filenames = ActionView::Base.annotate_rendered_view_with_filenames
end
end
end
end

16 changes: 16 additions & 0 deletions test/better_html/railtie_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

# setup dummy app
ENV["RAILS_ENV"] ||= "test"
require_relative "../dummy/config/environment"
# load railtie
require "test_helper"

module BetterHtml
class RailtieTest < ActiveSupport::TestCase
test "configuration is copied from ActionView" do
_ = ActionView::Base
assert BetterHtml.config.annotate_rendered_view_with_filenames
end
end
end

0 comments on commit 4dea811

Please sign in to comment.