Skip to content
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

CRM457-2149: Don't override adjustment comments when removing all uplifts #805

Merged
merged 4 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 8 additions & 1 deletion app/forms/nsm/uplift/base_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ def save

Claim.transaction do
claim.data[self.class::SCOPE].each do |selected_record|
row = self.class::Remover.new(claim:, explanation:, current_user:, selected_record:)
row = self.class::Remover.new(claim: claim,
explanation: explanation_for(selected_record),
current_user: current_user,
selected_record: selected_record)
next unless row.valid?

row.save
Expand All @@ -34,6 +37,10 @@ def save
rescue StandardError
false
end

def explanation_for(record)
[record['adjustment_comment'].presence, explanation].compact.join("\n\n")
end
end
end
end
17 changes: 17 additions & 0 deletions spec/forms/nsm/uplift/base_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,23 @@
end
end

context 'when the record has already been adjusted' do
before do
claim.data['letters_and_calls'][0]['adjustment_comment'] = 'Previous comment'
end

it 'preserves the previous comment' do
subject.save
expect(implementation_class::Remover).to have_received(:new)
.with(
claim: claim,
explanation: "Previous comment\n\n#{explanation}",
current_user: current_user,
selected_record: claim.data['letters_and_calls'][0]
)
end
end

context 'when invalid' do
let(:explanation) { nil }

Expand Down