Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 7 additions & 1 deletion app/controllers/casa_cases_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,13 @@ def set_casa_case

# Only allow a list of trusted parameters through.
def casa_case_params
params.require(:casa_case).permit(:case_number, :transition_aged_youth, :birth_month_year_youth, :court_date)
params.require(:casa_case).permit(
:case_number,
:transition_aged_youth,
:birth_month_year_youth,
:court_date,
:court_report_due_date
)
end

# Separate params so only admins can update the case_number
Expand Down
35 changes: 22 additions & 13 deletions app/models/casa_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,11 @@ def has_transitioned?
end

def update_cleaning_contact_types(args)
begin
args = parse_court_date(args)
rescue Date::Error
errors.messages[:court_date] << "was not a valid date."
return false
end
args = parse_date("court_date", args)
args = parse_date("court_report_due_date", args)

return false unless errors.messages.empty?

transaction do
casa_case_contact_types.destroy_all
update(args)
Expand All @@ -68,14 +67,23 @@ def update_cleaning_contact_types(args)

private

def parse_court_date(args)
day = args.delete("court_date(3i)")
month = args.delete("court_date(2i)")
year = args.delete("court_date(1i)")
return args if day.blank? && month.blank? && year.blank?
def validate_date(day, month, year)
raise Date::Error if day.blank? || month.blank? || year.blank?
court_date = Date.parse("#{day}-#{month}-#{year}")
args["court_date"] = court_date

Date.parse("#{day}-#{month}-#{year}")
end

def parse_date(date_field_name, args)
day = args.delete("#{date_field_name}(3i)")
month = args.delete("#{date_field_name}(2i)")
year = args.delete("#{date_field_name}(1i)")

return args if day.blank? && month.blank? && year.blank?

args[date_field_name.to_sym] = validate_date(day, month, year)
args
rescue Date::Error
errors.messages[date_field_name.to_sym] << "was not a valid date."
args
end
end
Expand All @@ -88,6 +96,7 @@ def parse_court_date(args)
# birth_month_year_youth :datetime
# case_number :string not null
# court_date :datetime
# court_report_due_date :datetime
# court_report_submitted :boolean default(FALSE), not null
# transition_aged_youth :boolean default(FALSE), not null
# created_at :datetime not null
Expand Down
4 changes: 2 additions & 2 deletions app/policies/casa_case_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ def permitted_attributes

case @user
when CasaAdmin
common_attrs.concat(%i[case_number birth_month_year_youth court_date])
common_attrs.concat(%i[case_number birth_month_year_youth court_date court_report_due_date])
when Supervisor
common_attrs.concat(%i[court_date])
common_attrs.concat(%i[court_date court_report_due_date])
else
common_attrs
end
Expand Down
14 changes: 13 additions & 1 deletion app/views/casa_cases/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</div>

<div class="field form-group">
<% if current_user.casa_admin? || current_user.supervisor? %>
<% if current_user.casa_admin? || current_user.supervisor? %>
<%= form.label :court_date, "Next Court Date" %>
<br>
<span class="datetime-year-month"> <%= form.date_select :court_date, {order: [:day, :month, :year], start_year: Date.current.year + 3, end_year: 2000, prompt: {day: 'Day', month: 'Month', year: 'Year'} }, class: "select2 date-input" %></span>
Expand All @@ -24,6 +24,18 @@
<% end %>
</div>

<div class="field form-group">
<% if current_user.casa_admin? || current_user.supervisor? %>
<%= form.label :court_report_due_date, "Court Report Due Date" %>
<br>
<span class="datetime-year-month"> <%= form.date_select :court_report_due_date, {order: [:day, :month, :year], start_year: Date.current.year + 3, end_year: 2000, prompt: {day: 'Day', month: 'Month', year: 'Year'} }, class: "select2 date-input" %></span>
<% else %>
<label for="court_report_due_date">
Court Report Due Date: <%= l @casa_case.court_report_due_date, format: :day_and_date, default: '' %>
</label>
<% end %>
</div>

