Skip to content

Commit d96a3df

Browse files
lfdebruxSamJamCul
authored andcommitted
Use full precision timestamps in JSON serializations
In forms-api PR govuk-forms/forms-api#790 we increased the precision of timestamps when serializing to the maximum; we should do the same in forms-admin.
1 parent e259031 commit d96a3df

3 files changed

Lines changed: 6 additions & 3 deletions

File tree

config/application.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,8 @@ class Application < Rails::Application
6565

6666
# Prevent ActiveRecord::PreparedStatementCacheExpired errors when adding columns
6767
config.active_record.enumerate_columns_in_select_statements = true
68+
69+
# Include full precision of timestamps in JSON responses
70+
config.active_support.time_precision = 6
6871
end
6972
end

spec/requests/forms/make_live_controller_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130

131131
it "sets the FormDocument's live_at time to be equal to the form's updated_at time" do
132132
post(make_live_path(form_id: form.id), params: form_params)
133-
expect(FormDocument.find_by(form_id: form.id, tag: "live")["content"]["live_at"]).to eq form.reload.updated_at.strftime("%Y-%m-%dT%H:%M:%S.%LZ")
133+
expect(FormDocument.find_by(form_id: form.id, tag: "live")["content"]["live_at"]).to eq form.reload.updated_at.strftime("%Y-%m-%dT%H:%M:%S.%6NZ")
134134
end
135135
end
136136

spec/services/form_document_sync_service_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
describe "#synchronize_form" do
88
context "when form state is live" do
99
let(:form) { create(:form, :live) }
10-
let(:expected_live_at) { form.reload.updated_at.strftime("%Y-%m-%dT%H:%M:%S.%LZ") }
10+
let(:expected_live_at) { form.reload.updated_at.strftime("%Y-%m-%dT%H:%M:%S.%6NZ") }
1111

1212
context "when there is no existing form document" do
1313
it "creates a live form document" do
@@ -32,7 +32,7 @@
3232

3333
it "updates the live_at date in the form document" do
3434
service.synchronize_form(form)
35-
expect(FormDocument.last["content"]).to include("live_at" => form.reload.updated_at.strftime("%Y-%m-%dT%H:%M:%S.%LZ"))
35+
expect(FormDocument.last["content"]).to include("live_at" => form.reload.updated_at.strftime("%Y-%m-%dT%H:%M:%S.%6NZ"))
3636
end
3737
end
3838

0 commit comments

Comments
 (0)