Skip to content

Commit

Permalink
Always consider teaching qualification
Browse files Browse the repository at this point in the history
... when calculating the work history duration. We want to change this
behaviour for teachers and assessors so we're always using this
calculation from now on.
  • Loading branch information
thomasleese committed Dec 4, 2023
1 parent 5d22370 commit 86391ec
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ def load_years_and_months_count
@years_count, @months_count =
WorkHistoryDuration.for_application_form(
application_form,
consider_teaching_qualification: true,
).count_years_and_months
end

Expand Down
7 changes: 3 additions & 4 deletions app/forms/teacher_interface/qualification_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,9 @@ def institution_country_code
end

def create_work_history_duration
WorkHistoryDuration.for_application_form(
application_form,
consider_teaching_qualification: true,
).tap(&:count_months)
WorkHistoryDuration.for_application_form(application_form).tap(
&:count_months
)
end

def changed_work_history_duration?(old_duration, new_duration)
Expand Down
1 change: 0 additions & 1 deletion app/forms/teacher_interface/work_history_school_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ def country_code
def has_enough_work_history_for_submission?
WorkHistoryDuration.for_application_form(
application_form.reload,
consider_teaching_qualification: true,
).enough_for_submission?
end
end
Expand Down
1 change: 0 additions & 1 deletion app/lib/application_form_section_status_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ def work_history_status
enough_for_submission =
WorkHistoryDuration.for_application_form(
application_form,
consider_teaching_qualification: true,
).enough_for_submission?

enough_for_submission ? :completed : :in_progress
Expand Down
35 changes: 7 additions & 28 deletions app/lib/work_history_duration.rb
Original file line number Diff line number Diff line change
@@ -1,46 +1,28 @@
# frozen_string_literal: true

class WorkHistoryDuration
def initialize(
application_form:,
relation:,
consider_teaching_qualification: false
)
def initialize(application_form:, relation:)
@application_form = application_form
@relation =
relation.where.not(start_date: nil).where.not(hours_per_week: nil)
@consider_teaching_qualification = consider_teaching_qualification
end

def self.for_application_form(
application_form,
consider_teaching_qualification: false
)
def self.for_application_form(application_form)
WorkHistoryDuration.new(
application_form:,
relation: application_form.work_histories,
consider_teaching_qualification:,
)
end

def self.for_ids(
ids,
application_form:,
consider_teaching_qualification: false
)
def self.for_ids(ids, application_form:)
WorkHistoryDuration.new(
application_form:,
relation: application_form.work_histories.where(id: ids),
consider_teaching_qualification:,
)
end

def self.for_record(record, consider_teaching_qualification: false)
for_ids(
[record.id],
application_form: record.application_form,
consider_teaching_qualification:,
)
def self.for_record(record)
for_ids([record.id], application_form: record.application_form)
end

def count_months
Expand Down Expand Up @@ -77,7 +59,7 @@ def enough_to_skip_induction?
AVERAGE_WEEKS_PER_MONTH = 4.34
HOURS_PER_FULL_TIME_MONTH = 130.0

attr_reader :application_form, :relation, :consider_teaching_qualification
attr_reader :application_form, :relation

def work_histories
@work_histories ||=
Expand All @@ -89,10 +71,7 @@ def work_histories
end

def teaching_qualification
@teaching_qualification ||=
if consider_teaching_qualification
application_form.teaching_qualification
end
@teaching_qualification ||= application_form.teaching_qualification
end

def work_history_full_time_months(work_history)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,6 @@ def assessment_declined_reasons

def work_history_duration
@work_history_duration ||=
WorkHistoryDuration.for_application_form(
application_form,
consider_teaching_qualification: true,
)
WorkHistoryDuration.for_application_form(application_form)
end
end
104 changes: 26 additions & 78 deletions spec/lib/work_history_duration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
let(:application_form) { create(:application_form) }
let(:today) { Date.new(2021, 1, 15) }

