From 4596429e10eaf075d04444350a7650f943b1c34d Mon Sep 17 00:00:00 2001 From: Richard Towers Date: Tue, 25 Jun 2024 12:39:21 +0100 Subject: [PATCH 01/15] Serialize times as UTC in keyset pagination --- app/queries/keyset_pagination.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/queries/keyset_pagination.rb b/app/queries/keyset_pagination.rb index 96699ab81..00f71a589 100644 --- a/app/queries/keyset_pagination.rb +++ b/app/queries/keyset_pagination.rb @@ -98,7 +98,9 @@ def presented_fields def key_for_record(record) key_fields.map do |k| value = record[k] - next value.iso8601(6) if value.respond_to?(:iso8601) + if value.is_a?(Time) || value.is_a?(Date) + next value.utc.iso8601(6) + end value.to_s end From ef17b8310d5184f6c51c3bf2024fc618e44bb047 Mon Sep 17 00:00:00 2001 From: Richard Towers Date: Tue, 25 Jun 2024 12:57:09 +0100 Subject: [PATCH 02/15] Test change note times in UTC public_timestamp comes from activerecord, so it will be UTC. If we compare it with a time in the current timezone (London), it won't be equal. --- spec/models/change_note_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/change_note_spec.rb b/spec/models/change_note_spec.rb index c9b25f00c..c94eafea2 100644 --- a/spec/models/change_note_spec.rb +++ b/spec/models/change_note_spec.rb @@ -45,7 +45,7 @@ context "payload contains public_updated_at" do it "sets the change note public_timestamp to public_updated_at time" do - time = Time.zone.yesterday + time = Time.now.utc.yesterday payload[:public_updated_at] = time described_class.create_from_edition(payload, edition) From b40326b8c0436afbeb51aed9ae7e881d1fe47da0 Mon Sep 17 00:00:00 2001 From: Richard Towers Date: Tue, 25 Jun 2024 13:00:06 +0100 Subject: [PATCH 03/15] Compare times in the same timezone (UTC) new_first_published_at is already explicitly UTC in this test, before it's turned into a string with iso8601. If we compare a time in the current timezone (London) with that, it won't be equal. --- .../content_with_a_previously_published_edition_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/integration/put_content/content_with_a_previously_published_edition_spec.rb b/spec/integration/put_content/content_with_a_previously_published_edition_spec.rb index 19ab31d95..f3fa9453b 100644 --- a/spec/integration/put_content/content_with_a_previously_published_edition_spec.rb +++ b/spec/integration/put_content/content_with_a_previously_published_edition_spec.rb @@ -94,7 +94,7 @@ put "/v2/content/#{content_id}", params: payload.to_json edition = Edition.last - expect(edition.first_published_at.iso8601).to eq(new_first_published_at) + expect(edition.first_published_at.utc.iso8601).to eq(new_first_published_at) end end From 4138d69ecbb182de9c5d3de6426efc07fe13c90c Mon Sep 17 00:00:00 2001 From: Richard Towers Date: Tue, 25 Jun 2024 13:29:37 +0100 Subject: [PATCH 04/15] Emit times in UTC when producing JSON And add a test for this behaviour --- app/models/symbolize_json.rb | 2 +- spec/models/symbolize_json_spec.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/models/symbolize_json.rb b/app/models/symbolize_json.rb index fade21163..06b036c14 100644 --- a/app/models/symbolize_json.rb +++ b/app/models/symbolize_json.rb @@ -20,7 +20,7 @@ def self.symbolize(value) new_hash[k.to_sym] = symbolize(v) end when ActiveSupport::TimeWithZone - value.iso8601 + value.utc.iso8601 else value end diff --git a/spec/models/symbolize_json_spec.rb b/spec/models/symbolize_json_spec.rb index 6392d47f1..20c0564de 100644 --- a/spec/models/symbolize_json_spec.rb +++ b/spec/models/symbolize_json_spec.rb @@ -10,6 +10,15 @@ expect(subject.public_updated_at).to eq(Date.new(2000, 1, 1)) end + it "emits times in different timezones as UTC" do + subject.public_updated_at = Time.utc(2000, 1, 1).in_time_zone("Eastern Time (US & Canada)") + + subject.save! + subject.reload + + expect(subject.public_updated_at).to eq(Time.utc(2000, 1, 1)) + end + context "json columns" do it "symbolizes hashes" do subject.details = { "foo" => "bar" } @@ -55,5 +64,6 @@ subject.reload expect(subject.details).to eq(nil) end + end end From 5c253db7040d425a94ce4724f524ab6cd91b1b9f Mon Sep 17 00:00:00 2001 From: Richard Towers Date: Tue, 25 Jun 2024 13:30:09 +0100 Subject: [PATCH 05/15] Test that unpublished_at is UTC --- spec/presenters/queries/content_item_presenter_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/presenters/queries/content_item_presenter_spec.rb b/spec/presenters/queries/content_item_presenter_spec.rb index 30bb6e05b..bf81aeb05 100644 --- a/spec/presenters/queries/content_item_presenter_spec.rb +++ b/spec/presenters/queries/content_item_presenter_spec.rb @@ -91,7 +91,7 @@ "type" => unpublishing.type, "explanation" => unpublishing.explanation, "alternative_path" => unpublishing.alternative_path, - "unpublished_at" => unpublishing.unpublished_at.rfc3339, + "unpublished_at" => unpublishing.unpublished_at.utc.rfc3339, ), ) end From e7b89c90d7de3c56c3d76c3e31194e110216c2a7 Mon Sep 17 00:00:00 2001 From: Richard Towers Date: Tue, 25 Jun 2024 13:43:15 +0100 Subject: [PATCH 06/15] Set expanded links generated times to UTC --- app/queries/get_expanded_links.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/queries/get_expanded_links.rb b/app/queries/get_expanded_links.rb index a434c2368..a92b978a0 100644 --- a/app/queries/get_expanded_links.rb +++ b/app/queries/get_expanded_links.rb @@ -59,7 +59,7 @@ def stored_links_response(expanded_links) def response(expanded_links, generated_date, version = nil) response = { - generated: generated_date.iso8601, + generated: generated_date.utc.iso8601, expanded_links:, } response[:version] = version if version From 7f41ec9e6dbdcba816bb57295ad30305acd6545f Mon Sep 17 00:00:00 2001 From: Richard Towers Date: Tue, 25 Jun 2024 13:56:02 +0100 Subject: [PATCH 07/15] Specify UTC time zone in test data --- spec/queries/get_content_collection_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/queries/get_content_collection_spec.rb b/spec/queries/get_content_collection_spec.rb index 5a6e57180..a48aa0a86 100644 --- a/spec/queries/get_content_collection_spec.rb +++ b/spec/queries/get_content_collection_spec.rb @@ -604,10 +604,10 @@ describe "result order" do before do - create(:edition, base_path: "/c4", title: "D", public_updated_at: "2014-06-14") - create(:edition, base_path: "/c1", title: "A", public_updated_at: "2014-06-13") - create(:edition, base_path: "/c3", title: "C", public_updated_at: "2014-06-17") - create(:edition, base_path: "/c2", title: "B", public_updated_at: "2014-06-15") + create(:edition, base_path: "/c4", title: "D", public_updated_at: Time.utc(2014, 06, 14)) + create(:edition, base_path: "/c1", title: "A", public_updated_at: Time.utc(2014, 06, 13)) + create(:edition, base_path: "/c3", title: "C", public_updated_at: Time.utc(2014, 06, 17)) + create(:edition, base_path: "/c2", title: "B", public_updated_at: Time.utc(2014, 06, 15)) end it "returns editions in default order" do From 0de9a5fa37d5ace0126cba4b426e61b2ccc07077 Mon Sep 17 00:00:00 2001 From: Richard Towers Date: Tue, 25 Jun 2024 13:57:14 +0100 Subject: [PATCH 08/15] Explicitly use UTC dates in CSV output ... this probably doesn't matter in practice, but to stop the change in default timezone from having an observable effect it's better to be explicit. --- lib/tasks/csv_report.rake | 58 +++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/lib/tasks/csv_report.rake b/lib/tasks/csv_report.rake index a7e00ecc5..540ef2de7 100644 --- a/lib/tasks/csv_report.rake +++ b/lib/tasks/csv_report.rake @@ -41,20 +41,22 @@ namespace :csv_report do csv << %w[published_at base_path content_id locale title document_type update_type first_publishing] - query = Edition.joins(:document) - .where(published_at: from_time...until_time) - .where.not(update_type: :republish) - .order(published_at: :asc) - .pluck(:published_at, - :base_path, - "documents.content_id", - "documents.locale", - :title, - :document_type, - :update_type, - Arel.sql("(user_facing_version = 1)")) - - query.each { |row| csv << row } + Time.use_zone("UTC") do + query = Edition.joins(:document) + .where(published_at: from_time...until_time) + .where.not(update_type: :republish) + .order(published_at: :asc) + .pluck(:published_at, + :base_path, + "documents.content_id", + "documents.locale", + :title, + :document_type, + :update_type, + Arel.sql("(user_facing_version = 1)")) + + query.each { |row| csv << row } + end end desc "Prints a CSV of all editions that were unpublished between the from and until timestamp" @@ -68,18 +70,20 @@ namespace :csv_report do csv << %w[unpublished_at base_path content_id locale title document_type unpublishing_type] - query = Unpublishing.joins({ edition: :document }) - .where(created_at: from_time...until_time) - .where.not(type: "substitute") - .order(created_at: :asc) - .pluck(:created_at, - "editions.base_path", - "documents.content_id", - "documents.locale", - "editions.title", - "editions.document_type", - :type) - - query.each { |row| csv << row } + Time.use_zone("UTC") do + query = Unpublishing.joins({ edition: :document }) + .where(created_at: from_time...until_time) + .where.not(type: "substitute") + .order(created_at: :asc) + .pluck(:created_at, + "editions.base_path", + "documents.content_id", + "documents.locale", + "editions.title", + "editions.document_type", + :type) + + query.each { |row| csv << row } + end end end From 1e7fce7276da05baf401388aa0442e82845582d2 Mon Sep 17 00:00:00 2001 From: Richard Towers Date: Tue, 25 Jun 2024 15:07:51 +0100 Subject: [PATCH 09/15] Use UTC for withdrawn_at datetimes --- app/presenters/edition_presenter.rb | 2 +- spec/presenters/edition_presenter_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/presenters/edition_presenter.rb b/app/presenters/edition_presenter.rb index b06b6b577..6cdd78158 100644 --- a/app/presenters/edition_presenter.rb +++ b/app/presenters/edition_presenter.rb @@ -141,7 +141,7 @@ def withdrawal_notice unpublishing = edition.unpublishing if unpublishing && unpublishing.withdrawal? - withdrawn_at = (unpublishing.unpublished_at || unpublishing.created_at).iso8601 + withdrawn_at = (unpublishing.unpublished_at || unpublishing.created_at).utc.iso8601 { withdrawn_notice: { explanation: unpublishing.explanation, diff --git a/spec/presenters/edition_presenter_spec.rb b/spec/presenters/edition_presenter_spec.rb index 1a41e7927..cfb2342ab 100644 --- a/spec/presenters/edition_presenter_spec.rb +++ b/spec/presenters/edition_presenter_spec.rb @@ -178,7 +178,7 @@ expected.merge( withdrawn_notice: { explanation: unpublishing.explanation, - withdrawn_at: unpublishing.created_at.iso8601, + withdrawn_at: unpublishing.created_at.utc.iso8601, }, ), ), From b61abc4fbd46450b28790a52afa069792552bdab Mon Sep 17 00:00:00 2001 From: Richard Towers Date: Tue, 25 Jun 2024 15:30:45 +0100 Subject: [PATCH 10/15] Present public_updated_at in UTC for unpublish events --- app/presenters/gone_presenter.rb | 2 +- spec/presenters/gone_presenter_spec.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/presenters/gone_presenter.rb b/app/presenters/gone_presenter.rb index 857026bd8..760543de5 100644 --- a/app/presenters/gone_presenter.rb +++ b/app/presenters/gone_presenter.rb @@ -46,7 +46,7 @@ def present base_path:, locale:, publishing_app:, - public_updated_at: public_updated_at&.iso8601, + public_updated_at: public_updated_at&.utc&.iso8601, details: { explanation:, alternative_path:, diff --git a/spec/presenters/gone_presenter_spec.rb b/spec/presenters/gone_presenter_spec.rb index 6ab88912b..1ab0f78d9 100644 --- a/spec/presenters/gone_presenter_spec.rb +++ b/spec/presenters/gone_presenter_spec.rb @@ -11,6 +11,15 @@ expect(subject).to be_valid_against_notification_schema("gone") end + context "with unpublished_at set" do + let(:unpublishing) { create(:unpublishing, unpublished_at: Time.utc(2000, 1, 1)) } + let(:edition) { unpublishing.edition } + + it "presents public_updated_at as the unpublishings unpublished_at time in UTC" do + expect(subject[:public_updated_at]).to eql(unpublishing.unpublished_at.utc.iso8601) + end + end + context "with a nil base_path" do let(:edition) { create(:gone_unpublished_edition, base_path: nil) } From 0cae684ee94e587e90a55aadf7706f1b2beca1e9 Mon Sep 17 00:00:00 2001 From: Richard Towers Date: Tue, 25 Jun 2024 15:40:03 +0100 Subject: [PATCH 11/15] Present public_updated_at in UTC for redirects --- app/presenters/redirect_presenter.rb | 2 +- spec/presenters/redirect_presenter_spec.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/presenters/redirect_presenter.rb b/app/presenters/redirect_presenter.rb index 7de578bee..a476f101a 100644 --- a/app/presenters/redirect_presenter.rb +++ b/app/presenters/redirect_presenter.rb @@ -76,6 +76,6 @@ def formatted_dates public_updated_at:, first_published_at:, }.compact - .transform_values(&:iso8601) + .transform_values { |v| v.utc.iso8601 } end end diff --git a/spec/presenters/redirect_presenter_spec.rb b/spec/presenters/redirect_presenter_spec.rb index 454754ad4..a43302580 100644 --- a/spec/presenters/redirect_presenter_spec.rb +++ b/spec/presenters/redirect_presenter_spec.rb @@ -18,7 +18,7 @@ end it "includes the public updated at" do - expect(subject[:public_updated_at]).to eq(edition.unpublishing.created_at.iso8601) + expect(subject[:public_updated_at]).to eq(edition.unpublishing.created_at.utc.iso8601) end end @@ -34,11 +34,11 @@ end it "includes the first published at" do - expect(subject[:first_published_at]).to eq(edition.first_published_at.iso8601) + expect(subject[:first_published_at]).to eq(edition.first_published_at.utc.iso8601) end it "includes the public updated at" do - expect(subject[:public_updated_at]).to eq(edition.public_updated_at.iso8601) + expect(subject[:public_updated_at]).to eq(edition.public_updated_at.utc.iso8601) end end end From ed7030da5ce9a2f15c06015a6f6e0e3229fcac23 Mon Sep 17 00:00:00 2001 From: Richard Towers Date: Tue, 25 Jun 2024 16:41:42 +0100 Subject: [PATCH 12/15] Use UTC times explicitly in tests These are the last few cases where we print dates/times with `.iso8601`, but weren't first ensuring they were in UTC. --- spec/clients/content_store_writer_spec.rb | 2 +- spec/commands/v2/put_content_spec.rb | 12 ++++++------ spec/factories/content_item_requests.rb | 2 +- ...ntent_with_a_previously_published_edition_spec.rb | 4 ++-- .../lib/data_hygiene/document_status_checker_spec.rb | 4 ++-- spec/models/change_note_spec.rb | 2 +- spec/presenters/edition_presenter_spec.rb | 2 +- spec/queries/get_expanded_links_spec.rb | 2 +- spec/requests/publish_intent_requests_spec.rb | 2 +- spec/requests/unpublishing_spec.rb | 6 +++--- 10 files changed, 19 insertions(+), 19 deletions(-) diff --git a/spec/clients/content_store_writer_spec.rb b/spec/clients/content_store_writer_spec.rb index 6b0a9ec6b..0c5f5501f 100644 --- a/spec/clients/content_store_writer_spec.rb +++ b/spec/clients/content_store_writer_spec.rb @@ -18,7 +18,7 @@ let(:publish_intent) do { - publish_time: Time.zone.now.iso8601, + publish_time: Time.now.utc.iso8601, publishing_app: "whitehall", rendering_app: "whitehall-frontend", routes: [ diff --git a/spec/commands/v2/put_content_spec.rb b/spec/commands/v2/put_content_spec.rb index 9fa036219..d41797b95 100644 --- a/spec/commands/v2/put_content_spec.rb +++ b/spec/commands/v2/put_content_spec.rb @@ -156,13 +156,13 @@ context "when the draft does not exist" do context "with a provided last_edited_at" do it "stores the provided timestamp" do - last_edited_at = 1.year.ago + last_edited_at = 1.year.ago.utc described_class.call(payload.merge(last_edited_at: last_edited_at.iso8601)) edition = Edition.last - expect(edition.last_edited_at.iso8601).to eq(last_edited_at.iso8601) + expect(edition.last_edited_at.utc.iso8601).to eq(last_edited_at.iso8601) end end @@ -172,7 +172,7 @@ edition = Edition.last - expect(edition.last_edited_at.iso8601).to eq(Time.zone.now.iso8601) + expect(edition.last_edited_at.utc.iso8601).to eq(Time.now.utc.iso8601) end end @@ -214,7 +214,7 @@ %w[minor major republish].each do |update_type| context "with update_type of #{update_type}" do it "stores the provided timestamp" do - last_edited_at = 1.year.ago + last_edited_at = 1.year.ago.utc described_class.call( payload.merge( @@ -223,7 +223,7 @@ ), ) - expect(edition.reload.last_edited_at.iso8601).to eq(last_edited_at.iso8601) + expect(edition.reload.last_edited_at.utc.iso8601).to eq(last_edited_at.iso8601) end end end @@ -233,7 +233,7 @@ Timecop.freeze do described_class.call(payload) - expect(edition.reload.last_edited_at.iso8601).to eq(Time.zone.now.iso8601) + expect(edition.reload.last_edited_at.utc.iso8601).to eq(Time.now.utc.iso8601) end end diff --git a/spec/factories/content_item_requests.rb b/spec/factories/content_item_requests.rb index 912e391f7..e67169c08 100644 --- a/spec/factories/content_item_requests.rb +++ b/spec/factories/content_item_requests.rb @@ -6,7 +6,7 @@ description { "Test description" } document_type { "answer" } schema_name { "answer" } - public_updated_at { Time.zone.now.iso8601 } + public_updated_at { Time.now.utc.iso8601 } publishing_app { "publisher" } rendering_app { "frontend" } locale { "en" } diff --git a/spec/integration/put_content/content_with_a_previously_published_edition_spec.rb b/spec/integration/put_content/content_with_a_previously_published_edition_spec.rb index f3fa9453b..a5681bb8a 100644 --- a/spec/integration/put_content/content_with_a_previously_published_edition_spec.rb +++ b/spec/integration/put_content/content_with_a_previously_published_edition_spec.rb @@ -79,8 +79,8 @@ put "/v2/content/#{content_id}", params: payload.to_json edition = Edition.last - expect(edition.major_published_at.iso8601) - .to eq(major_published_at.iso8601) + expect(edition.major_published_at.utc.iso8601) + .to eq(major_published_at.utc.iso8601) end end diff --git a/spec/lib/data_hygiene/document_status_checker_spec.rb b/spec/lib/data_hygiene/document_status_checker_spec.rb index 6917f4662..141a48b0a 100644 --- a/spec/lib/data_hygiene/document_status_checker_spec.rb +++ b/spec/lib/data_hygiene/document_status_checker_spec.rb @@ -22,7 +22,7 @@ context "and there is an old content item" do let(:content_item) do content_item_for_base_path(base_path).merge( - "updated_at" => (edition.published_at - 1).iso8601, + "updated_at" => (edition.published_at - 1).utc.iso8601, ) end before { stub_content_store_has_item(base_path, content_item) } @@ -32,7 +32,7 @@ context "and there is a recent content item" do let(:content_item) do content_item_for_base_path(base_path).merge( - "updated_at" => (edition.published_at + 1).iso8601, + "updated_at" => (edition.published_at + 1).utc.iso8601, ) end before { stub_content_store_has_item(base_path, content_item) } diff --git a/spec/models/change_note_spec.rb b/spec/models/change_note_spec.rb index c94eafea2..0e6bd476d 100644 --- a/spec/models/change_note_spec.rb +++ b/spec/models/change_note_spec.rb @@ -30,7 +30,7 @@ expect { subject }.to change { ChangeNote.count }.by(1) result = ChangeNote.last expect(result.note).to eq "Excellent" - expect(result.public_timestamp.iso8601).to eq Time.zone.now.iso8601 + expect(result.public_timestamp.utc.iso8601).to eq Time.zone.now.utc.iso8601 end end diff --git a/spec/presenters/edition_presenter_spec.rb b/spec/presenters/edition_presenter_spec.rb index cfb2342ab..240fb4af3 100644 --- a/spec/presenters/edition_presenter_spec.rb +++ b/spec/presenters/edition_presenter_spec.rb @@ -203,7 +203,7 @@ expected.merge( withdrawn_notice: { explanation: unpublishing.explanation, - withdrawn_at: unpublishing.unpublished_at.iso8601, + withdrawn_at: unpublishing.unpublished_at.utc.iso8601, }, ), ), diff --git a/spec/queries/get_expanded_links_spec.rb b/spec/queries/get_expanded_links_spec.rb index d4ac82546..7a1cb9530 100644 --- a/spec/queries/get_expanded_links_spec.rb +++ b/spec/queries/get_expanded_links_spec.rb @@ -44,7 +44,7 @@ it "returns the data from expanded links" do expect(result).to match( - generated: updated_at.iso8601, + generated: updated_at.utc.iso8601, expanded_links: expanded_links.as_json, ) end diff --git a/spec/requests/publish_intent_requests_spec.rb b/spec/requests/publish_intent_requests_spec.rb index 57d67aa42..dfc9f13a2 100644 --- a/spec/requests/publish_intent_requests_spec.rb +++ b/spec/requests/publish_intent_requests_spec.rb @@ -1,7 +1,7 @@ RSpec.describe "Publish intent requests", type: :request do let(:content_item) do { - publish_time: (Time.zone.now + 3.hours).iso8601, + publish_time: (Time.now.utc + 3.hours).iso8601, publishing_app: "publisher", rendering_app: "frontend", routers: [ diff --git a/spec/requests/unpublishing_spec.rb b/spec/requests/unpublishing_spec.rb index 58f3f2a35..cc8196c98 100644 --- a/spec/requests/unpublishing_spec.rb +++ b/spec/requests/unpublishing_spec.rb @@ -29,7 +29,7 @@ content_item: a_hash_including( withdrawn_notice: { explanation: "Test withdrawal", - withdrawn_at: Time.zone.now.iso8601, + withdrawn_at: Time.now.utc.iso8601, }, ), } @@ -107,8 +107,8 @@ base_path:, locale: edition.locale, publishing_app: edition.publishing_app, - public_updated_at: Time.zone.now.iso8601, - first_published_at: edition.first_published_at.iso8601, + public_updated_at: Time.now.utc.iso8601, + first_published_at: edition.first_published_at.utc.iso8601, redirects: [ { path: base_path, From 8679fda5bed705eea19e78321d1736da7764fa46 Mon Sep 17 00:00:00 2001 From: Richard Towers Date: Tue, 25 Jun 2024 17:27:37 +0100 Subject: [PATCH 13/15] Rubocop fixes --- spec/models/symbolize_json_spec.rb | 1 - spec/queries/get_content_collection_spec.rb | 8 ++++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/spec/models/symbolize_json_spec.rb b/spec/models/symbolize_json_spec.rb index 20c0564de..95b4a6aaa 100644 --- a/spec/models/symbolize_json_spec.rb +++ b/spec/models/symbolize_json_spec.rb @@ -64,6 +64,5 @@ subject.reload expect(subject.details).to eq(nil) end - end end diff --git a/spec/queries/get_content_collection_spec.rb b/spec/queries/get_content_collection_spec.rb index a48aa0a86..da09acf61 100644 --- a/spec/queries/get_content_collection_spec.rb +++ b/spec/queries/get_content_collection_spec.rb @@ -604,10 +604,10 @@ describe "result order" do before do - create(:edition, base_path: "/c4", title: "D", public_updated_at: Time.utc(2014, 06, 14)) - create(:edition, base_path: "/c1", title: "A", public_updated_at: Time.utc(2014, 06, 13)) - create(:edition, base_path: "/c3", title: "C", public_updated_at: Time.utc(2014, 06, 17)) - create(:edition, base_path: "/c2", title: "B", public_updated_at: Time.utc(2014, 06, 15)) + create(:edition, base_path: "/c4", title: "D", public_updated_at: Time.utc(2014, 6, 14)) + create(:edition, base_path: "/c1", title: "A", public_updated_at: Time.utc(2014, 6, 13)) + create(:edition, base_path: "/c3", title: "C", public_updated_at: Time.utc(2014, 6, 17)) + create(:edition, base_path: "/c2", title: "B", public_updated_at: Time.utc(2014, 6, 15)) end it "returns editions in default order" do From 9f49075faf6887fae52a9692f68a729dafface60 Mon Sep 17 00:00:00 2001 From: Richard Towers Date: Tue, 25 Jun 2024 17:28:48 +0100 Subject: [PATCH 14/15] Rubocop fixes --- spec/clients/content_store_writer_spec.rb | 2 +- spec/commands/v2/put_content_spec.rb | 4 ++-- spec/factories/content_item_requests.rb | 2 +- spec/models/change_note_spec.rb | 2 +- spec/requests/publish_intent_requests_spec.rb | 2 +- spec/requests/unpublishing_spec.rb | 4 ++-- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/spec/clients/content_store_writer_spec.rb b/spec/clients/content_store_writer_spec.rb index 0c5f5501f..4919b00dd 100644 --- a/spec/clients/content_store_writer_spec.rb +++ b/spec/clients/content_store_writer_spec.rb @@ -18,7 +18,7 @@ let(:publish_intent) do { - publish_time: Time.now.utc.iso8601, + publish_time: Time.zone.now.utc.iso8601, publishing_app: "whitehall", rendering_app: "whitehall-frontend", routes: [ diff --git a/spec/commands/v2/put_content_spec.rb b/spec/commands/v2/put_content_spec.rb index d41797b95..bb2869104 100644 --- a/spec/commands/v2/put_content_spec.rb +++ b/spec/commands/v2/put_content_spec.rb @@ -172,7 +172,7 @@ edition = Edition.last - expect(edition.last_edited_at.utc.iso8601).to eq(Time.now.utc.iso8601) + expect(edition.last_edited_at.utc.iso8601).to eq(Time.zone.now.utc.iso8601) end end @@ -233,7 +233,7 @@ Timecop.freeze do described_class.call(payload) - expect(edition.reload.last_edited_at.utc.iso8601).to eq(Time.now.utc.iso8601) + expect(edition.reload.last_edited_at.utc.iso8601).to eq(Time.zone.now.utc.iso8601) end end diff --git a/spec/factories/content_item_requests.rb b/spec/factories/content_item_requests.rb index e67169c08..9be19b044 100644 --- a/spec/factories/content_item_requests.rb +++ b/spec/factories/content_item_requests.rb @@ -6,7 +6,7 @@ description { "Test description" } document_type { "answer" } schema_name { "answer" } - public_updated_at { Time.now.utc.iso8601 } + public_updated_at { Time.zone.now.utc.iso8601 } publishing_app { "publisher" } rendering_app { "frontend" } locale { "en" } diff --git a/spec/models/change_note_spec.rb b/spec/models/change_note_spec.rb index 0e6bd476d..3fb4d2025 100644 --- a/spec/models/change_note_spec.rb +++ b/spec/models/change_note_spec.rb @@ -45,7 +45,7 @@ context "payload contains public_updated_at" do it "sets the change note public_timestamp to public_updated_at time" do - time = Time.now.utc.yesterday + time = Time.zone.now.utc.yesterday payload[:public_updated_at] = time described_class.create_from_edition(payload, edition) diff --git a/spec/requests/publish_intent_requests_spec.rb b/spec/requests/publish_intent_requests_spec.rb index dfc9f13a2..5f88a99bf 100644 --- a/spec/requests/publish_intent_requests_spec.rb +++ b/spec/requests/publish_intent_requests_spec.rb @@ -1,7 +1,7 @@ RSpec.describe "Publish intent requests", type: :request do let(:content_item) do { - publish_time: (Time.now.utc + 3.hours).iso8601, + publish_time: (Time.zone.now.utc + 3.hours).iso8601, publishing_app: "publisher", rendering_app: "frontend", routers: [ diff --git a/spec/requests/unpublishing_spec.rb b/spec/requests/unpublishing_spec.rb index cc8196c98..b5d80b75c 100644 --- a/spec/requests/unpublishing_spec.rb +++ b/spec/requests/unpublishing_spec.rb @@ -29,7 +29,7 @@ content_item: a_hash_including( withdrawn_notice: { explanation: "Test withdrawal", - withdrawn_at: Time.now.utc.iso8601, + withdrawn_at: Time.zone.now.utc.iso8601, }, ), } @@ -107,7 +107,7 @@ base_path:, locale: edition.locale, publishing_app: edition.publishing_app, - public_updated_at: Time.now.utc.iso8601, + public_updated_at: Time.zone.now.utc.iso8601, first_published_at: edition.first_published_at.utc.iso8601, redirects: [ { From aebce53909dbd04258a5eb5707dd57cff0b54bfd Mon Sep 17 00:00:00 2001 From: Richard Towers Date: Wed, 26 Jun 2024 10:19:35 +0100 Subject: [PATCH 15/15] Use SymbolizeJSON to convert times to UTC for link changes --- app/queries/get_link_changes.rb | 2 +- spec/queries/get_link_changes_spec.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/queries/get_link_changes.rb b/app/queries/get_link_changes.rb index a88510269..b9bf47e0a 100644 --- a/app/queries/get_link_changes.rb +++ b/app/queries/get_link_changes.rb @@ -23,7 +23,7 @@ def as_hash end { - link_changes: results, + link_changes: SymbolizeJSON.symbolize(results), } end diff --git a/spec/queries/get_link_changes_spec.rb b/spec/queries/get_link_changes_spec.rb index 01d2503ea..f1ef7cd76 100644 --- a/spec/queries/get_link_changes_spec.rb +++ b/spec/queries/get_link_changes_spec.rb @@ -1,7 +1,7 @@ RSpec.describe Queries::GetLinkChanges do describe "#as_hash" do it "returns the link changes with the correct data" do - create(:link_change, link_type: "taxons") + link_change = create(:link_change, link_type: "taxons") result = Queries::GetLinkChanges.new(link_types: "taxons").as_hash @@ -10,6 +10,7 @@ expect(change.keys).to match_array( %i[source target link_type change user_uid created_at], ) + expect(change[:created_at]).to eql(link_change.created_at.utc.iso8601) end it "expands the source and target" do