Skip to content

Commit 7980077

Browse files
authoredOct 17, 2023
CDPT-1049 Fix drag through calculations (#697)
1 parent 75b9cdf commit 7980077

File tree

5 files changed

+59
-27
lines changed

5 files changed

+59
-27
lines changed
 

‎app/services/calculators/multiples/multiple_offenses_calculator.rb

+6-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ def spent_date_for(proceeding)
5555
proceeding, spent_date, other_conviction_date, other_spent_date
5656
)
5757

58-
next if conviction_date > other_conviction_date
58+
# indefinite spent dates are only expected with a relevant order
59+
next if other_spent_date == ResultsVariant::INDEFINITE
60+
61+
# Drag through for "never spent" convictions only applies to previous convictions
62+
next if other_spent_date == ResultsVariant::NEVER_SPENT && conviction_date > other_conviction_date
5963

6064
# This comparison determines wether the relevant order spent date is the longest
6165
# within the same conviction and also when compared to another conviction spent date.
@@ -79,7 +83,7 @@ def all_spent?
7983
private
8084

8185
def within_other_conviction_date_and_spent_date?(proceeding, spent_date, other_conviction_date, other_spent_date)
82-
# We should first check wether the proceeding spent date has been affected
86+
# We should first check whether the proceeding spent date has been affected
8387
# by previous comparisons, if so, we should use the value assigned to _spent_date_
8488
# otherwise we continue to compare spent dates with _spent_date_without_relevant_orders_
8589

‎app/value_objects/conviction_type.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def initialize(raw_value, params = {})
8484
ADULT_RESTRAINING_ORDER = new(:adult_restraining_order, parent: ADULT_COMMUNITY_REPARATION, relevant_order: true, drag_through: true, calculator_class: Calculators::AdditionCalculator::PlusZeroMonths),
8585
ADULT_SERIOUS_CRIME_PREVENTION = new(:adult_serious_crime_prevention, parent: ADULT_COMMUNITY_REPARATION, relevant_order: true, drag_through: true, calculator_class: Calculators::AdditionCalculator::PlusZeroMonths),
8686
ADULT_SEXUAL_HARM_PREVENTION_ORDER = new(:adult_sexual_harm_prevention_order, parent: ADULT_COMMUNITY_REPARATION, relevant_order: true, drag_through: true, calculator_class: Calculators::AdditionCalculator::PlusZeroMonths),
87-
ADULT_OTHER_REQUIREMENT_ORDER = new(:adult_other_requirement_order, parent: ADULT_COMMUNITY_REPARATION, relevant_order: true, calculator_class: Calculators::AdditionCalculator::PlusTwelveMonths),
87+
ADULT_OTHER_REQUIREMENT_ORDER = new(:adult_other_requirement_order, parent: ADULT_COMMUNITY_REPARATION, relevant_order: true, drag_through: true, calculator_class: Calculators::AdditionCalculator::PlusTwelveMonths),
8888

8989
ADULT_BIND_OVER = new(:adult_bind_over, parent: ADULT_DISCHARGE, relevant_order: true, calculator_class: Calculators::AdditionCalculator::PlusZeroMonths),
9090
ADULT_ABSOLUTE_DISCHARGE = new(:adult_absolute_discharge, parent: ADULT_DISCHARGE, skip_length: true, calculator_class: Calculators::ImmediatelyCalculator),

‎spec/services/calculators/multiples/multiple_offenses_calculator_spec.rb

+51-22
Original file line numberDiff line numberDiff line change
@@ -211,29 +211,58 @@
211211

