File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -51,6 +51,10 @@ def notify!
5151 end
5252
5353 def update_publishing_api!
54+ if edition . saved_change_to_primary_locale?
55+ Whitehall ::PublishingApi . discard_translation_async ( edition , locale : edition . primary_locale_before_last_save )
56+ end
57+
5458 ServiceListeners ::PublishingApiPusher
5559 . new ( edition . reload )
5660 . push ( event : verb , options :)
Original file line number Diff line number Diff line change 1+ require "test_helper"
2+
3+ class DraftLocaleSwitchTest < ActiveSupport ::TestCase
4+ test "updates Publishing API when changing primary locale of a draft" do
5+ edition = create ( :draft_document_collection , title : "English Title" , primary_locale : "en" )
6+ edition . primary_locale = "fr"
7+ edition . save!
8+
9+ Whitehall ::PublishingApi . expects ( :patch_links ) . at_least_once
10+
11+ Whitehall ::PublishingApi . expects ( :save_draft_translation ) . with (
12+ anything ,
13+ :fr ,
14+ nil ,
15+ bulk_publishing : false ,
16+ )
17+
18+ Whitehall ::PublishingApi . expects ( :discard_translation_async ) . with (
19+ anything ,
20+ locale : "en" ,
21+ )
22+
23+ DraftEditionUpdater . new ( edition , current_user : create ( :user ) ) . perform!
24+ end
25+
26+ test "does not discard translation when primary locale is unchanged" do
27+ edition = create ( :draft_document_collection , title : "English Title" , primary_locale : "en" )
28+ edition . title = "New Title"
29+ edition . primary_locale = "en"
30+ edition . save!
31+
32+ Whitehall ::PublishingApi . expects ( :patch_links ) . at_least_once
33+ Whitehall ::PublishingApi . expects ( :save_draft_translation ) . with (
34+ anything ,
35+ :en ,
36+ nil ,
37+ bulk_publishing : false ,
38+ )
39+
40+ Whitehall ::PublishingApi . expects ( :discard_translation_async ) . never
41+
42+ DraftEditionUpdater . new ( edition , current_user : create ( :user ) ) . perform!
43+ end
44+ end
You can’t perform that action at this time.
0 commit comments