Skip to content

Commit 55aeb56

Browse files
authored
Merge pull request #6444 from amuta/am-exclude-from-court-report-issue-6429
Am exclude from court report issue 6429
2 parents c9a82b3 + be9d871 commit 55aeb56

File tree

10 files changed

+99
-45
lines changed

10 files changed

+99
-45
lines changed

app/controllers/contact_topics_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,6 @@ def set_contact_topic
5656

5757
# Only allow a list of trusted parameters through.
5858
def contact_topic_params
59-
params.require(:contact_topic).permit(:casa_org_id, :question, :details, :active)
59+
params.require(:contact_topic).permit(:casa_org_id, :question, :details, :active, :exclude_from_court_report)
6060
end
6161
end

app/models/case_court_report_context.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ def org_address(path_to_template)
108108
def court_topics
109109
topics = ContactTopic
110110
.joins(contact_topic_answers: {case_contact: [:casa_case, :contact_types]}).distinct
111+
.where(contact_topics: {exclude_from_court_report: false})
111112
.where("casa_cases.id": @casa_case.id)
112113
.where("case_contacts.occurred_at": @date_range)
113114
.order(:occurred_at, :value)

app/models/contact_topic.rb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,15 @@ def default_contact_topics
4242
#
4343
# Table name: contact_topics
4444
#
45-
# id :bigint not null, primary key
46-
# active :boolean default(TRUE), not null
47-
# details :text
48-
# question :string
49-
# soft_delete :boolean default(FALSE), not null
50-
# created_at :datetime not null
51-
# updated_at :datetime not null
52-
# casa_org_id :bigint not null
45+
# id :bigint not null, primary key
46+
# active :boolean default(TRUE), not null
47+
# details :text
48+
# exclude_from_court_report :boolean default(FALSE), not null
49+
# question :string
50+
# soft_delete :boolean default(FALSE), not null
51+
# created_at :datetime not null
52+
# updated_at :datetime not null
53+
# casa_org_id :bigint not null
5354
#
5455
# Foreign Keys
5556
#

app/models/user.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def no_attempt_for_two_weeks
121121
if volunteer.supervisor.active? &&
122122
volunteer.case_assignments.any? { |assignment| assignment.active? } &&
123123
(volunteer.case_contacts.none? ||
124-
volunteer.case_contacts.maximum(:created_at) < (14.days.ago))
124+
volunteer.case_contacts.maximum(:created_at) < 14.days.ago)
125125

126126
no_attempt_count += 1
127127
end

app/views/contact_topics/_form.html.erb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
<%= form.check_box :active, class: 'form-check-input' %>
3030
<%= form.label :active, "Active?", class: 'form-check-label' %>
3131
</div>
32+
<div class="form-check checkbox-style mb-20">
33+
<%= form.check_box :exclude_from_court_report, class: 'form-check-input' %>
34+
<%= form.label :exclude_from_court_report, "Exclude from Court Report?", class: 'form-check-label' %>
35+
</div>
3236
<div class="actions mb-10">
3337
<%= button_tag(type: "submit", class: "btn-sm main-btn primary-btn btn-hover") do %>
3438
<i class="lni lni-checkmark-circle mr-5"></i> Submit
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddExcludeFromCourtReportToContactTopics < ActiveRecord::Migration[7.2]
2+
def change
3+
add_column :contact_topics, :exclude_from_court_report, :boolean, default: false, null: false
4+
end
5+
end

db/schema.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[7.2].define(version: 2025_05_28_092341) do
13+
ActiveRecord::Schema[7.2].define(version: 2025_07_02_142004) do
1414
# These are extensions that must be enabled in order to support this database
1515
enable_extension "plpgsql"
1616

@@ -270,6 +270,7 @@
270270
t.string "question"
271271
t.datetime "created_at", null: false
272272
t.datetime "updated_at", null: false
273+
t.boolean "exclude_from_court_report", default: false, null: false
273274
end
274275

275276
create_table "contact_type_groups", force: :cascade do |t|

