Skip to content

Commit

Permalink
Merge pull request rubyforgood#1140 from big-meel/881-court-date-clear
Browse files Browse the repository at this point in the history
881 court date clear
  • Loading branch information
compwron authored Oct 20, 2020
2 parents 7cda900 + 10d8fee commit 85c356a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
13 changes: 13 additions & 0 deletions app/models/casa_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ class CasaCase < ApplicationRecord
.where("birth_month_year_youth <= ?", 14.years.ago)
}

scope :due_date_passed, -> {
where("court_date < ?", Time.now)
}

def self.available_for_volunteer(volunteer)
ids = connection.select_values(%{
SELECT casa_cases.id
Expand Down Expand Up @@ -65,6 +69,15 @@ def update_cleaning_contact_types(args)
end
end

def clear_court_dates

update(court_date: nil,
court_report_due_date: nil,
court_report_submitted: false
)

end

private

def validate_date(day, month, year)
Expand Down
7 changes: 7 additions & 0 deletions lib/tasks/scheduler.rake
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,10 @@ task transition_youth: :environment do
CasaCase.should_transition.update_all(transition_aged_youth: true)
puts "done."
end

desc "Clear court dates and report information when date has passed, run by heroku scheduler"
task clear_passed_dates: :environment do
puts "Checking case due dates..."
CasaCase.due_date_passed.each { |key| key.clear_court_dates }
puts "done."
end
31 changes: 31 additions & 0 deletions spec/models/casa_case_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,35 @@
expect(casa_case.contact_types.reload).to match_array([type2])
end
end

describe "#clear_court_dates" do
context "when court date has passed" do


it "clears court date" do

casa_case = create(:casa_case, court_date: "2020-09-13 02:11:58")
casa_case.clear_court_dates

expect(casa_case.court_date).to eql nil
end

it "clears report due date" do

casa_case = create(:casa_case, court_date: "2020-09-13 02:11:58", court_report_due_date: "2020-09-13 02:11:58")
casa_case.clear_court_dates

expect(casa_case.court_report_due_date).to eql nil
end

it "sets court report as unsubmitted" do

casa_case = create(:casa_case, court_date: "2020-09-13 02:11:58", court_report_submitted: true)
casa_case.clear_court_dates

expect(casa_case.court_report_submitted).to eql false
end

end
end
end

0 comments on commit 85c356a

Please sign in to comment.