Skip to content

Commit

Permalink
Merge PR #41055
Browse files Browse the repository at this point in the history
Closes #41055.
  • Loading branch information
rafaelfranca committed Jan 8, 2021
2 parents e20a874 + 4a401ca commit 1e6d25c
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 9 deletions.
14 changes: 7 additions & 7 deletions actionview/lib/action_view/railtie.rb
Expand Up @@ -39,6 +39,13 @@ class Railtie < Rails::Engine # :nodoc:
end
end

config.after_initialize do |app|
button_to_generates_button_tag = app.config.action_view.delete(:button_to_generates_button_tag)
unless button_to_generates_button_tag.nil?
ActionView::Helpers::UrlHelper.button_to_generates_button_tag = button_to_generates_button_tag
end
end

config.after_initialize do |app|
ActionView::Helpers::AssetTagHelper.image_loading = app.config.action_view.delete(:image_loading)
ActionView::Helpers::AssetTagHelper.image_decoding = app.config.action_view.delete(:image_decoding)
Expand Down Expand Up @@ -81,13 +88,6 @@ class Railtie < Rails::Engine # :nodoc:
PartialRenderer.collection_cache = app.config.action_controller.cache_store
end

initializer "action_view.button_to_generates_button_tag" do |app|
ActiveSupport.on_load(:action_view) do
ActionView::Helpers::UrlHelper.button_to_generates_button_tag =
app.config.action_view.delete(:button_to_generates_button_tag)
end
end

config.after_initialize do |app|
enable_caching = if app.config.action_view.cache_template_loading.nil?
app.config.cache_classes
Expand Down
4 changes: 4 additions & 0 deletions guides/source/configuring.md
Expand Up @@ -734,6 +734,8 @@ Defaults to `'signed cookie'`.

* `config.action_view.preload_links_header` determines whether `javascript_include_tag` and `stylesheet_link_tag` will generate a `Link` header that preload assets.

* `config.action_view.button_to_generates_button_tag` determines whether `button_to` will render `<button>` element, regardless of whether or not the content is passed as the first argument or as a block.

### Configuring Action Mailbox

`config.action_mailbox` provides the following configuration options:
Expand Down Expand Up @@ -1040,6 +1042,7 @@ text/javascript image/svg+xml application/postscript application/x-shockwave-fla
`config.load_defaults` sets new defaults up to and including the version passed. Such that passing, say, `6.0` also gets the new defaults from every version before it.

#### For '6.2', defaults from previous versions below and:
- `config.action_view.button_to_generates_button_tag`: `true`
- `config.active_support.key_generator_hash_digest_class`: `OpenSSL::Digest::SHA256`

#### For '6.1', defaults from previous versions below and:
Expand Down Expand Up @@ -1102,6 +1105,7 @@ text/javascript image/svg+xml application/postscript application/x-shockwave-fla
- `config.action_mailer.delivery_job`: `ActionMailer::DeliveryJob`
- `config.action_view.form_with_generates_ids`: `false`
- `config.action_view.preload_links_header`: `nil`
- `config.action_view.button_to_generates_button_tag`: `false`
- `config.active_job.retry_jitter`: `0.0`
- `config.active_job.skip_after_callbacks_if_terminated`: `false`
- `config.action_mailbox.queues.incineration`: `:action_mailbox_incineration`
Expand Down
Expand Up @@ -6,8 +6,9 @@
#
# Read the Guide for Upgrading Ruby on Rails for more info on each option.

# button_to view helpers consistently render <button> elements.
# Rails.application.config.action_view.button_to_generates_button_tag = false
# `button_to` view helper will render `<button>` element, regardless of whether
# or not the content is passed as the first argument or as a block.
# Rails.application.config.action_view.button_to_generates_button_tag = true

# Change the digest class for they key generators to `OpenSSL::Digest::SHA256`.
# Changing this defaults means invalidate all encripted messages generated by
Expand Down
25 changes: 25 additions & 0 deletions railties/test/application/configuration_test.rb
Expand Up @@ -2371,6 +2371,31 @@ class ::DummySerializer < ActiveJob::Serializers::ObjectSerializer; end
assert_equal true, ActionView::Helpers::FormTagHelper.default_enforce_utf8
end

test "ActionView::Helpers::UrlHelper.button_to_generates_button_tag is true by default" do
app "development"
assert_equal true, ActionView::Helpers::UrlHelper.button_to_generates_button_tag
end

test "ActionView::Helpers::UrlHelper.button_to_generates_button_tag is false by default for upgraded apps" do
remove_from_config '.*config\.load_defaults.*\n'
add_to_config 'config.load_defaults "6.1"'
app "development"

assert_equal false, ActionView::Helpers::UrlHelper.button_to_generates_button_tag
end

test "ActionView::Helpers::UrlHelper.button_to_generates_button_tag can be configured via config.action_view.button_to_generates_button_tag" do
remove_from_config '.*config\.load_defaults.*\n'

app_file "config/initializers/new_framework_defaults_6_2.rb", <<-RUBY
Rails.application.config.action_view.button_to_generates_button_tag = true
RUBY

app "development"

assert_equal true, ActionView::Helpers::UrlHelper.button_to_generates_button_tag
end

test "ActionView::Helpers::AssetTagHelper.image_loading is nil by default" do
app "development"
assert_nil ActionView::Helpers::AssetTagHelper.image_loading
Expand Down

0 comments on commit 1e6d25c

Please sign in to comment.