-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10201 from DFE-Digital/426-withdrawal-reasons-mig…
…rations 426 Part 1 New withdrawal reasons, migrations and tables
- Loading branch information
Showing
9 changed files
with
191 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
class WithdrawalReason < ApplicationRecord | ||
belongs_to :application_choice | ||
validates :reason, presence: true | ||
|
||
PERSONAL_CIRCUMSTANCES_KEY = 'personal-circumstances-have-changed'.freeze | ||
CONFIG_PATH = 'config/candidate_withdrawal_reasons.yml'.freeze | ||
|
||
enum :status, { | ||
draft: 'draft', | ||
published: 'published', | ||
} | ||
|
||
def publish! | ||
update!(status: 'published') | ||
end | ||
|
||
def self.selectable_reasons | ||
YAML.load_file(CONFIG_PATH).fetch('candidate-withdrawal-reasons') | ||
end | ||
|
||
def self.find_reason_options(reason = '') | ||
if reason.empty? | ||
selectable_reasons | ||
else | ||
selectable_reasons.dig(*reason.split('.')) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
candidate-withdrawal-reasons: | ||
applying-to-another-provider: | ||
accepted-another-offer: {} | ||
seen-a-course-that-suits-me-better: {} | ||
provider-has-not-replied-to-me: {} | ||
location-is-too-far-away: {} | ||
personal-circumstances-have-changed: | ||
concerns-about-cost-of-doing-course: {} | ||
concerns-about-having-enough-time-to-train: {} | ||
concerns-about-training-with-a-disability-or-health-condition: {} | ||
other: {} | ||
course-no-longer-available: {} | ||
other: {} | ||
change-or-update-application-with-this-provider: | ||
update-my-application-correct-an-error-or-add-information: {} | ||
change-study-pattern: {} | ||
apply-for-a-different-subject-with-the-same-provider: {} | ||
other: {} | ||
apply-in-the-future: | ||
personal-circumstances-have-changed: | ||
concerns-about-cost-of-doing-course: {} | ||
concerns-about-having-enough-time-to-train: {} | ||
concerns-about-training-with-a-disability-or-health-condition: {} | ||
other: {} | ||
gain-more-experience: {} | ||
improve-qualifications: {} | ||
other: {} | ||
do-not-want-to-train-anymore: | ||
personal-circumstances-have-changed: | ||
concerns-about-cost-of-doing-course: {} | ||
concerns-about-having-enough-time-to-train: {} | ||
concerns-about-training-with-a-disability-or-health-condition: {} | ||
other: {} | ||
another-career-path-or-accepted-a-job-offer: {} | ||
other: {} | ||
other: {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class CreateWithdrawalReasons < ActiveRecord::Migration[8.0] | ||
def change | ||
create_table :withdrawal_reasons do |t| | ||
t.string :reason, index: true | ||
t.text :comment | ||
t.string :status, default: 'draft' | ||
t.references :application_choice, null: false, foreign_key: { on_delete: :cascade } | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe WithdrawalReason do | ||
describe 'validations' do | ||
it { is_expected.to validate_presence_of(:reason) } | ||
end | ||
|
||
describe 'associations' do | ||
it { is_expected.to belong_to(:application_choice) } | ||
end | ||
|
||
describe '#selectable_reasons' do | ||
it 'returns a hash of selectable reasons' do | ||
expect(described_class.selectable_reasons).to eq(selectable_reasons) | ||
end | ||
end | ||
|
||
describe '#find_reason_options' do | ||
context 'without a reason_id' do | ||
it 'returns all selectable reasons' do | ||
expect(described_class.find_reason_options).to eq(selectable_reasons) | ||
end | ||
end | ||
|
||
context 'with primary reason id' do | ||
it 'returns all the reasons under that id' do | ||
expect( | ||
described_class.find_reason_options('applying-to-another-provider'), | ||
).to eq(selectable_reasons['applying-to-another-provider']) | ||
end | ||
end | ||
|
||
context 'with nested reason id' do | ||
it 'returns all secondary reasons when there are any' do | ||
expect( | ||
described_class.find_reason_options('applying-to-another-provider.personal-circumstances-have-changed'), | ||
).to eq({ 'concerns-about-cost-of-doing-course' => {}, | ||
'concerns-about-having-enough-time-to-train' => {}, | ||
'concerns-about-training-with-a-disability-or-health-condition' => {}, | ||
'other' => {} }) | ||
end | ||
|
||
it 'returns an empty hash when there are none' do | ||
expect( | ||
described_class.find_reason_options('applying-to-another-provider.location-is-too-far-away'), | ||
).to eq({}) | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def selectable_reasons | ||
{ 'applying-to-another-provider' => | ||
{ 'accepted-another-offer' => {}, | ||
'seen-a-course-that-suits-me-better' => {}, | ||
'provider-has-not-replied-to-me' => {}, | ||
'location-is-too-far-away' => {}, | ||
'personal-circumstances-have-changed' => | ||
{ 'concerns-about-cost-of-doing-course' => {}, | ||
'concerns-about-having-enough-time-to-train' => {}, | ||
'concerns-about-training-with-a-disability-or-health-condition' => {}, | ||
'other' => {} }, | ||
'course-no-longer-available' => {}, | ||
'other' => {} }, | ||
'change-or-update-application-with-this-provider' => | ||
{ 'update-my-application-correct-an-error-or-add-information' => {}, | ||
'change-study-pattern' => {}, | ||
'apply-for-a-different-subject-with-the-same-provider' => {}, | ||
'other' => {} }, | ||
'apply-in-the-future' => | ||
{ 'personal-circumstances-have-changed' => | ||
{ 'concerns-about-cost-of-doing-course' => {}, | ||
'concerns-about-having-enough-time-to-train' => {}, | ||
'concerns-about-training-with-a-disability-or-health-condition' => {}, | ||
'other' => {} }, | ||
'gain-more-experience' => {}, | ||
'improve-qualifications' => {}, | ||
'other' => {} }, | ||
'do-not-want-to-train-anymore' => | ||
{ 'personal-circumstances-have-changed' => | ||
{ 'concerns-about-cost-of-doing-course' => {}, | ||
'concerns-about-having-enough-time-to-train' => {}, | ||
'concerns-about-training-with-a-disability-or-health-condition' => {}, | ||
'other' => {} }, | ||
'another-career-path-or-accepted-a-job-offer' => {}, | ||
'other' => {} }, | ||
'other' => {} } | ||
end | ||
end |