Skip to content

Commit

Permalink
Skip soft-deleted RequestIssues for match on decision review edit (#9005
Browse files Browse the repository at this point in the history
)

connects #8799 

### Description
Exclude RequestIssues that are not associated with any review_request, as they are "soft deleted."
  • Loading branch information
pkarman authored and va-bot committed Jan 28, 2019
1 parent 8f32fbd commit 626f57b
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/models/decision_review.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def contestable_issues
end

def active_nonrating_request_issues
@active_nonrating_request_issues ||= RequestIssue.nonrating
@active_nonrating_request_issues ||= RequestIssue.nonrating.not_deleted
.where(veteran_participant_id: veteran.participant_id)
.where.not(id: request_issues.map(&:id))
.select(&:status_active?)
Expand Down
18 changes: 12 additions & 6 deletions app/models/request_issue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ def nonrating
).where.not(issue_category: nil)
end

def not_deleted
where.not(review_request_id: nil)
end

def unidentified
where(
contested_rating_issue_reference_id: nil,
Expand Down Expand Up @@ -348,13 +352,15 @@ def legacy_issue_opted_in?
# Instead of fully deleting removed issues, we instead strip them from the review so we can
# maintain a record of the other data that was on them incase we need to revert the update.
def remove_from_review
update!(review_request: nil)
legacy_issue_optin&.flag_for_rollback!
transaction do
update!(review_request: nil)
legacy_issue_optin&.flag_for_rollback!

# removing a request issue also deletes the associated request_decision_issue
# if the decision issue is not associated with any other request issue, also delete
decision_issues.each { |decision_issue| decision_issue.destroy_on_removed_request_issue(id) }
decision_issues.delete_all
# removing a request issue also deletes the associated request_decision_issue
# if the decision issue is not associated with any other request issue, also delete
decision_issues.each { |decision_issue| decision_issue.destroy_on_removed_request_issue(id) }
decision_issues.delete_all
end
end

def create_decision_issue_from_params(decision_issue_param)
Expand Down
30 changes: 28 additions & 2 deletions spec/feature/intake/higher_level_review/edit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -546,8 +546,7 @@
click_intake_add_issue
click_intake_no_matching_issues

fill_in "Issue category", with: active_nonrating_request_issue.issue_category
find("#issue-category").send_keys :enter
click_dropdown(text: active_nonrating_request_issue.issue_category)
expect(page).to have_content("Does issue 2 match any of the issues actively being reviewed?")
expect(page).to have_content("#{active_nonrating_request_issue.issue_category}: " \
"#{active_nonrating_request_issue.description}")
Expand All @@ -574,6 +573,33 @@
).to_not be_nil
end
end

context "nonrating request issue was added and then removed" do
let!(:active_nonrating_request_issue) do
create(
:request_issue,
:nonrating,
review_request: higher_level_review
)
end

before do
higher_level_review.create_issues!([active_nonrating_request_issue])
active_nonrating_request_issue.remove_from_review
higher_level_review.reload
end

it "does not appear as a potential match on edit" do
visit "higher_level_reviews/#{nonrating_ep_claim_id}/edit"
click_intake_add_issue
click_intake_no_matching_issues
click_dropdown(text: active_nonrating_request_issue.issue_category)

expect(page).to have_content("Does issue 2 match any of these issue categories?")
expect(page).to_not have_content("Does issue match any of the issues actively being reviewed?")
expect(page).to_not have_content("nonrating issue description")
end
end
end

context "Veteran has no ratings" do
Expand Down
10 changes: 10 additions & 0 deletions spec/models/request_issue_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,16 @@
end
end

context ".not_deleted" do
subject { RequestIssue.not_deleted }

let!(:deleted_request_issue) { create(:request_issue, review_request: nil) }

it "filters by whether it is associated with a review_request" do
expect(subject.find_by(id: deleted_request_issue.id)).to be_nil
end
end

context ".find_active_by_contested_rating_issue_reference_id" do
let(:active_rating_request_issue) do
rating_request_issue.tap do |ri|
Expand Down

0 comments on commit 626f57b

Please sign in to comment.