Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/services/form_copy_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ def copy(tag: "draft")

copy_pages(content["steps"])
copy_routing_conditions(content["steps"])
copy_group

@copied_form.copied_from_id = @form.id
@copied_form.creator_id = @logged_in_user.id
@copied_form.save!

copy_group

# Copy Welsh translations if available
if @form.available_languages.include?("cy")
copy_welsh_translations(tag:)
Expand Down
24 changes: 19 additions & 5 deletions spec/services/form_copy_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
let(:source_form) { create(:form, :live_with_draft) }
let(:source_form_document) { FormDocument.find_by(form_id: source_form.id) }
let(:logged_in_user) { create(:user) }
let(:copied_form) { described_class.new(source_form, logged_in_user).copy(tag: "live") }
let(:tag) { "live" }
let(:copied_form) { described_class.new(source_form, logged_in_user).copy(tag:) }

before do
GroupForm.create!(form: source_form, group: group)
Expand Down Expand Up @@ -233,11 +234,24 @@

context "when source form is in a group" do
let(:group) { create(:group) }
let(:source_form) { create(:form, :live_with_draft) }

it "places the copied form in the same group as the original form" do
expect(copied_form.group).to eq(source_form.group)
expect(copied_form.group).to eq(group)
context "when copying a live form" do
let(:source_form) { create(:form, :live_with_draft) }

it "places the copied form in the same group as the original form" do
expect(copied_form.group).to eq(source_form.group)
expect(copied_form.group).to eq(group)
end
end

context "when copying a draft form with no pages" do
let(:source_form) { create(:form) }
let(:tag) { "draft" }

it "places the copied form in the same group as the original form" do
expect(copied_form.group).to eq(source_form.group)
expect(copied_form.group).to eq(group)
end
end
end

Expand Down