8000 Refactor `Plan.deep_copy(plan)` by aaronskiba · Pull Request #3469 · DMPRoadmap/roadmap · GitHub
[go: up one dir, main page]

Skip to content

Refactor Plan.deep_copy(plan) #3469

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 16, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Changelog

- Refactor Plan.deep_copy(plan) [#3469](https://github.com/DMPRoadmap/roadmap/pull/3469)
- 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.
- Fixed bar chart click function in the Usage dashboard (GitHub issue #3443)

Expand Down
4 changes: 1 addition & 3 deletions app/models/plan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,9 @@ def self.deep_copy(plan)
plan_copy.save!
# Copy newly generated Id to the identifier
plan_copy.identifier = plan_copy.id.to_s
plan.save!
plan.answers.each do |answer|
answer_copy = Answer.deep_copy(answer)
answer_copy.plan_id = plan_copy.id
answer_copy.save!
plan_copy.answers << answer_copy
end
plan.guidance_groups.each do |guidance_group|
plan_copy.guidance_groups << guidance_group if guidance_group.present?
Expand Down
4 changes: 4 additions & 0 deletions spec/models/plan_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,10 @@
expect(subject.title).to include(plan.title)
end

it "copies the new plan's id to its identifer" do
expect(subject.identifier).to eql(subject.id.to_s)
end

it 'persists the record' do
expect(subject).to be_persisted
end
Expand Down
0