diff --git a/Gemfile b/Gemfile index 3f8865eb0..9b98bfa23 100644 --- a/Gemfile +++ b/Gemfile @@ -36,5 +36,6 @@ group :test do gem "mocha", require: false gem "shoulda-context" gem "simplecov" + gem "timecop" gem "webmock" end diff --git a/Gemfile.lock b/Gemfile.lock index 107648a31..07669fff4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -616,6 +617,7 @@ DEPENDENCIES simplecov sprockets-rails terser + timecop webmock RUBY VERSION diff --git a/app/helpers/timed_update_helper.rb b/app/helpers/timed_update_helper.rb new file mode 100644 index 000000000..3dbc6a37b --- /dev/null +++ b/app/helpers/timed_update_helper.rb @@ -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 diff --git a/app/views/components/_global_bar.html.erb b/app/views/components/_global_bar.html.erb index 5ff9a8fd0..763419494 100644 --- a/app/views/components/_global_bar.html.erb +++ b/app/views/components/_global_bar.html.erb @@ -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 diff --git a/config/environments/test.rb b/config/environments/test.rb index 2eecacae8..544904ae9 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -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 diff --git a/test/unit/helpers/timed_update_helper_test.rb b/test/unit/helpers/timed_update_helper_test.rb new file mode 100644 index 000000000..3e971f8f3 --- /dev/null +++ b/test/unit/helpers/timed_update_helper_test.rb @@ -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