Skip to content

Commit

Permalink
Allow utc_to_local_returns_utc_offset_times to be set in new_framewor…
Browse files Browse the repository at this point in the history
…k_defaults_6_1.rb

Enabling this option in new_framework_defaults_6_1.rb didn't work
before, as railtie initializers run before application initializers.
  • Loading branch information
eugeneius committed Apr 3, 2020
1 parent d56d2e7 commit 775148c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion activesupport/CHANGELOG.md
Expand Up @@ -18,7 +18,7 @@

This changes the output of `ActiveSupport::TimeZone.utc_to_local`, but
can be controlled with the
`Rails.application.config.active_support.utc_to_local_returns_utc_offset_times` config.
`ActiveSupport.utc_to_local_returns_utc_offset_times` config.

New Rails 6.1 apps have it enabled by default, existing apps can upgrade
via the config in config/initializers/new_framework_defaults_6_1.rb
Expand Down
4 changes: 1 addition & 3 deletions railties/lib/rails/application/configuration.rb
Expand Up @@ -179,9 +179,7 @@ def load_defaults(target_version)
action_dispatch.cookies_same_site_protection = :lax
end

if respond_to?(:active_support)
active_support.utc_to_local_returns_utc_offset_times = true
end
ActiveSupport.utc_to_local_returns_utc_offset_times = true
else
raise "Unknown version #{target_version.to_s.inspect}"
end
Expand Down
Expand Up @@ -24,4 +24,4 @@

# Specify whether `ActiveSupport::TimeZone.utc_to_local` returns a time with an
# UTC offset or a UTC time.
# Rails.application.config.active_support.utc_to_local_returns_utc_offset_times = true
# ActiveSupport.utc_to_local_returns_utc_offset_times = true
26 changes: 24 additions & 2 deletions railties/test/application/configuration_test.rb
Expand Up @@ -2295,13 +2295,35 @@ class ::DummySerializer < ActiveJob::Serializers::ObjectSerializer; end
assert_equal :lax, Rails.application.config.action_dispatch.cookies_same_site_protection
end

test "enables utc_to_local_returns_utc_offset_times by default" do
test "ActiveSupport.utc_to_local_returns_utc_offset_times is true in 6.1 defaults" do
remove_from_config '.*config\.load_defaults.*\n'
add_to_config 'config.load_defaults "6.1"'

app "development"

assert_equal true, Rails.application.config.active_support.utc_to_local_returns_utc_offset_times
assert_equal true, ActiveSupport.utc_to_local_returns_utc_offset_times
end

test "ActiveSupport.utc_to_local_returns_utc_offset_times is false in 6.0 defaults" do
remove_from_config '.*config\.load_defaults.*\n'
add_to_config 'config.load_defaults "6.0"'

app "development"

assert_equal false, ActiveSupport.utc_to_local_returns_utc_offset_times
end

test "ActiveSupport.utc_to_local_returns_utc_offset_times can be configured in an initializer" do
remove_from_config '.*config\.load_defaults.*\n'
add_to_config 'config.load_defaults "6.0"'

app_file "config/initializers/new_framework_defaults_6_1.rb", <<-RUBY
ActiveSupport.utc_to_local_returns_utc_offset_times = true
RUBY

app "development"

assert_equal true, ActiveSupport.utc_to_local_returns_utc_offset_times
end

test "ActiveStorage.queues[:analysis] is :active_storage_analysis by default" do
Expand Down

0 comments on commit 775148c

Please sign in to comment.