From c0b892dfbe71115f0aebd73f1e29561d99a453b0 Mon Sep 17 00:00:00 2001 From: pezholio Date: Thu, 17 Oct 2024 09:42:02 +0100 Subject: [PATCH] Add `editor_id` to top-level fields MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This ensures this value gets set if it is present. I’ve added some shared exampes to the new edition and previous draft integration specs, as these seemed like the best places for them to go. --- app/models/edition.rb | 1 + .../content_with_a_previous_draft_spec.rb | 4 ++++ .../put_content/new_edition_spec.rb | 2 ++ .../shared_context/put_content_calls.rb | 23 +++++++++++++++++++ 4 files changed, 30 insertions(+) diff --git a/app/models/edition.rb b/app/models/edition.rb index 2f7273707b..e214e9caf5 100644 --- a/app/models/edition.rb +++ b/app/models/edition.rb @@ -16,6 +16,7 @@ class Edition < ApplicationRecord description details document_type + editor_id first_published_at last_edited_at major_published_at diff --git a/spec/integration/put_content/content_with_a_previous_draft_spec.rb b/spec/integration/put_content/content_with_a_previous_draft_spec.rb index 935dfe2ae1..7a40552d16 100644 --- a/spec/integration/put_content/content_with_a_previous_draft_spec.rb +++ b/spec/integration/put_content/content_with_a_previous_draft_spec.rb @@ -52,6 +52,10 @@ expect(previously_drafted_item.last_edited_at).to eq(Time.zone.now) end + include_examples "setting editor_id" do + subject { previously_drafted_item.reload } + end + context "when public_updated_at is in the payload" do let(:public_updated_at) { Time.zone.now } before do diff --git a/spec/integration/put_content/new_edition_spec.rb b/spec/integration/put_content/new_edition_spec.rb index 894e0e6b47..2ab1ad8a13 100644 --- a/spec/integration/put_content/new_edition_spec.rb +++ b/spec/integration/put_content/new_edition_spec.rb @@ -83,6 +83,8 @@ include_examples "creates a change note" end + include_examples "setting editor_id" + context "and the change history is in the details hash" do before do payload.delete(:change_note) diff --git a/spec/support/shared_context/put_content_calls.rb b/spec/support/shared_context/put_content_calls.rb index 82ad2b3963..8fab5ebb05 100644 --- a/spec/support/shared_context/put_content_calls.rb +++ b/spec/support/shared_context/put_content_calls.rb @@ -22,4 +22,27 @@ let(:locale) { "en" } let(:content_id) { SecureRandom.uuid } let(:change_note) { "change note" } + + shared_examples "setting editor_id" do + context "when editor_id is present in the payload" do + let(:editor_id) { SecureRandom.uuid } + before do + payload.merge!( + editor_id:, + ) + end + + it "adds an editor_id to the edition" do + put "/v2/content/#{content_id}", params: payload.to_json + + expect(subject.editor_id).to eq(editor_id) + end + end + + it "does not set an editor_id by default" do + put "/v2/content/#{content_id}", params: payload.to_json + + expect(subject.editor_id).to be_nil + end + end end