-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #381 from alphagov/set-time-zone-everywhere
Set time_zone to London in all GOV.UK apps
- Loading branch information
Showing
5 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module GovukTimezone | ||
def self.configure(config) | ||
case config.time_zone | ||
when "UTC" | ||
Rails.logger.info "govuk_app_config changing time_zone from UTC (the default) to London" | ||
when "London" | ||
Rails.logger.info "govuk_app_config always sets time_zone to London - there is no need to set config.time_zone in your app" | ||
else | ||
raise "govuk_app_config prevents configuring time_zones other than London - config.time_zone was set to #{config.time_zone}" | ||
end | ||
|
||
config.time_zone = "London" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
require "spec_helper" | ||
require "govuk_app_config/govuk_timezone" | ||
|
||
RSpec.describe GovukError do | ||
describe ".configure" do | ||
let(:config) { Rails::Railtie::Configuration.new } | ||
let(:logger) { instance_double("ActiveSupport::Logger") } | ||
|
||
before do | ||
allow(Rails).to receive(:logger).and_return(logger) | ||
end | ||
|
||
it "should override the default UTC time_zone to London" do | ||
config.time_zone = "UTC" | ||
expect(logger).to receive(:info) | ||
GovukTimezone.configure(config) | ||
expect(config.time_zone).to eq("London") | ||
end | ||
|
||
it "should leave time_zones set to London as London" do | ||
config.time_zone = "London" | ||
expect(logger).to receive(:info) | ||
GovukTimezone.configure(config) | ||
expect(config.time_zone).to eq("London") | ||
end | ||
|
||
it "should raise an error if configured with any other time zone" do | ||
config.time_zone = "Shanghai" | ||
expect { GovukTimezone.configure(config) }.to raise_error(/govuk_app_config prevents configuring time_zones/) | ||
end | ||
end | ||
end |