<% if current_user.casa_admin? %>
<div class="field form-group">
<%= form.label :birth_month_year_youth, "Youth's Birth Month & Year" %>
Expand Down
4 changes: 4 additions & 0 deletions app/views/casa_cases/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
<h6><strong>Next Court Date:</strong> <%= l @casa_case.court_date, format: :day_and_date, default: '' %></h6>
</p>

<p>
<h6><strong>Court Report Due Date:</strong> <%= l @casa_case.court_report_due_date, format: :day_and_date, default: '' %></h6>
</p>

<p>
<h6><strong>Court Report Submission:</strong> <%= @casa_case.decorate.court_report_submission %>
</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddCourtReportDueDateToCasaCases < ActiveRecord::Migration[6.0]
def change
add_column :casa_cases, :court_report_due_date, :datetime
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2020_10_02_192636) do
ActiveRecord::Schema.define(version: 2020_10_04_165322) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -45,6 +45,7 @@
t.datetime "birth_month_year_youth"
t.boolean "court_report_submitted", default: false, null: false
t.datetime "court_date"
t.datetime "court_report_due_date"
t.index ["casa_org_id"], name: "index_casa_cases_on_casa_org_id"
t.index ["case_number"], name: "index_casa_cases_on_case_number", unique: true
end
Expand Down
79 changes: 43 additions & 36 deletions spec/system/admin_adds_new_case_spec.rb
Original file line number Diff line number Diff line change
@@ -1,66 +1,73 @@
require 'rails_helper'
require "rails_helper"

RSpec.describe 'admin adds a new case', type: :system do
RSpec.describe "admin adds a new case", type: :system do
let(:admin) { create(:casa_admin) }
let(:case_number) { '12345' }
let(:case_number) { "12345" }
let!(:next_year) { (Date.today.year + 1).to_s }

before do
sign_in admin
visit root_path
click_on 'Cases'
click_on "Cases"

click_on 'New Case'
click_on "New Case"
end

context 'when all fields are filled' do
it 'is successful' do
fill_in 'Case number', with: case_number
select '3', from: 'casa_case_court_date_3i'
select 'March', from: 'casa_case_court_date_2i'
select '2020', from: 'casa_case_court_date_1i'

check 'Transition aged youth'
has_checked_field? 'Transition aged youth'

click_on 'Create CASA Case'
context "when all fields are filled" do
it "is successful" do
fill_in "Case number", with: case_number
select "3", from: "casa_case_court_date_3i"
select "March", from: "casa_case_court_date_2i"
select next_year, from: "casa_case_court_date_1i"

select "1", from: "casa_case_court_report_due_date_3i"
select "April", from: "casa_case_court_report_due_date_2i"
select next_year, from: "casa_case_court_report_due_date_1i"

check "Transition aged youth"
has_checked_field? "Transition aged youth"

click_on "Create CASA Case"

expect(page.body).to have_content(case_number)
expect(page).to have_content('CASA case was successfully created.')
expect(page).to have_content('Next Court Date: Tuesday, 3-MAR-2020')
expect(page).to have_content('Transition Aged Youth: Yes')
expect(page).to have_content("CASA case was successfully created.")
expect(page).to have_content("Next Court Date: Wednesday, 3-MAR-2021")
expect(page).to have_content("Court Report Due Date: Thursday, 1-APR-2021")
expect(page).to have_content("Transition Aged Youth: Yes")
end
end

context 'when non-mandatory fields are not filled' do
it 'is successful' do
fill_in 'Case number', with: case_number
click_on 'Create CASA Case'
context "when non-mandatory fields are not filled" do
it "is successful" do
fill_in "Case number", with: case_number
click_on "Create CASA Case"

expect(page.body).to have_content(case_number)
expect(page).to have_content('CASA case was successfully created.')
expect(page).to have_content('Next Court Date:')
expect(page).to have_content('Transition Aged Youth: No')
expect(page).to have_content("CASA case was successfully created.")
expect(page).to have_content("Next Court Date:")
expect(page).to have_content("Court Report Due Date:")
expect(page).to have_content("Transition Aged Youth: No")
end
end

context 'when the case number field is not filled' do
it 'does not create a new case' do
click_on 'Create CASA Case'
context "when the case number field is not filled" do
it "does not create a new case" do
click_on "Create CASA Case"