lib/tasks/no_contact_made_reminder.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def get_contact_types_in_past_2_weeks(volunteer, contact_made)
4040
def valid_past_reminders(volunteer)
4141
reminder = UserReminderTime.find_by(user_id: volunteer.id)
4242

43-
if reminder&.case_contact_types && reminder.case_contact_types.today?
43+
if reminder&.case_contact_types&.today?
4444
return false
4545
end
4646

spec/models/case_court_report_context_spec.rb

Lines changed: 56 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -193,23 +193,9 @@
193193
])
194194
end
195195
end
196-
# let(:contacts) { create_list(:case_contact, 4, casa_case: casa_case, occurred_at: 1.month.ago) }
197196

198197
context "when given data" do
199-
# Add some values that should get filtered out
200198
before do
201-
contact_one = create(:case_contact, casa_case: casa_case, medium_type: "in-person", occurred_at: 1.day.ago)
202-
create_list(:contact_topic_answer, 2, case_contact: contact_one, contact_topic: topics[0], value: "Not included")
203-
204-
contact_two = create(:case_contact, casa_case: casa_case, medium_type: "in-person", occurred_at: 50.day.ago)
205-
create_list(:contact_topic_answer, 2, case_contact: contact_two, contact_topic: topics[0], value: "Not included")
206-
207-
other_case = create(:casa_case, casa_org: org)
208-
contact_three = create(:case_contact, casa_case: other_case, medium_type: "in-person", occurred_at: 50.day.ago)
209-
create_list(:contact_topic_answer, 2, case_contact: contact_three, contact_topic: topics[0], value: "Not included")
210-
end
211-
212-
it "generates correctly shaped data" do
213199
# Contact 1 Answers
214200
create(:contact_topic_answer, case_contact: contacts[0], contact_topic: topics[0], value: "Answer 1")
215201
create(:contact_topic_answer, case_contact: contacts[0], contact_topic: topics[1], value: "Answer 2")
@@ -222,27 +208,64 @@
222208
create(:contact_topic_answer, case_contact: contacts[2], contact_topic: topics[1], value: "Answer 5")
223209
create(:contact_topic_answer, case_contact: contacts[2], contact_topic: topics[2], value: "")
224210

225-
# Contact 4 Answers
226-
# No Answers
227-
228-
expected_topics = {
229-
"Question 1" => {topic: "Question 1", details: "Details 1", answers: [
230-
{date: "12/02/20", medium: "Type A1, Type B1", value: "Answer 1"},
231-
{date: "12/03/20", medium: "Type A2, Type B2", value: "Answer 3"}
232-
]},
233-
"Question 2" => {topic: "Question 2", details: "Details 2", answers: [
234-
{date: "12/02/20", medium: "Type A1, Type B1", value: "Answer 2"},
235-
{date: "12/04/20", medium: "Type A3, Type B3", value: "Answer 5"}
236-
]},
237-
"Question 3" => {topic: "Question 3", details: "Details 3", answers: [
238-
{date: "12/03/20", medium: "Type A2, Type B2", value: "No Answer Provided"},
239-
{date: "12/04/20", medium: "Type A3, Type B3", value: "No Answer Provided"}
240-
]}
241-
}
211+
# Contacts that will be filtered
212+
one_day_ago_contact = create(:case_contact, casa_case: casa_case, medium_type: "in-person", occurred_at: 1.day.ago)
213+
create_list(:contact_topic_answer, 2, case_contact: one_day_ago_contact, contact_topic: topics[0], value: "Answer From One Day Ago")
242214

