Created
February 20, 2018 10:51
-
-
Save floehopper/1d35fb77d91ec85ac70276bf99f292e5 to your computer and use it in GitHub Desktop.
Publish event for force_publish within EditionUnwithdrawer#perform!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit 3253a2b7cdf1ba8b60365638ad1b517bbc1e30fd | |
Author: James Mead <james@floehopper.org> | |
Date: Sun Feb 18 12:21:40 2018 +0000 | |
Publish event for force_publish within EditionUnwithdrawer#perform! | |
The EditionUnwithdrawer was already publishing an 'unwithdrawn' event to | |
the notifier for the originally withdrawn edition which ends up as | |
superseded, but it was not publishing a 'force_publish' event for the | |
new draft edition which is force-published. | |
diff --git a/app/services/edition_unwithdrawer.rb b/app/services/edition_unwithdrawer.rb | |
index e822efb3e..d41c2a14d 100644 | |
--- a/app/services/edition_unwithdrawer.rb | |
+++ b/app/services/edition_unwithdrawer.rb | |
@@ -41,9 +41,10 @@ def fire_transition! | |
def force_publish!(unwithdrawn_edition) | |
# The perform! method could be called instead, but this would lead to a nested transaction, | |
# with possible race conditions | |
- force_publisher = EditionForcePublisher.new(unwithdrawn_edition) | |
+ force_publisher = EditionForcePublisher.new(unwithdrawn_edition, user: user, notifier: notifier) | |
force_publisher.send(:prepare_edition) | |
force_publisher.send(:fire_transition!) | |
+ force_publisher.send(:notify!) | |
end | |
def user | |
diff --git a/test/unit/services/edition_unwithdrawer_test.rb b/test/unit/services/edition_unwithdrawer_test.rb | |
index 633a0b192..1ddec0b7b 100644 | |
--- a/test/unit/services/edition_unwithdrawer_test.rb | |
+++ b/test/unit/services/edition_unwithdrawer_test.rb | |
@@ -43,7 +43,7 @@ class EditionUnwithdrawerTest < ActiveSupport::TestCase | |
test "unwithdraw handles legacy withdrawn editions" do | |
edition = FactoryBot.create(:published_edition, state: 'withdrawn') | |
- unwithdrawn_edition = unwithdraw(edition) | |
+ unwithdrawn_edition = unwithdraw(edition: edition) | |
assert unwithdrawn_edition.published? | |
assert unwithdrawn_edition.minor_change | |
@@ -52,9 +52,16 @@ class EditionUnwithdrawerTest < ActiveSupport::TestCase | |
assert_equal "Unwithdrawn", unwithdrawn_edition.editorial_remarks.first.body | |
end | |
- def unwithdraw(edition = nil) | |
+ test 'publishes events to notifier' do | |
+ notifier = stub('notifier') | |
+ notifier.expects(:publish).with('unwithdraw', @edition, user: @user) | |
+ notifier.expects(:publish).with('force_publish', Not(equals(@edition)), user: @user) | |
+ unwithdraw(notifier: notifier) | |
+ end | |
+ | |
+ def unwithdraw(edition: nil, notifier: nil) | |
edition ||= @edition | |
- @unwithdrawer = EditionUnwithdrawer.new(edition, user: @user) | |
+ @unwithdrawer = EditionUnwithdrawer.new(edition, user: @user, notifier: notifier) | |
@unwithdrawer.perform! | |
edition.document.published_edition | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment