Skip to content

Commit

Permalink
5015-draft-support-nov //
Browse files Browse the repository at this point in the history
response to CR
  • Loading branch information
Sam Williams committed Jan 8, 2024
1 parent 3d4bee4 commit fa23a47
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
24 changes: 15 additions & 9 deletions app/decorators/case_contact_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,7 @@ def duration_minutes
elsif minutes <= 60
"#{minutes} minutes"
else
formatted_hour_value = minutes / 60
formatted_minutes_value = minutes.remainder(60)

if formatted_minutes_value.zero?
"#{formatted_hour_value} #{"hour".pluralize(formatted_hour_value)}"
else
"#{formatted_hour_value} #{"hour".pluralize(formatted_hour_value)} #{formatted_minutes_value} minutes"
end
formatted_hours_and_minutes(minutes)
end
end

Expand Down Expand Up @@ -115,7 +108,7 @@ def additional_expenses_count
end

def address_of_volunteer
if volunteer_address && !volunteer_address.empty?
if volunteer_address&.present?
volunteer_address
elsif volunteer
volunteer.address&.content
Expand All @@ -139,4 +132,17 @@ def form_page_notes
def form_updated_message
"Case contact created at #{I18n.l(created_at, format: :time_on_date)}, was successfully updated."
end

private

def formatted_hours_and_minutes(minutes)
formatted_hour_value = minutes / 60
formatted_minutes_value = minutes.remainder(60)

if formatted_minutes_value.zero?
"#{formatted_hour_value} #{"hour".pluralize(formatted_hour_value)}"
else
"#{formatted_hour_value} #{"hour".pluralize(formatted_hour_value)} #{formatted_minutes_value} minutes"
end
end
end
9 changes: 9 additions & 0 deletions app/models/case_contact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class CaseContact < ApplicationRecord
validate :occurred_at_not_in_future
validate :reimbursement_only_when_miles_driven, if: :active_or_expenses?
validate :volunteer_address_when_reimbursement_wanted, if: :active_or_expenses?
validate :volunteer_address_is_valid, if: :active_or_expenses?

belongs_to :creator, class_name: "User"
has_one :supervisor_volunteer, -> {
Expand Down Expand Up @@ -199,6 +200,14 @@ def volunteer_address_when_reimbursement_wanted
end
end

def volunteer_address_is_valid
if volunteer_address&.present?
if Address.new(user_id: creator.id, content: volunteer_address).invalid?
errors.add(:base, "The volunteer's address is not valid.")
end
end
end

def contact_made_chosen
errors.add(:base, "Must enter whether the contact was made.") if contact_made.nil?
!contact_made.nil?
Expand Down
2 changes: 1 addition & 1 deletion spec/requests/case_contacts/form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
let(:organization) { build(:casa_org) }
let(:admin) { create(:casa_admin, casa_org: organization) }
let(:supervisor) { create(:supervisor, casa_org: organization) }
let(:volunteer) { create(:volunteer, casa_org: organization, supervisor: supervisor) }
let!(:volunteer) { create(:volunteer, casa_org: organization, supervisor: supervisor) }
let(:creator) { admin }
let!(:casa_case) { create(:casa_case, casa_org: organization) }

Expand Down

0 comments on commit fa23a47

Please sign in to comment.