243-
court_report_context = build(:case_court_report_context, start_date: 45.day.ago.to_s, end_date: 5.day.ago.to_s, casa_case: casa_case)
215+
one_year_ago_contact = create(:case_contact, casa_case: casa_case, medium_type: "in-person", occurred_at: 1.year.ago)
216+
create_list(:contact_topic_answer, 2, case_contact: one_year_ago_contact, contact_topic: topics[0], value: "Answer From One Year Ago")
217+
218+
other_case = create(:casa_case, casa_org: org)
219+
other_case_contact = create(:case_contact, casa_case: other_case, medium_type: "in-person", occurred_at: 1.month.ago)
220+
create_list(:contact_topic_answer, 2, case_contact: other_case_contact, contact_topic: topics[0], value: "Answer From Another Case")
221+
end
222+
223+
it "returns a hash of topics with the correct shape" do
224+
court_topics = build(:case_court_report_context, casa_case: casa_case).court_topics
225+
226+
expect(court_topics).to be_a(Hash)
227+
228+
expect(court_topics.keys).to all(a_kind_of(String))
229+
expect(court_topics.values).to all(
230+
a_hash_including(
231+
topic: a_kind_of(String),
232+
details: a_kind_of(String),
233+
answers: all(
234+
a_hash_including(
235+
date: a_string_matching(/\d{2}\/\d{2}\/\d{2}/),
236+
medium: a_kind_of(String),
237+
value: a_kind_of(String)
238+
)
239+
)
240+
)
241+
)
242+
end
243+
244+
it "returns topics related to the case" do
245+
court_topics = build(:case_court_report_context, casa_case: casa_case).court_topics
246+
247+
expect(court_topics.keys).to match_array(["Question 1", "Question 2", "Question 3"])
248+
expect(court_topics["Question 1"][:answers].map { |a| a[:value] }).to match_array(
249+
["Answer From One Year Ago", "Answer 1", "Answer 3", "Answer From One Day Ago"]
250+
)
251+
expect(court_topics["Question 2"][:answers].map { |a| a[:value] }).to match_array(["Answer 2", "Answer 5"])
252+
expect(court_topics["Question 3"][:answers].map { |a| a[:value] }).to match_array(["No Answer Provided", "No Answer Provided"])
253+
end
254+
255+
it "filters by date range" do
256+
court_topics = build(:case_court_report_context, start_date: 45.day.ago.to_s, end_date: 5.day.ago.to_s, casa_case: casa_case).court_topics
257+
258+
expect(court_topics.keys).to match_array(["Question 1", "Question 2", "Question 3"])
259+
expect(court_topics["Question 1"][:answers].map { |a| a[:value] }).to match_array(["Answer 1", "Answer 3"])
260+
end
261+
262+
it "filters answers from topics set be excluded from court report" do
263+
topics[0].update(exclude_from_court_report: true)
264+
265+
court_topics = build(:case_court_report_context, casa_case: casa_case).court_topics
244266

245-
expect(court_report_context.court_topics).to eq(expected_topics)
267+
expect(court_topics.keys).not_to include("Question 1")
268+
expect(court_topics.keys).to include("Question 2", "Question 3")
246269
end
247270
end
248271

spec/requests/contact_topics_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,17 @@
5353
post contact_topics_url, params: {contact_topic: attributes}
5454
expect(response).to redirect_to(edit_casa_org_path(casa_org))
5555
end
56+
57+
it "can set exclude_from_court_report attribute" do
58+
attributes[:exclude_from_court_report] = true
59+
60+
expect do
61+
post contact_topics_url, params: {contact_topic: attributes}
62+
end.to change(ContactTopic, :count).by(1)
63+
64+
topic = ContactTopic.last
65+
expect(topic.exclude_from_court_report).to be true
66+
end
5667
end
5768

5869
context "with invalid parameters" do
@@ -107,6 +118,14 @@
107118
patch contact_topic_url(contact_topic), params: {contact_topic: new_attributes}
108119
expect(response).to redirect_to(edit_casa_org_path(casa_org))
109120
end
121+
122+
it "can change exclude_from_court_report" do
123+
new_attributes = {exclude_from_court_report: true}
124+
125+
expect {
126+
patch contact_topic_url(contact_topic), params: {contact_topic: new_attributes}
127+
}.to change { contact_topic.reload.exclude_from_court_report }.from(false).to(true)
128+
end
110129
end
111130

112131
context "with invalid parameters" do

0 commit comments

Comments
 (0)