expect(current_path).to eq(casa_cases_path)
expect(page).to have_content('Case number can\'t be blank')
expect(page).to have_content("Case number can't be blank")
end
end

context 'when the case number already exists' do
context "when the case number already exists" do
let!(:casa_case) { create(:casa_case, case_number: case_number) }
it 'does not create a new case' do
fill_in 'Case number', with: case_number
click_on 'Create CASA Case'

it "does not create a new case" do
fill_in "Case number", with: case_number
click_on "Create CASA Case"

expect(current_path).to eq(casa_cases_path)
expect(page).to have_content('Case number has already been taken')
expect(page).to have_content("Case number has already been taken")
end
end
end
1 change: 1 addition & 0 deletions spec/system/admin_edits_a_case_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

has_checked_field? :court_report_submitted
expect(page).to have_text("Court Date")
expect(page).to have_text("Court Report Due Date")
expect(page).to have_text("Day")
expect(page).to have_text("Month")
expect(page).to have_text("Year")
Expand Down
28 changes: 26 additions & 2 deletions spec/system/supervisor_edits_case_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,39 +23,63 @@
select "4", from: "casa_case_court_date_3i"
select "November", from: "casa_case_court_date_2i"
select next_year, from: "casa_case_court_date_1i"

select "8", from: "casa_case_court_report_due_date_3i"
select "September", from: "casa_case_court_report_due_date_2i"
select next_year, from: "casa_case_court_report_due_date_1i"

click_on "Update CASA Case"
has_checked_field? :court_report_submitted
has_checked_field? "Youth"
has_no_checked_field? "Supervisor"

expect(page).to have_text("Court Date")
expect(page).to have_text("Court Report Due Date")
expect(page).to have_text("Day")
expect(page).to have_text("Month")
expect(page).to have_text("Year")
expect(page).to have_text("November")
expect(page).to have_text("September")

visit casa_case_path(casa_case)

expect(page).to have_text("Court Report Submission: Submitted")
expect(page).to have_text("4-NOV-#{next_year}")
expect(page).to have_text("8-SEP-#{next_year}")
end

it "will return error message if date is not fully selected" do
it "will return error message if date fields are not fully selected" do
visit casa_case_path(casa_case)
expect(page).to have_text("Court Report Submission: Not Submitted")
visit edit_casa_case_path(casa_case)
has_no_checked_field? :court_report_submitted

select "November", from: "casa_case_court_date_2i"
select "April", from: "casa_case_court_report_due_date_2i"

click_on "Update CASA Case"

expect(page).to have_text("Court date was not a valid date.")
expect(page).to have_text("Court report due date was not a valid date.")
end

it "will return error message if date is not valid" do
it "will return error message if date fields are not valid" do
visit casa_case_path(casa_case)
expect(page).to have_text("Court Report Submission: Not Submitted")
visit edit_casa_case_path(casa_case)
has_no_checked_field? :court_report_submitted

select "31", from: "casa_case_court_date_3i"
select "April", from: "casa_case_court_date_2i"
select next_year, from: "casa_case_court_date_1i"

select "31", from: "casa_case_court_report_due_date_3i"
select "April", from: "casa_case_court_report_due_date_2i"
select next_year, from: "casa_case_court_report_due_date_1i"

click_on "Update CASA Case"

expect(page).to have_text("Court date was not a valid date.")
expect(page).to have_text("Court report due date was not a valid date.")
end
end
2 changes: 1 addition & 1 deletion spec/system/user_views_supervisor_edit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
click_on "Submit"
page.find ".header-flash > div"
supervisor.reload
}.to change {supervisor.email}.to "new" + supervisor.email
}.to change { supervisor.email }.to "new" + supervisor.email
end
end

Expand Down
1 change: 1 addition & 0 deletions spec/system/volunteer_edits_case_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
has_checked_field? :court_report_submitted

expect(page).to have_text("Court Date")
expect(page).to have_text("Court Report Due Date")
expect(page).not_to have_text("Day")
expect(page).not_to have_text("Month")
expect(page).not_to have_text("Year")
Expand Down