212212
context "when all sentences are dates" do
213213
context "and there is overlapping of rehabilitation periods" do
214-
let(:conviction_1) do
215-
instance_double(
216-
Calculators::Multiples::Proceedings,
217-
conviction?: true,
218-
conviction_date: Date.new(2020, 1, 1),
219-
spent_date: Date.new(2022, 1, 1),
220-
spent_date_without_relevant_orders: Date.new(2022, 1, 1),
221-
)
222-
end
223-
224-
let(:conviction_2) do
225-
instance_double(
226-
Calculators::Multiples::Proceedings,
227-
conviction?: true,
228-
conviction_date: Date.new(2021, 1, 1),
229-
spent_date: Date.new(2025, 1, 1),
230-
spent_date_without_relevant_orders: Date.new(2025, 1, 1),
231-
)
214+
context "when 2nd sentence causes drag through" do
215+
let(:conviction_1) do
216+
instance_double(
217+
Calculators::Multiples::Proceedings,
218+
conviction?: true,
219+
conviction_date: Date.new(2020, 1, 1),
220+
spent_date: Date.new(2022, 1, 1),
221+
spent_date_without_relevant_orders: Date.new(2022, 1, 1),
222+
)
223+
end
224+
225+
let(:conviction_2) do
226+
instance_double(
227+
Calculators::Multiples::Proceedings,
228+
conviction?: true,
229+
conviction_date: Date.new(2021, 1, 1),
230+
spent_date: Date.new(2025, 1, 1),
231+
spent_date_without_relevant_orders: Date.new(2025, 1, 1),
232+
)
233+
end
234+
235+
it "returns the spent date for the matching check group" do
236+
expect(calculator.spent_date_for(conviction_1)).to eq(Date.new(2025, 1, 1))
237+
expect(calculator.spent_date_for(conviction_2)).to eq(Date.new(2025, 1, 1))
238+
end
232239
end
233240

234-
it "returns the spent date for the matching check group" do
235-
expect(calculator.spent_date_for(conviction_1)).to eq(Date.new(2025, 1, 1))
236-
expect(calculator.spent_date_for(conviction_2)).to eq(Date.new(2025, 1, 1))
241+
context "when 1st sentence causes drag through" do
242+
let(:conviction_1) do
243+
instance_double(
244+
Calculators::Multiples::Proceedings,
245+
conviction?: true,
246+
conviction_date: Date.new(2019, 4, 23),
247+
spent_date: Date.new(2030, 4, 22),
248+
spent_date_without_relevant_orders: Date.new(2030, 4, 22),
249+
)
250+
end
251+
252+
let(:conviction_2) do
253+
instance_double(
254+
Calculators::Multiples::Proceedings,
255+
conviction?: true,
256+
conviction_date: Date.new(2023, 9, 23),
257+
spent_date: Date.new(2026, 3, 22),
258+
spent_date_without_relevant_orders: Date.new(2026, 3, 22),
259+
)
260+
end
261+
262+
it "returns the spent date for the matching check group" do
263+
expect(calculator.spent_date_for(conviction_1)).to eq(Date.new(2030, 4, 22))
264+
expect(calculator.spent_date_for(conviction_2)).to eq(Date.new(2030, 4, 22))
265+
end
237266
end
238267
end
239268

@@ -352,7 +381,7 @@
352381
let(:spent_date_2) { ResultsVariant::INDEFINITE }
353382

354383
it "returns the spent date for the matching check group" do
355-
expect(calculator.spent_date_for(conviction_1)).to eq(ResultsVariant::INDEFINITE)
384+
expect(calculator.spent_date_for(conviction_1)).to eq(Date.new(2023, 1, 1))
356385
expect(calculator.spent_date_for(conviction_2)).to eq(ResultsVariant::INDEFINITE)
357386
end
358387
end

‎spec/spec_helper.rb

-1
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,4 @@
2222
end
2323

2424
config.shared_context_metadata_behavior = :apply_to_host_groups
25-
config.profile_examples = true
2625
end

‎spec/value_objects/conviction_type_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@
430430

431431
it { expect(conviction_type.skip_length?).to eq(false) }
432432
it { expect(conviction_type.relevant_order?).to eq(true) }
433-
it { expect(conviction_type.drag_through?).to eq(false) }
433+
it { expect(conviction_type.drag_through?).to eq(true) }
434434
it { expect(conviction_type.calculator_class).to eq(Calculators::AdditionCalculator::PlusTwelveMonths) }
435435
end
436436

0 commit comments

Comments
 (0)
Failed to load comments.