Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timed updates #3369

Merged
merged 2 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: I'm not sure about this name, but I can't think of anything better!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I also couldn't think of anything better. Let's sleep on it and see if a better name turns up in the morning.

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
Loading