Skip to content

Commit

Permalink
Only reopen judge assign tasks if attorney tasks are cancelled (#12491)
Browse files Browse the repository at this point in the history
* Only reopen judge assign tasks if attorney tasks are cancelled

* Add spec for attorney rewrite task

* Update attorney_quality_review_task_spec.rb

* Update attorney_rewrite_task_spec.rb

* Update attorney_rewrite_task_spec.rb
  • Loading branch information
hschallhorn authored Oct 28, 2019
1 parent 30add3b commit bab4a7f
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 4 deletions.
6 changes: 3 additions & 3 deletions app/models/tasks/attorney_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AttorneyTask < Task
validate :assigned_to_role_is_valid
validate :child_attorney_tasks_are_completed, on: :create

after_update :send_back_to_judge_assign, if: :task_just_cancelled?
after_update :send_back_to_judge_assign, if: :attorney_task_just_cancelled?

def available_actions(user)
# Both the judge who assigned this task and the judge who is assigned the parent review task get these actions
Expand Down Expand Up @@ -63,8 +63,8 @@ def assigned_by_role_is_valid
errors.add(:assigned_by, "has to be a judge") if assigned_by && !assigned_by.judge_in_vacols?
end

def task_just_cancelled?
saved_change_to_attribute?("status") && cancelled?
def attorney_task_just_cancelled?
type.eql?(AttorneyTask.name) && saved_change_to_attribute?("status") && cancelled?
end

def send_back_to_judge_assign
Expand Down
6 changes: 6 additions & 0 deletions spec/factories/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,12 @@
end
end

factory :ama_attorney_rewrite_task, class: AttorneyRewriteTask do
type { AttorneyRewriteTask.name }
appeal { create(:appeal) }
parent { create(:ama_judge_decision_review_task) }
end

factory :ama_judge_dispatch_return_to_attorney_task, class: AttorneyDispatchReturnTask do
type { AttorneyDispatchReturnTask.name }
appeal { create(:appeal) }
Expand Down
23 changes: 22 additions & 1 deletion spec/models/tasks/attorney_quality_review_task_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# frozen_string_literal: true

require "rails_helper"
require "support/database_cleaner"
require "support/vacols_database_cleaner"

describe AttorneyQualityReviewTask do
describe AttorneyQualityReviewTask, :all_dbs do
context ".create" do
it "returns the correct label" do
expect(AttorneyQualityReviewTask.new.label).to eq(
Expand All @@ -16,4 +18,23 @@
)
end
end

context "when cancelling the task" do
let(:atty) { create(:user) }
let(:judge) { create(:user) }
let!(:atty_staff) { create(:staff, :attorney_role, sdomainid: atty.css_id) }
let!(:judge_staff) { create(:staff, :judge_role, sdomainid: judge.css_id) }
let(:parent) { create(:ama_judge_dispatch_return_task) }
let!(:task) do
create(:ama_judge_dispatch_return_to_attorney_task, assigned_by: judge, assigned_to: atty, parent: parent)
end

subject { task.update!(status: Constants.TASK_STATUSES.cancelled) }

it "cancels the task and moves the parent back to the judge's queue" do
expect(subject).to be true
expect(task.reload.status).to eq Constants.TASK_STATUSES.cancelled
expect(parent.reload.status).to eq Constants.TASK_STATUSES.assigned
end
end
end
26 changes: 26 additions & 0 deletions spec/models/tasks/attorney_rewrite_task_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

require "rails_helper"
require "support/database_cleaner"
require "support/vacols_database_cleaner"

describe AttorneyRewriteTask, :all_dbs do
context "when cancelling the task" do
let(:atty) { create(:user) }
let(:judge) { create(:user) }
let!(:atty_staff) { create(:staff, :attorney_role, sdomainid: atty.css_id) }
let!(:judge_staff) { create(:staff, :judge_role, sdomainid: judge.css_id) }
let(:parent) { create(:ama_judge_decision_review_task) }
let!(:task) do
create(:ama_attorney_rewrite_task, assigned_by: judge, assigned_to: atty, parent: parent)
end

subject { task.update!(status: Constants.TASK_STATUSES.cancelled) }

it "cancels the task and moves the parent back to the judge's queue" do
expect(subject).to be true
expect(task.reload.status).to eq Constants.TASK_STATUSES.cancelled
expect(parent.reload.status).to eq Constants.TASK_STATUSES.assigned
end
end
end

0 comments on commit bab4a7f

Please sign in to comment.