Skip to content

Commit

Permalink
Merge pull request #4501 from DFE-Digital/2280-change-coursetype-to-d…
Browse files Browse the repository at this point in the history
…egreetype

[2280] Update usages from `course_type` to `degree_type`
  • Loading branch information
avinhurry authored Sep 11, 2024
2 parents 903c344 + 037cb73 commit 01d13e0
Show file tree
Hide file tree
Showing 16 changed files with 65 additions and 65 deletions.
6 changes: 3 additions & 3 deletions app/controllers/find/search/visa_status_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def create
private

def next_step_path
if course_type_answer_determiner.show_exit_page?
if degree_type_answer_determiner.show_exit_page?
find_no_degree_and_requires_visa_sponsorship_path(filter_params[:find_visa_status_form])
else
find_results_path(
Expand All @@ -40,8 +40,8 @@ def next_step_path
end
end

def course_type_answer_determiner
@course_type_answer_determiner ||= CourseTypeAnswerDeterminer.new(
def degree_type_answer_determiner
@degree_type_answer_determiner ||= DegreeTypeAnswerDeterminer.new(
university_degree_status: form_params[:university_degree_status],
age_group: form_params[:age_group],
visa_status: form_params[:visa_status]
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/publish/courses/outcome_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def handle_qualification_update
if undergraduate_to_other_qualification?
@course.enrichments.find_or_initialize_draft.update(course_length: nil, salary_details: nil)
@course.update(
course_type: 'postgraduate',
degree_type: 'postgraduate',
a_level_subject_requirements: [],
accept_pending_a_level: nil,
accept_a_level_equivalency: nil,
Expand Down
8 changes: 4 additions & 4 deletions app/models/course.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ class Course < ApplicationRecord
open: 1
}, prefix: :application_status

enum :course_type, {
enum :degree_type, {
postgraduate: 'postgraduate',
undergraduate: 'undergraduate'
}, suffix: :course_type
}, suffix: :degree_type

enum :funding, {
not_set: 'not_set',
Expand Down Expand Up @@ -332,8 +332,8 @@ def new_draft_attributes
)
}

scope :with_course_type, lambda { |course_type|
if course_type == :undergraduate
scope :with_degree_type, lambda { |degree_type|
if degree_type == :undergraduate
where(program_type: Course.program_types[:teacher_degree_apprenticeship])
else
where.not(program_type: Course.program_types[:teacher_degree_apprenticeship])
Expand Down
2 changes: 1 addition & 1 deletion app/services/api_course_search_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def course_order(outer_scope)
outer_scope.order('course.created_at': :asc)
end

def filter_by_course_type(scope)
def filter_by_degree_type(scope)
scope # we want to return all course types in the API
end
end
16 changes: 8 additions & 8 deletions app/services/course_search_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ def initialize(
filter:,
sort: nil,
course_scope: Course,
course_type_answer_determiner: Find::CourseTypeAnswerDeterminer
degree_type_answer_determiner: Find::DegreeTypeAnswerDeterminer
)
@filter = filter || {}
@course_scope = course_scope
@sort = sort
@course_type_answer_determiner = course_type_answer_determiner.new(
@degree_type_answer_determiner = degree_type_answer_determiner.new(
university_degree_status: @filter['university_degree_status'],
age_group: @filter['age_group'],
visa_status: @filter['visa_status']
Expand All @@ -21,7 +21,7 @@ def initialize(

def call
scope = course_scope
scope = filter_by_course_type(scope)
scope = filter_by_degree_type(scope)
scope = scope.with_salary if funding_filter_salary?
scope = scope.with_qualifications(qualifications) if qualifications.any?
scope = scope.application_status_open if applications_open?
Expand Down Expand Up @@ -91,12 +91,12 @@ def course_order(outer_scope)
outer_scope
end

def filter_by_course_type(scope)
scope.with_course_type(course_type)
def filter_by_degree_type(scope)
scope.with_degree_type(degree_type)
end

def course_type
return :undergraduate if @course_type_answer_determiner.show_undergraduate_courses?
def degree_type
return :undergraduate if @degree_type_answer_determiner.show_undergraduate_courses?

:postgraduate
end
Expand Down Expand Up @@ -222,7 +222,7 @@ def funding_filter_salary?
end

def qualifications
return [] if filter[:qualification].blank? || course_type == :undergraduate
return [] if filter[:qualification].blank? || degree_type == :undergraduate

filter[:qualification] = filter[:qualification].values if filter[:qualification].is_a?(Hash)
filter[:qualification] = filter[:qualification].split(',') if filter[:qualification].is_a?(String)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Find
class CourseTypeAnswerDeterminer
class DegreeTypeAnswerDeterminer
attr_reader :age_group, :visa_status, :university_degree_status

def initialize(age_group:, visa_status:, university_degree_status:)
Expand Down
4 changes: 2 additions & 2 deletions app/services/publish/courses/assign_tda_attributes_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def initialize(course)
def call
if FeatureService.enabled?(:db_backed_funding_type)
@course.assign_attributes(
course_type: 'undergraduate',
degree_type: 'undergraduate',
funding: 'apprenticeship',
study_mode: 'full_time',
program_type: 'teacher_degree_apprenticeship',
Expand All @@ -22,7 +22,7 @@ def call
)
else
@course.assign_attributes(
course_type: 'undergraduate',
degree_type: 'undergraduate',
funding_type: 'apprenticeship',
study_mode: 'full_time',
program_type: 'teacher_degree_apprenticeship',
Expand Down
2 changes: 1 addition & 1 deletion app/view_objects/find/result_filters/filters_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def qualification_params_nil?
end

def show_undergraduate_courses?
CourseTypeAnswerDeterminer.new(
DegreeTypeAnswerDeterminer.new(
age_group: params[:age_group],
university_degree_status: params[:university_degree_status],
visa_status: params[:visa_status]
Expand Down
2 changes: 1 addition & 1 deletion app/views/find/courses/_advice.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div id="section-advice-and-support">
<h2 class="govuk-heading-m" id="section-advice"><%= t(".heading") %></h2>
<span class="govuk-body">
<% if course.postgraduate_course_type? %>
<% if course.postgraduate_degree_type? %>
<%= t(
".postgraduate.body_html",
teacher_training_adviser_link: govuk_link_to(
Expand Down
32 changes: 16 additions & 16 deletions spec/features/publish/courses/editing_course_outcome_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
and_there_is_a_qts_course_i_want_to_edit
when_i_visit_the_course_outcome_page_in_the_next_cycle
and_i_choose_undergraduate_degree_with_qts
and_the_course_type_is_postgraduate
and_the_degree_type_is_postgraduate
and_i_submit
then_the_default_options_for_a_tda_course_should_be_applied
end
Expand All @@ -52,9 +52,9 @@
and_the_db_backed_funding_type_feature_flag_is_enabled
and_there_is_a_tda_course_i_want_to_edit
when_i_visit_the_course_outcome_page_in_the_next_cycle
and_the_course_type_is_undergraduate
and_the_degree_type_is_undergraduate
and_i_choose_qts
and_the_course_type_is_postgraduate
and_the_degree_type_is_postgraduate
and_the_back_link_points_to_the_outcome_page
and_i_choose_the_fee_paying
and_the_back_link_points_to_the_funding_type_page
Expand Down Expand Up @@ -82,9 +82,9 @@
and_the_db_backed_funding_type_feature_flag_is_enabled
and_there_is_a_tda_course_i_want_to_edit
when_i_visit_the_course_outcome_page_in_the_next_cycle
and_the_course_type_is_undergraduate
and_the_degree_type_is_undergraduate
and_i_choose_qts
and_the_course_type_is_postgraduate
and_the_degree_type_is_postgraduate
and_the_back_link_points_to_the_outcome_page
and_i_choose_salaried
and_the_back_link_points_to_the_funding_type_page
Expand All @@ -104,7 +104,7 @@
and_there_is_a_qts_course_i_want_to_edit
when_i_visit_the_course_outcome_page_in_the_next_cycle
and_i_choose_undergraduate_degree_with_qts
and_the_course_type_is_postgraduate
and_the_degree_type_is_postgraduate
and_i_submit
then_the_default_options_for_a_tda_course_should_be_applied
end
Expand All @@ -116,9 +116,9 @@
and_the_db_backed_funding_type_feature_flag_is_disabled
and_there_is_a_tda_course_i_want_to_edit
when_i_visit_the_course_outcome_page_in_the_next_cycle
and_the_course_type_is_undergraduate
and_the_degree_type_is_undergraduate
and_i_choose_qts
and_the_course_type_is_postgraduate
and_the_degree_type_is_postgraduate
and_the_back_link_points_to_the_outcome_page
and_i_choose_the_fee_paying
and_the_back_link_points_to_the_funding_type_page
Expand Down Expand Up @@ -146,9 +146,9 @@
and_the_db_backed_funding_type_feature_flag_is_disabled
and_there_is_a_tda_course_i_want_to_edit
when_i_visit_the_course_outcome_page_in_the_next_cycle
and_the_course_type_is_undergraduate
and_the_degree_type_is_undergraduate
and_i_choose_qts
and_the_course_type_is_postgraduate
and_the_degree_type_is_postgraduate
and_the_back_link_points_to_the_outcome_page
and_i_choose_salaried
and_the_back_link_points_to_the_funding_type_page
Expand Down Expand Up @@ -178,7 +178,7 @@ def and_there_is_a_qts_course_i_want_to_edit
end

def and_there_is_a_tda_course_i_want_to_edit
given_a_course_exists(:undergraduate_degree_with_qts, course_type: 'undergraduate')
given_a_course_exists(:undergraduate_degree_with_qts, degree_type: 'undergraduate')
end

def course_enrichment
Expand Down Expand Up @@ -285,17 +285,17 @@ def when_i_visit_the_course_outcome_page_in_the_next_cycle
)
end

def and_the_course_type_is_undergraduate
expect(course.undergraduate_course_type?).to be(true)
def and_the_degree_type_is_undergraduate
expect(course.undergraduate_degree_type?).to be(true)
end

def and_the_course_type_is_postgraduate
expect(course.reload.postgraduate_course_type?).to be(true)
def and_the_degree_type_is_postgraduate
expect(course.reload.postgraduate_degree_type?).to be(true)
end

def then_the_default_options_for_a_tda_course_should_be_applied
course.reload
expect(course.undergraduate_course_type?).to be(true)
expect(course.undergraduate_degree_type?).to be(true)
expect(course.full_time?).to be(true)
expect(course.funding_type == 'apprenticeship').to be(true)
expect(course.can_sponsor_skilled_worker_visa).to be false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
and_there_is_a_qts_course_i_want_to_edit
when_i_visit_the_course_outcome_page_in_the_next_cycle
and_i_choose_undergraduate_degree_with_qts
and_the_course_type_is_postgraduate
and_the_degree_type_is_postgraduate
and_i_submit
then_the_default_options_for_a_tda_course_should_be_applied
end
Expand All @@ -55,9 +55,9 @@
and_the_db_backed_funding_type_feature_flag_is_disabled
and_there_is_a_tda_course_i_want_to_edit
when_i_visit_the_course_outcome_page_in_the_next_cycle
and_the_course_type_is_undergraduate
and_the_degree_type_is_undergraduate
and_i_choose_qts
and_the_course_type_is_postgraduate
and_the_degree_type_is_postgraduate
and_the_back_link_points_to_the_outcome_page
and_i_choose_the_fee_paying
and_the_back_link_points_to_the_funding_type_page
Expand Down Expand Up @@ -85,9 +85,9 @@
and_the_db_backed_funding_type_feature_flag_is_disabled
and_there_is_a_tda_course_i_want_to_edit
when_i_visit_the_course_outcome_page_in_the_next_cycle
and_the_course_type_is_undergraduate
and_the_degree_type_is_undergraduate
and_i_choose_qts
and_the_course_type_is_postgraduate
and_the_degree_type_is_postgraduate
and_the_back_link_points_to_the_outcome_page
and_i_choose_salaried
and_the_back_link_points_to_the_funding_type_page
Expand Down Expand Up @@ -117,7 +117,7 @@ def and_there_is_a_qts_course_i_want_to_edit
end

def and_there_is_a_tda_course_i_want_to_edit
given_a_course_exists(:undergraduate_degree_with_qts, course_type: 'undergraduate')
given_a_course_exists(:undergraduate_degree_with_qts, degree_type: 'undergraduate')
end

def course_enrichment
Expand Down Expand Up @@ -224,17 +224,17 @@ def when_i_visit_the_course_outcome_page_in_the_next_cycle
)
end

def and_the_course_type_is_undergraduate
expect(course.undergraduate_course_type?).to be(true)
def and_the_degree_type_is_undergraduate
expect(course.undergraduate_degree_type?).to be(true)
end

def and_the_course_type_is_postgraduate
expect(course.reload.postgraduate_course_type?).to be(true)
def and_the_degree_type_is_postgraduate
expect(course.reload.postgraduate_degree_type?).to be(true)
end

def then_the_default_options_for_a_tda_course_should_be_applied
course.reload
expect(course.undergraduate_course_type?).to be(true)
expect(course.undergraduate_degree_type?).to be(true)
expect(course.full_time?).to be(true)
expect(course.funding_type == 'apprenticeship').to be(true)
expect(course.can_sponsor_skilled_worker_visa).to be false
Expand Down
24 changes: 12 additions & 12 deletions spec/models/course_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2901,47 +2901,47 @@
end
end

describe 'course_type enum' do
describe 'degree_type enum' do
subject(:course) { create(:course) }

context 'default' do
it 'sets the value as postgraduate' do
expect(course.course_type).to eq('postgraduate')
expect(course.degree_type).to eq('postgraduate')
end
end

context 'undergraduate course' do
it 'sets the value to undergraduate' do
course.undergraduate_course_type!
expect(course.reload.course_type).to eq('undergraduate')
course.undergraduate_degree_type!
expect(course.reload.degree_type).to eq('undergraduate')
end
end

context 'postgraduate course' do
it 'sets the value to postgraduate' do
course.postgraduate_course_type!
expect(course.reload.course_type).to eq('postgraduate')
course.postgraduate_degree_type!
expect(course.reload.degree_type).to eq('postgraduate')
end
end

context 'validation' do
it 'raises an error when setting an invalid course_type' do
expect { course.update!(course_type: 'invalid') }.to raise_error(ArgumentError)
it 'raises an error when setting an invalid degree_type' do
expect { course.update!(degree_type: 'invalid') }.to raise_error(ArgumentError)
end
end

context 'predicate methods' do
it 'returns true for postgraduate?' do
expect(course.postgraduate_course_type?).to be true
expect(course.postgraduate_degree_type?).to be true
end

it 'returns false for undergraduate?' do
expect(course.undergraduate_course_type?).to be false
expect(course.undergraduate_degree_type?).to be false
end

it 'returns true for undergraduate? after setting to undergraduate' do
course.undergraduate_course_type!
expect(course.undergraduate_course_type?).to be true
course.undergraduate_degree_type!
expect(course.undergraduate_degree_type?).to be true
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/services/course_search_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
).and_return(course_with_includes)

allow(course_with_includes).to receive(:where).and_return(outer_query_scope)
allow(scope).to receive(:with_course_type).and_return(scope)
allow(scope).to receive(:with_degree_type).and_return(scope)
end

describe 'when no scope is passed' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require 'rails_helper'

RSpec.describe Find::CourseTypeAnswerDeterminer do
RSpec.describe Find::DegreeTypeAnswerDeterminer do
describe '#show_undergraduate_courses?' do
context 'when the age group is not further education, no degree, and no visa sponsorship required' do
let(:params) do
Expand Down
Loading

0 comments on commit 01d13e0

Please sign in to comment.