Skip to content

Commit

Permalink
Handle nil for config.govuk_time_zone
Browse files Browse the repository at this point in the history
  • Loading branch information
richardTowers committed Jul 23, 2024
1 parent 85cb008 commit f6054dd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/govuk_app_config/govuk_timezone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module GovukTimezone
def self.configure(config)
raise "govuk_app_config prevents configuring time_zone with config.time_zone - use config.govuk_time_zone instead" unless config.time_zone == "UTC"

if config.respond_to? :govuk_time_zone
if config.respond_to?(:govuk_time_zone) && config.govuk_time_zone.present?
config.time_zone = config.govuk_time_zone
else
Rails.logger.info 'govuk_app_config changing time_zone from UTC (the rails default) to London (the GOV.UK default). Set config.govuk_time_zone = "UTC" if you need UTC.'
Expand Down
7 changes: 7 additions & 0 deletions spec/lib/govuk_timezone_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
expect(config.time_zone).to eq("Shanghai")
end

it "should default to London if config.govuk_time_zone is nil" do
config = Struct.new(:time_zone, :govuk_time_zone).new("UTC", nil)
expect(logger).to receive(:info)
GovukTimezone.configure(config)
expect(config.time_zone).to eq("London")
end

it "should raise an error if config.time_zone is set to anything other than the default UTC" do
config = Struct.new(:time_zone).new("London")
expect { GovukTimezone.configure(config) }.to raise_error(/govuk_app_config prevents configuring time_zone with config[.]time_zone/)
Expand Down

0 comments on commit f6054dd

Please sign in to comment.