-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- was part of the original component in static, but lack of it only caused an error once trying to render the component guide page - modified a bit from the original, had to require active_support, rewrote minitest to rspec, added timecop, set timezone in tests, configure as app helper
- Loading branch information
1 parent
b29df5f
commit ab6b041
Showing
6 changed files
with
40 additions
and
1 deletion.
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
2 changes: 1 addition & 1 deletion
2
app/views/govuk_publishing_components/components/_global_bar.html.erb
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
11 changes: 11 additions & 0 deletions
11
lib/govuk_publishing_components/app_helpers/timed_update_helper.rb
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,11 @@ | ||
require "active_support/all" | ||
|
||
module GovukPublishingComponents | ||
module AppHelpers | ||
module TimedUpdateHelper | ||
def self.before_update_time?(year:, month:, day:, hour:, minute:) | ||
Time.zone.now.before? Time.zone.local(year, month, day, hour, minute) | ||
end | ||
end | ||
end | ||
end |
24 changes: 24 additions & 0 deletions
24
spec/lib/govuk_publishing_components/app_helpers/timed_update_helper_spec.rb
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,24 @@ | ||
require "spec_helper" | ||
require "timecop" | ||
|
||
RSpec.describe GovukPublishingComponents::AppHelpers::TimedUpdateHelper do | ||
describe "Timed Update helper" do | ||
it "#before_update_time? returns true if we haven't reached the requested time yet" do | ||
Time.zone = "London" | ||
Timecop.freeze(2024, 6, 17, 23, 59) | ||
expect(GovukPublishingComponents::AppHelpers::TimedUpdateHelper.before_update_time?(year: 2024, month: 6, day: 18, hour: 0, minute: 0)).to be true | ||
end | ||
|
||
it "#before_update_time? returns false if we've reached the requested time" do | ||
Time.zone = "London" | ||
Timecop.freeze(2024, 6, 18, 0, 0) | ||
expect(GovukPublishingComponents::AppHelpers::TimedUpdateHelper.before_update_time?(year: 2024, month: 6, day: 18, hour: 0, minute: 0)).to be false | ||
end | ||
|
||
it "#before_update_time? returns false if we've passed the requested time" do | ||
Time.zone = "London" | ||
Timecop.freeze(2024, 6, 20, 10, 10) | ||
expect(GovukPublishingComponents::AppHelpers::TimedUpdateHelper.before_update_time?(year: 2024, month: 6, day: 18, hour: 0, minute: 0)).to be false | ||
end | ||
end | ||
end |