Skip to content

Commit 2d707d5

Browse files
authored
Merge pull request #3469 from DMPRoadmap/aaron/refactor-plan-deep-copy
Refactor `Plan.deep_copy(plan)`
2 parents a5f5b53 + f0a3ecf commit 2d707d5

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Changelog
22

3+
- Refactor Plan.deep_copy(plan) [#3469](https://github.com/DMPRoadmap/roadmap/pull/3469)
34
- Fixed a bug in the deep copy of plans where the old identifier was being copied into the new plan. We now copy the generated id of the new plan to the identifier field.
45
- Fixed bar chart click function in the Usage dashboard (GitHub issue #3443)
56

app/models/plan.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,9 @@ def self.deep_copy(plan)
257257
plan_copy.save!
258258
# Copy newly generated Id to the identifier
259259
plan_copy.identifier = plan_copy.id.to_s
260-
plan.save!
261260
plan.answers.each do |answer|
262261
answer_copy = Answer.deep_copy(answer)
263-
answer_copy.plan_id = plan_copy.id
264-
answer_copy.save!
262+
plan_copy.answers << answer_copy
265263
end
266264
plan.guidance_groups.each do |guidance_group|
267265
plan_copy.guidance_groups << guidance_group if guidance_group.present?

spec/models/plan_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,10 @@
398398
expect(subject.title).to include(plan.title)
399399
end
400400

401+
it "copies the new plan's id to its identifer" do
402+
expect(subject.identifier).to eql(subject.id.to_s)
403+
end
404+
401405
it 'persists the record' do
402406
expect(subject).to be_persisted
403407
end

0 commit comments

Comments
 (0)