Skip to content

Commit

Permalink
Merge pull request #9827 from alphagov/content-modelling/834-dont-sho…
Browse files Browse the repository at this point in the history
…w-draft-in-content-block-history-when-scheduling

(834) Don’t record drafts in version history
  • Loading branch information
pezholio authored Jan 16, 2025
2 parents b3a9b7f + e9f8b70 commit 7781ecb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ def record_create
end

def record_update
user = Current.user
state = try(:state)
versions.create!(event: "updated", user:, state:)
unless draft?
user = Current.user
state = try(:state)
versions.create!(event: "updated", user:, state:)
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ class ContentBlockManager::HasAuditTrailTest < ActiveSupport::TestCase
it "creates a 'created' version with the current user" do
user = create("user")
Current.user = user
edition = create(
edition = build(
:content_block_edition,
creator: user,
document: create(:content_block_document, :email_address),
)

assert_changes -> { edition.versions.count }, from: 0, to: 1 do
edition.save
end

version = edition.versions.first

assert_equal user.id.to_s, version.whodunnit
Expand All @@ -29,14 +34,29 @@ class ContentBlockManager::HasAuditTrailTest < ActiveSupport::TestCase
document: create(:content_block_document, :email_address),
)
edition.scheduled_publication = Time.zone.now
edition.schedule!

assert_changes -> { edition.versions.count }, from: 1, to: 2 do
edition.schedule!
end

version = edition.versions.first

assert_equal user.id.to_s, version.whodunnit
assert_equal "updated", version.event
assert_equal "scheduled", version.state
end

it "does not record a version when updating an existing draft" do
edition = create(
:content_block_edition,
document: create(:content_block_document, :email_address),
state: "draft",
)

assert_no_changes -> { edition.versions.count } do
edition.update!(details: { "foo": "bar" })
end
end
end

describe "acting_as" do
Expand Down

0 comments on commit 7781ecb

Please sign in to comment.