shared_examples "month counter" do |consider_teaching_qualification|
shared_examples "month counter" do
subject(:count_months) do
travel_to(today) { work_history_duration.count_months }
end
Expand All @@ -32,7 +32,7 @@
)
end

it { is_expected.to eq(consider_teaching_qualification ? 6 : 12) }
it { is_expected.to eq(6) }
end

context "with a finished full time work history with extra hours" do
Expand All @@ -46,7 +46,7 @@
)
end

it { is_expected.to eq(consider_teaching_qualification ? 6 : 12) }
it { is_expected.to eq(6) }
end

context "with a finished part time work history" do
Expand All @@ -60,7 +60,7 @@
)
end

it { is_expected.to eq(consider_teaching_qualification ? 3 : 6) }
it { is_expected.to eq(3) }
end

context "with an ongoing full time work history" do
Expand All @@ -73,7 +73,7 @@
)
end

it { is_expected.to eq(consider_teaching_qualification ? 7 : 13) }
it { is_expected.to eq(7) }
end

context "with an ongoing part time work history" do
Expand All @@ -86,7 +86,7 @@
)
end

it { is_expected.to eq(consider_teaching_qualification ? 4 : 7) }
it { is_expected.to eq(4) }
end

context "with a full time and a part time work history" do
Expand All @@ -107,7 +107,7 @@
)
end

it { is_expected.to eq(consider_teaching_qualification ? 3 : 10) }
it { is_expected.to eq(3) }
end

context "with work history before the teaching qualification" do
Expand All @@ -121,80 +121,39 @@
)
end

it { is_expected.to eq(consider_teaching_qualification ? 0 : 12) }
it { is_expected.to eq(0) }
end
end

describe "#count_months" do
context "passing an application form" do
context "when not considering the teaching qualification" do
subject(:work_history_duration) do
described_class.for_application_form(application_form)
end

it_behaves_like "month counter", false
subject(:work_history_duration) do
described_class.for_application_form(application_form)
end

context "when considering the teaching qualification" do
subject(:work_history_duration) do
described_class.for_application_form(
application_form,
consider_teaching_qualification: true,
)
end

it_behaves_like "month counter", true
end
it_behaves_like "month counter"
end

context "passing a work history relation" do
context "when not considering the teaching qualification" do
subject(:work_history_duration) do
described_class.new(
application_form:,
relation: application_form.work_histories,
)
end

it_behaves_like "month counter", false
subject(:work_history_duration) do
described_class.new(
application_form:,
relation: application_form.work_histories,
)
end

context "when considering the teaching qualification" do
subject(:work_history_duration) do
described_class.new(
application_form:,
relation: application_form.work_histories,
consider_teaching_qualification: true,
)
end

it_behaves_like "month counter", true
end
it_behaves_like "month counter"
end

context "passing work history IDs" do
context "when not considering the teaching qualification" do
subject(:work_history_duration) do
described_class.for_ids(
application_form.work_histories.pluck(:id),
application_form:,
)
end

it_behaves_like "month counter", false
subject(:work_history_duration) do
described_class.for_ids(
application_form.work_histories.pluck(:id),
application_form:,
)
end

context "when considering the teaching qualification" do
subject(:work_history_duration) do
described_class.for_ids(
application_form.work_histories.pluck(:id),
application_form:,
consider_teaching_qualification: true,
)
end

it_behaves_like "month counter", true
end
it_behaves_like "month counter"
end

context "passing a work history record" do
Expand All @@ -216,22 +175,11 @@
)
end

subject(:count) { work_history_duration.count_months }
let(:work_history_duration) { described_class.for_record(work_history) }

context "when not considering the teaching qualification" do
let(:work_history_duration) { described_class.for_record(work_history) }
it { is_expected.to eq(12) }
end
subject(:count) { work_history_duration.count_months }

context "when considering the teaching qualification" do
let(:work_history_duration) do
described_class.for_record(
work_history,
consider_teaching_qualification: true,
)
end
it { is_expected.to eq(6) }
end
it { is_expected.to eq(6) }
end
end
end

0 comments on commit 86391ec

Please sign in to comment.