Skip to content

Commit ce34bef

Browse files
committed
Prevent making Welsh live if the form has draft changes
We need to prevent Welsh forms being made live if there are changes to the draft since the form was made live. If we don't, it's possible for a user to: - make an English version of the form live - make a change to that English version (e.g. adding or deleting a question) - complete the Welsh translations for the form - make the Welsh version live without making the English changes live In this case the different language versions would be out of sync, as the English and Welsh form documents would be from before and after the change respectively. This would lead to unexpected behaviour for form fillers when switching languages.
1 parent 4e02643 commit ce34bef

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

app/models/form.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,15 @@ def can_make_english_version_live?
296296
end
297297

298298
def can_make_welsh_version_live?
299-
has_live_version && all_ready_for_live? && welsh_completed? && live_form_document.present? && live_welsh_form_document.blank?
299+
english_version_has_been_made_live? && welsh_version_ready? && live_welsh_form_document.blank?
300+
end
301+
302+
def english_version_has_been_made_live?
303+
!has_draft_version && has_live_version && live_form_document.present?
304+
end
305+
306+
def welsh_version_ready?
307+
all_ready_for_live? && welsh_completed?
300308
end
301309

302310
def after_archive

spec/models/form_spec.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1644,7 +1644,7 @@
16441644
context "when the Welsh task is still in progress" do
16451645
let(:form) { create :form, :ready_for_live, :with_welsh_translation, state: "live", welsh_completed: false }
16461646

1647-
it "returns true" do
1647+
it "returns false" do
16481648
expect(form.can_make_language_live?(language:)).to be false
16491649
end
16501650
end
@@ -1655,6 +1655,20 @@
16551655
it "returns true" do
16561656
expect(form.can_make_language_live?(language:)).to be true
16571657
end
1658+
1659+
context "when there are changes which have not yet been made live on the English version" do
1660+
before do
1661+
form.name = "A new form name"
1662+
form.save_draft!
1663+
1664+
form.share_preview_completed = true
1665+
form.save_draft!
1666+
end
1667+
1668+
it "returns false" do
1669+
expect(form.can_make_language_live?(language:)).to be false
1670+
end
1671+
end
16581672
end
16591673
end
16601674

0 commit comments

Comments
 (0)