Skip to content

Commit

Permalink
Merge pull request #1888 from alphagov/publish_ordering
Browse files Browse the repository at this point in the history
fix(workflow) update artefact before 'publishing' edition state
  • Loading branch information
FelixMarcusMillne authored Aug 22, 2023
2 parents 0d00cec + 6394162 commit 65e0d26
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class CannotDeletePublishedPublication < RuntimeError; end
edition.reviewer = nil
end

after_transition on: :publish do |edition, _transition|
before_transition on: :publish do |edition, _transition|
edition.was_published
end

Expand Down
16 changes: 16 additions & 0 deletions test/models/workflow_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require "test_helper"
require "minitest/autorun"

class WorkflowTest < ActiveSupport::TestCase
def setup
Expand Down Expand Up @@ -521,4 +522,19 @@ def template_user_and_published_transaction
assert_equal "schedule_for_publishing", edition.actions.last.request_type
end
end

context "#publish" do
setup do
@user = FactoryBot.create(:user, :govuk_editor)
end

should "not be in published state if the transition fails" do
edition = FactoryBot.create(:edition, state: "ready")
raise_exception = -> { raise "something went wrong with the publish transition" }
edition.stub :was_published, raise_exception do
assert_raises(RuntimeError) { publish(@user, edition, "this should fail") }
end
assert_equal "ready", edition.state
end
end
end

0 comments on commit 65e0d26

Please sign in to comment.