Skip to content

Commit

Permalink
Merge pull request #3369 from alphagov/timed-updates
Browse files Browse the repository at this point in the history
Timed updates
  • Loading branch information
KludgeKML authored Jul 3, 2024
2 parents 5415667 + f3ba36a commit bef6269
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 7 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ group :test do
gem "mocha", require: false
gem "shoulda-context"
gem "simplecov"
gem "timecop"
gem "webmock"
end
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ GEM
terser (1.2.3)
execjs (>= 0.3.0, < 3)
thor (1.3.1)
timecop (0.9.10)
timeout (0.4.1)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
Expand Down Expand Up @@ -616,6 +617,7 @@ DEPENDENCIES
simplecov
sprockets-rails
terser
timecop
webmock

RUBY VERSION
Expand Down
5 changes: 5 additions & 0 deletions app/helpers/timed_update_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module TimedUpdateHelper
def before_update_time?(year:, month:, day:, hour:, minute:)
Time.zone.now.before? Time.zone.local(year, month, day, hour, minute)
end
end
12 changes: 6 additions & 6 deletions app/views/components/_global_bar.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<%
show_global_bar ||= true # Toggles the appearance of the global bar

title = "Bring photo ID to vote"
title_href = "/how-to-vote/photo-id-youll-need"
link_text = "Check what photo ID you'll need to vote in person in the General Election on 4 July."

if before_update_time?(year: 2024, month: 7, day: 4, hour: 22, minute: 0)
show_global_bar ||= true # Toggles the appearance of the global bar
title = "Bring photo ID to vote"
title_href = "/how-to-vote/photo-id-youll-need"
link_text = "Check what photo ID you'll need to vote in person in the General Election on 4 July."
end

link_href = false

Expand Down
2 changes: 1 addition & 1 deletion config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
config.cache_store = :null_store

# Raise exceptions instead of rendering exception templates.
config.action_dispatch.show_exceptions = false
config.action_dispatch.show_exceptions = :none

# Disable request forgery protection in test environment.
config.action_controller.allow_forgery_protection = false
Expand Down
20 changes: 20 additions & 0 deletions test/unit/helpers/timed_update_helper_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require "test_helper"

class TimedUpdateHelperTest < ActiveSupport::TestCase
include TimedUpdateHelper

test "#before_update_time? returns true if we haven't reached the requested time yet" do
Timecop.freeze(2024, 6, 17, 23, 59)
assert before_update_time?(year: 2024, month: 6, day: 18, hour: 0, minute: 0)
end

test "#before_update_time? returns false if we've reached the requested time" do
Timecop.freeze(2024, 6, 18, 0, 0)
assert_not before_update_time?(year: 2024, month: 6, day: 18, hour: 0, minute: 0)
end

test "#before_update_time? returns false if we've passed the requested time" do
Timecop.freeze(2024, 6, 20, 10, 10)
assert_not before_update_time?(year: 2024, month: 6, day: 18, hour: 0, minute: 0)
end
end

0 comments on commit bef6269

Please sign in to comment.