Skip to content

Commit

Permalink
rename column
Browse files Browse the repository at this point in the history
  • Loading branch information
yoomlam committed Jul 27, 2020
1 parent 3eb678b commit 3264d8d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 25 deletions.
11 changes: 5 additions & 6 deletions app/jobs/set_appeal_age_aod_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Early morning job that checks if the claimant meets the Advance-On-Docket age criteria.
# If criteria is satisfied, all active appeals associated with claimant will be marked as AOD.
# This job only sets age_aod to true; it does not set it from true to false (see appeal.conditionally_set_age_aod).
# This job only sets aod_based_on_age to true; it does not set it from true to false (see appeal.conditionally_set_age_aod).
class SetAppealAgeAodJob < CaseflowJob
include ActionView::Helpers::DateHelper

Expand All @@ -13,8 +13,7 @@ def perform
appeals = non_aod_active_appeals.joins(claimants: :person).where("people.date_of_birth <= ?", 75.years.ago)
detail_msg = "IDs of age-related AOD appeals: #{appeals.pluck(:id)}"

appeals.update_all(age_aod: true)
appeals.update_all(updated_at: Time.now.utc)
appeals.update_all(aod_based_on_age: true, updated_at: Time.now.utc)

log_success(detail_msg)
rescue StandardError => error
Expand Down Expand Up @@ -45,8 +44,8 @@ def log_error(collector_name, err, details)
private

def non_aod_active_appeals
# `age_aod` is initially nil
# `age_aod` being false means that it was once true (in the case where the claimant's DOB was updated)
Appeal.active.where(age_aod: [nil, false])
# `aod_based_on_age` is initially nil
# `aod_based_on_age` being false means that it was once true (in the case where the claimant's DOB was updated)
Appeal.active.where(aod_based_on_age: [nil, false])
end
end
14 changes: 7 additions & 7 deletions app/models/appeal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Appeal < DecisionReview
"de_novo": "de_novo"
}

after_create :conditionally_set_age_aod
after_create :conditionally_set_aod_based_on_age

after_save :set_original_stream_data

Expand Down Expand Up @@ -269,16 +269,16 @@ def regional_office_key
nil
end

def conditionally_set_age_aod
aod_based_on_age = claimant&.advanced_on_docket_based_on_age?
update(age_aod: aod_based_on_age) if age_aod != aod_based_on_age
def conditionally_set_aod_based_on_age
updated_aod_based_on_age = claimant&.advanced_on_docket_based_on_age?
update(aod_based_on_age: updated_aod_based_on_age) if aod_based_on_age != updated_aod_based_on_age
end

def advanced_on_docket?
conditionally_set_age_aod
# One of the AOD motion reasons is 'age'. Keep interrogation of any motions separate from `age_aod`,
conditionally_set_aod_based_on_age
# One of the AOD motion reasons is 'age'. Keep interrogation of any motions separate from `aod_based_on_age`,
# which reflects `claimant.advanced_on_docket_based_on_age?`.
age_aod || claimant&.advanced_on_docket_motion_granted?(receipt_date)
aod_based_on_age || claimant&.advanced_on_docket_motion_granted?(receipt_date)
end

# Prefer aod? over aod going forward, as this function returns a boolean
Expand Down
18 changes: 9 additions & 9 deletions spec/jobs/set_appeal_age_aod_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# rubocop:enable Metrics/LineLength

describe "#perform" do
let(:appeal) { create(:appeal, :with_schedule_hearing_tasks) }
let(:non_aod_appeal) { create(:appeal, :with_schedule_hearing_tasks) }

let(:age_aod_appeal) { create(:appeal, :with_schedule_hearing_tasks, :advanced_on_docket_due_to_age) }
let(:motion_aod_appeal) { create(:appeal, :with_schedule_hearing_tasks, :advanced_on_docket_due_to_motion) }
Expand All @@ -22,8 +22,8 @@
allow_any_instance_of(SlackService).to receive(:send_notification) { |_, first_arg| @slack_msg = first_arg }
end

it "sets age_aod for only active appeals with a claimant that satisfies the age criteria" do
expect(appeal.active?).to eq(true)
it "sets aod_based_on_age for only active appeals with a claimant that satisfies the age criteria" do
expect(non_aod_appeal.active?).to eq(true)
expect(age_aod_appeal.active?).to eq(true)
expect(motion_aod_appeal.active?).to eq(true)
expect(inactive_age_aod_appeal.active?).to eq(false)
Expand All @@ -32,13 +32,13 @@
described_class.perform_now
expect(@slack_msg).to include(success_msg)

# `age_aod` will be nil
# `age_aod` being false means that it was once true (in the case where the claimant's DOB was updated)
expect(appeal.reload.age_aod).not_to eq(true)
expect(inactive_age_aod_appeal.reload.age_aod).not_to eq(true)
# `aod_based_on_age` will be nil
# `aod_based_on_age` being false means that it was once true (in the case where the claimant's DOB was updated)
expect(non_aod_appeal.reload.aod_based_on_age).not_to eq(true)
expect(inactive_age_aod_appeal.reload.aod_based_on_age).not_to eq(true)

expect(age_aod_appeal.reload.age_aod).to eq(true)
expect(motion_aod_appeal.reload.age_aod).to eq(false)
expect(age_aod_appeal.reload.aod_based_on_age).to eq(true)
expect(motion_aod_appeal.reload.aod_based_on_age).to eq(false)
end

context "when the entire job fails" do
Expand Down
6 changes: 3 additions & 3 deletions spec/models/appeal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@

it "returns true" do
expect(appeal.advanced_on_docket?).to eq(true)
expect(appeal.age_aod).to eq(true)
expect(appeal.aod_based_on_age).to eq(true)
end
end

Expand All @@ -469,7 +469,7 @@

it "returns false" do
expect(appeal.advanced_on_docket?).to eq(false)
expect(appeal.age_aod).to eq(false)
expect(appeal.aod_based_on_age).to eq(false)
end
end

Expand All @@ -478,7 +478,7 @@

it "returns true" do
expect(appeal.advanced_on_docket?).to eq(true)
expect(appeal.age_aod).to eq(false)
expect(appeal.aod_based_on_age).to eq(false)
end
end
end
Expand Down

0 comments on commit 3264d8d

Please sign in to comment.