From bef11da0710b875bf1e6ad8563c5bdcbcec46800 Mon Sep 17 00:00:00 2001 From: Rhian Moraes Date: Mon, 7 Jun 2021 09:26:06 -0300 Subject: [PATCH 1/3] Rename past_court_date.rb (spec) to past_court_date_spec.rb --- spec/models/{past_court_date.rb => past_court_date_spec.rb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename spec/models/{past_court_date.rb => past_court_date_spec.rb} (100%) diff --git a/spec/models/past_court_date.rb b/spec/models/past_court_date_spec.rb similarity index 100% rename from spec/models/past_court_date.rb rename to spec/models/past_court_date_spec.rb From 9c4e2de127cad9d6a04f8ae17a0706f569f7d90e Mon Sep 17 00:00:00 2001 From: Rhian Moraes Date: Mon, 7 Jun 2021 11:07:46 -0300 Subject: [PATCH 2/3] Implement pending specs for past court date model --- spec/models/past_court_date_spec.rb | 45 +++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/spec/models/past_court_date_spec.rb b/spec/models/past_court_date_spec.rb index 1d9d415879..057558a604 100644 --- a/spec/models/past_court_date_spec.rb +++ b/spec/models/past_court_date_spec.rb @@ -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? } From 5a5012a0ec0f7bb12c4da3a037388b0c81268aef Mon Sep 17 00:00:00 2001 From: Rhian Moraes Date: Mon, 7 Jun 2021 11:15:59 -0300 Subject: [PATCH 3/3] Replace slash-separated template path in past court dates in favor of Rails.root.join --- app/models/past_court_date.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/past_court_date.rb b/app/models/past_court_date.rb index 6994d7fde0..01e9184bc6 100644 --- a/app/models/past_court_date.rb +++ b/app/models/past_court_date.rb @@ -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