Skip to content

Commit

Permalink
Merge pull request #2132 from rhian-cs/implement-pending-past-court-d…
Browse files Browse the repository at this point in the history
…ate-model-specs

Implement pending past court date model specs
  • Loading branch information
compwron authored Jun 8, 2021
2 parents fc86484 + 5a5012a commit 6227bcc
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/models/past_court_date.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class PastCourtDate < ApplicationRecord
belongs_to :hearing_type, optional: true
belongs_to :judge, optional: true

DOCX_TEMPLATE_PATH = "app/documents/templates/default_past_court_date_template.docx"
DOCX_TEMPLATE_PATH = Rails.root.join("app", "documents", "templates", "default_past_court_date_template.docx")

# get reports associated with the case this belongs to before this court date but after the court date before this one
def associated_reports
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,49 @@
describe "methods" do
let(:past_court_date) { build_stubbed(:past_court_date) }

pending "#associated_reports"
pending "#latest_associated_report"
describe "reports methods" do
let(:past_court_date) { create(:past_court_date, casa_case: casa_case) }

let(:volunteer) { create(:volunteer) }
let(:casa_case) { create(:casa_case, casa_org: volunteer.casa_org) }
let!(:case_assignment) { create(:case_assignment, volunteer: volunteer, casa_case: casa_case) }

let!(:reports) do
[10, 30, 60].map do |n|
report = CaseCourtReport.new(
volunteer_id: volunteer.id,
case_id: casa_case.id,
path_to_template: "app/documents/templates/default_report_template.docx"
)
casa_case.court_reports.attach(io: StringIO.new(report.generate_to_string), filename: "report#{n}.docx")
attached_report = casa_case.latest_court_report
attached_report.created_at = n.days.ago

attached_report.save!
attached_report
end
end

describe "#associated_reports" do
subject(:associated_reports) { past_court_date.associated_reports }

context "without other court dates" do
it { is_expected.to eq reports }
end

context "with a previous court date" do
let!(:other_past_court_date) { create(:past_court_date, casa_case: casa_case, date: 40.days.ago) }

it { is_expected.to eq [reports[0], reports[1]] }
end
end

describe "#latest_associated_report" do
subject(:latest_associated_report) { past_court_date.latest_associated_report }

it { is_expected.to eq past_court_date.associated_reports.order(:created_at).last }
end
end

describe "#additional_info?" do
subject(:additional_info?) { past_court_date.additional_info? }
Expand Down

0 comments on commit 6227bcc

Please sign in to comment.