aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2013-01-04 00:22:21 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2013-01-04 00:25:08 -0300
commit39374aa925a7d670b039c0c0c9aa9f4aef19466b (patch)
tree8e47fa7a1ec65c9729f50691cc3f65ffc91e493d
parentdd3360e05e4909f2f0c74a624cccc2def688f828 (diff)
downloadrails-39374aa925a7d670b039c0c0c9aa9f4aef19466b.tar.gz
rails-39374aa925a7d670b039c0c0c9aa9f4aef19466b.tar.bz2
rails-39374aa925a7d670b039c0c0c9aa9f4aef19466b.zip
Set the default timezone after the initialization since the configuration
now lives in the application initializers. Fix #8711
-rw-r--r--activesupport/lib/active_support/railtie.rb30
-rw-r--r--railties/test/application/configuration_test.rb12
2 files changed, 27 insertions, 15 deletions
diff --git a/activesupport/lib/active_support/railtie.rb b/activesupport/lib/active_support/railtie.rb
index 133aa6a054..72ac597d99 100644
--- a/activesupport/lib/active_support/railtie.rb
+++ b/activesupport/lib/active_support/railtie.rb
@@ -13,20 +13,6 @@ module ActiveSupport
end
end
- # Sets the default value for Time.zone
- # If assigned value cannot be matched to a TimeZone, an exception will be raised.
- initializer "active_support.initialize_time_zone" do |app|
- require 'active_support/core_ext/time/zones'
- zone_default = Time.find_zone!(app.config.time_zone)
-
- unless zone_default
- raise 'Value assigned to config.time_zone not recognized. ' \
- 'Run "rake -D time" for a list of tasks for finding appropriate time zone names.'
- end
-
- Time.zone_default = zone_default
- end
-
# Sets the default week start
# If assigned value is not a valid day symbol (e.g. :sunday, :monday, ...), an exception will be raised.
initializer "active_support.initialize_beginning_of_week" do |app|
@@ -42,5 +28,21 @@ module ActiveSupport
ActiveSupport.send(k, v) if ActiveSupport.respond_to? k
end
end
+
+ # Sets the default value for Time.zone after initialization since the default configuration
+ # lives in application initializers.
+ # If assigned value cannot be matched to a TimeZone, an exception will be raised.
+ config.after_initialize do |app|
+ require 'active_support/core_ext/time/zones'
+ zone_default = Time.find_zone!(app.config.time_zone)
+
+ unless zone_default
+ raise 'Value assigned to config.time_zone not recognized. ' \
+ 'Run "rake -D time" for a list of tasks for finding appropriate time zone names.'
+ end
+
+ Time.zone_default = zone_default
+ end
+
end
end
diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb
index 53109cb041..920798c930 100644
--- a/railties/test/application/configuration_test.rb
+++ b/railties/test/application/configuration_test.rb
@@ -407,7 +407,17 @@ module ApplicationTests
require "#{app_path}/config/environment"
- assert_equal "Wellington", Rails.application.config.time_zone
+ assert_equal Time.find_zone!("Wellington"), Time.zone_default
+ end
+
+ test "timezone can be set on initializers" do
+ app_file "config/initializers/locale.rb", <<-RUBY
+ Rails.application.config.time_zone = "Central Time (US & Canada)"
+ RUBY
+
+ require "#{app_path}/config/environment"
+
+ assert_equal Time.find_zone!("Central Time (US & Canada)"), Time.zone_default
end
test "raises when an invalid timezone is defined in the config" do