Skip to content

Commit

Permalink
Rename accredited_provider_id to accredited_provider_number
Browse files Browse the repository at this point in the history
  The AccreditedProvidersController still uses a param called
  `accredited_provdier_id`. It is unrelated to the
  accredited_provider_number
  • Loading branch information
inulty-dfe committed Nov 27, 2024
1 parent 45d6aa6 commit 843da5d
Show file tree
Hide file tree
Showing 15 changed files with 70 additions and 70 deletions.
4 changes: 2 additions & 2 deletions app/components/providers/provider_list/view.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

if @provider.accredited_provider?
component.with_row do |row|
row.with_key { "Accredited provider ID" }
row.with_value { value_provided?(@provider.accredited_provider_id.to_s) }
row.with_key { "Accredited provider number" }
row.with_value { value_provided?(@provider.accredited_provider_number.to_s) }
row.with_action(text: "Change", href: edit_support_recruitment_cycle_provider_path(@provider.recruitment_cycle_year, @provider), visually_hidden_text: "accredited provider id")
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/support/providers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def update_provider_params
:provider_type,
:ukprn,
:urn,
:accrediting_provider, :accredited_provider_id)
:accrediting_provider, :accredited_provider_number)
end

def create_provider_params
Expand Down
24 changes: 12 additions & 12 deletions app/forms/support/provider_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Support
class ProviderForm < BaseForm
FIELDS = %i[
accredited_provider
accredited_provider_id
accredited_provider_number

provider_code
provider_name
Expand All @@ -14,9 +14,9 @@ class ProviderForm < BaseForm
urn
].freeze

UNIVERSITY_ACCREDITED_PROVIDER_ID_FORMAT = /\A1\d{3}\z/
SCITT_ACCREDITED_PROVIDER_ID_FORMAT = /\A5\d{3}\z/
ACCREDITED_PROVIDER_ID_FORMAT = /\A[15]\d{3}\z/
UNIVERSITY_ACCREDITED_PROVIDER_NUMBER_FORMAT = /\A1\d{3}\z/
SCITT_ACCREDITED_PROVIDER_NUMBER_FORMAT = /\A5\d{3}\z/
ACCREDITED_PROVIDER_NUMBER_FORMAT = /\A[15]\d{3}\z/

attr_accessor(*FIELDS, :recruitment_cycle)

Expand All @@ -32,7 +32,7 @@ def initialize(identifier_model, recruitment_cycle:, params: {})
validate :provider_code_taken

validates :accredited_provider, presence: true
validate :validate_accredited_provider_id
validate :validate_accredited_provider_number

validates :ukprn, ukprn_format: { allow_blank: false }

Expand Down Expand Up @@ -77,21 +77,21 @@ def provider_type_school_is_an_invalid_accredited_provider
errors.add(:provider_type, :school_is_an_invalid_accredited_provider) if accredited_provider? && lead_school?
end

def validate_accredited_provider_id
def validate_accredited_provider_number
return unless accredited_provider?

if accredited_provider_id.blank?
errors.add(:accredited_provider_id, :blank)
if accredited_provider_number.blank?
errors.add(:accredited_provider_number, :blank)
else
regex = if university?
UNIVERSITY_ACCREDITED_PROVIDER_ID_FORMAT
UNIVERSITY_ACCREDITED_PROVIDER_NUMBER_FORMAT
elsif scitt?
SCITT_ACCREDITED_PROVIDER_ID_FORMAT
SCITT_ACCREDITED_PROVIDER_NUMBER_FORMAT
else
ACCREDITED_PROVIDER_ID_FORMAT
ACCREDITED_PROVIDER_NUMBER_FORMAT
end

errors.add(:accredited_provider_id, :invalid) unless regex.match?(accredited_provider_id)
errors.add(:accredited_provider_number, :invalid) unless regex.match?(accredited_provider_number)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def current_accredited_courses

validate :add_enrichment_errors

validates :accredited_provider_id, accredited_provider_id_format: { allow_blank: true }, on: :update, if: :accredited_provider?
validates :accredited_provider_number, accredited_provider_number_format: { allow_blank: true }, on: :update, if: :accredited_provider?

acts_as_mappable lat_column_name: :latitude, lng_column_name: :longitude

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class AccreditedProviderIdFormatValidator < ActiveModel::EachValidator
class AccreditedProviderNumberFormatValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
return if options[:allow_blank] && value.blank?

Expand Down
6 changes: 3 additions & 3 deletions app/views/support/providers/_list.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<tr class="govuk-table__row">
<th scope="col" class="govuk-table__header govuk-!-width-one-half">Provider name</th>
<th scope="col" class="govuk-table__header govuk-!-width-one-third">Provider code</th>
<th scope="col" class="govuk-table__header govuk-!-width-one-third">Accredited Provider Number</th>
<th scope="col" class="govuk-table__header govuk-!-width-one-third">Accredited provider number</th>
<th scope="col" class="govuk-table__header govuk-!-width-one-third">UKPRN</th>
</tr>
</thead>
Expand All @@ -27,8 +27,8 @@
<td class="govuk-table__cell">
<span class="govuk-!-display-block govuk-!-margin-bottom-1">
<% if provider.accrediting_provider_before_type_cast == "Y" %>
<% if provider.accredited_provider_id.present? %>
<%= govuk_tag(text: provider.accredited_provider_id, colour: "green") %>
<% if provider.accredited_provider_number.present? %>
<%= govuk_tag(text: provider.accredited_provider_number, colour: "green") %>
<% else %>
<%= govuk_tag(text: "Fill me in", colour: "yellow") %>
<% end %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/support/providers/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@

<%= f.govuk_radio_buttons_fieldset :accrediting_provider, legend: { text: "Is the organisation an accredited provider?", size: "s" } do %>
<%= f.govuk_radio_button :accrediting_provider, :accredited_provider, label: { text: "Yes", size: "s" } do %>
<%= f.govuk_text_field :accredited_provider_id,
label: { text: "Accredited provider ID" },
<%= f.govuk_text_field :accredited_provider_number,
label: { text: "Accredited provider number" },
width: 10 %>
<% end %>
<%= f.govuk_radio_button :accrediting_provider, :not_an_accredited_provider, label: { text: "No", size: "s" } %>
Expand Down
6 changes: 3 additions & 3 deletions app/views/support/providers/onboarding/checks/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@

if @provider_form.accredited_provider?
component.with_row do |row|
row.with_key { "Accredited provider ID" }
row.with_value { @provider_form.accredited_provider_id }
row.with_action(text: "Change", href: new_support_recruitment_cycle_providers_onboarding_path(goto_confirmation: true), visually_hidden_text: "accredited provider ID")
row.with_key { "Accredited provider number" }
row.with_value { @provider_form.accredited_provider_number }
row.with_action(text: "Change", href: new_support_recruitment_cycle_providers_onboarding_path(goto_confirmation: true), visually_hidden_text: "accredited provider number")
end
end

Expand Down
4 changes: 2 additions & 2 deletions app/views/support/providers/onboardings/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

<%= f.govuk_radio_buttons_fieldset(:accredited_provider, legend: { text: "Is the organisation an accredited provider?", size: "s" }) do %>
<%= f.govuk_radio_button :accredited_provider, :accredited_provider, label: { text: "Yes" }, link_errors: true do %>
<%= f.govuk_text_field :accredited_provider_id,
<%= f.govuk_text_field :accredited_provider_number,
width: 10,
label: { text: "Accredited provider ID" },
label: { text: "Accredited provider number" },
autocomplete: :disabled %>

<% end %>
Expand Down
12 changes: 6 additions & 6 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -901,9 +901,9 @@ en:
ukprn:
blank: Enter a UK provider reference number (UKPRN)
contains_eight_numbers_starting_with_one: Enter a valid UK provider reference number (UKPRN) - it must be 8 digits starting with a 1, like 12345678
accredited_provider_id:
blank: Enter the accredited provider ID
format: Enter a valid accredited provider ID - it must be 4 digits starting with a 1 or a 5
accredited_provider_number:
blank: Enter the accredited provider number
format: Enter a valid accredited provider number - it must be 4 digits starting with a 1 or a 5
organisation:
attributes:
name:
Expand Down Expand Up @@ -1092,9 +1092,9 @@ en:
provider_type:
blank: "Select a provider type"
school_is_an_invalid_accredited_provider: "Accredited provider cannot be a school"
accredited_provider_id:
blank: "Enter an accredited provider ID"
invalid: "Enter a valid accredited provider ID"
accredited_provider_number:
blank: "Enter an accredited provider number"
invalid: "Enter a valid accredited provider number"
urn:
blank: "Enter a unique reference number (URN)"
invalid: "Enter a valid unique reference number (URN)"
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/providers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
trait :accredited_provider do
provider_type { :university }
accrediting_provider { 'Y' }
accredited_provider_id { Faker::Number.within(range: 1000..1999) }
accredited_provider_number { Faker::Number.within(range: 1000..1999) }
urn { nil }
end

Expand Down
8 changes: 4 additions & 4 deletions spec/features/support/providers/editing_a_provider_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
then_i_am_on_the_support_provider_edit_page
when_i_fill_in_a_valid_provider_name
and_i_choose_a_different_provider_type
and_i_fill_in_a_valid_id
and_i_fill_in_a_valid_number
and_i_click_the_submit_button
then_i_am_redirected_back_to_the_support_provider_show_page
and_the_provider_details_are_updated
Expand Down Expand Up @@ -55,7 +55,7 @@
private

def and_there_is_a_provider
@provider = create(:provider, :accredited_provider, :scitt, provider_name: 'Provider 1', accredited_provider_id: 5432)
@provider = create(:provider, :accredited_provider, :scitt, provider_name: 'Provider 1', accredited_provider_number: 5432)
end

def when_i_visit_the_support_provider_show_page
Expand Down Expand Up @@ -96,8 +96,8 @@ def when_i_fill_in_a_valid_provider_name
support_provider_edit_page.provider_name.set('Provider 2')
end

def and_i_fill_in_a_valid_id
fill_in 'provider-accredited-provider-id-field', with: '1234'
def and_i_fill_in_a_valid_number
fill_in 'provider-accredited-provider-number-field', with: '1234'
end

def and_i_choose_a_different_provider_type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,12 @@ def when_i_fill_in_a_valid_provider_details(provider_type:)
fill_in 'Unique reference number (URN)', with: '54321'
when :university
choose 'Yes'
fill_in 'Accredited provider ID', with: '1111'
fill_in 'Accredited provider number', with: '1111'

choose 'Higher education institution (HEI)'
when :scitt
choose 'Yes'
fill_in 'Accredited provider ID', with: '5555'
fill_in 'Accredited provider number', with: '5555'

choose 'School centred initial teacher training (SCITT)'
end
Expand Down Expand Up @@ -192,12 +192,12 @@ def and_the_provider_form_should_be_prefilled_with_the_provider_details(provider
expect(page).to have_field('Unique reference number (URN)', with: '54321')
when :university
expect(page).to have_checked_field('Yes')
expect(page).to have_field('Accredited provider ID', with: '1111')
expect(page).to have_field('Accredited provider number', with: '1111')

expect(page).to have_checked_field('Higher education institution (HEI)')
when :scitt
expect(page).to have_checked_field('Yes')
expect(page).to have_field('Accredited provider ID', with: '5555')
expect(page).to have_field('Accredited provider number', with: '5555')

expect(page).to have_checked_field('School centred initial teacher training (SCITT)')
end
Expand Down
38 changes: 19 additions & 19 deletions spec/forms/support/provider_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module Support
let(:params) do
build(:provider).attributes.symbolize_keys.slice(
:accrediting_provider,
:accredited_provider_id,
:accredited_provider_number,
:provider_code,
:provider_name,
:provider_type,
Expand Down Expand Up @@ -127,7 +127,7 @@ module Support
{ accredited_provider: :accredited_provider }
end

include_examples 'blank validation', :accredited_provider_id, 'Enter an accredited provider ID'
include_examples 'blank validation', :accredited_provider_number, 'Enter an accredited provider number'
end

context 'urn set to invalid' do
Expand Down Expand Up @@ -190,42 +190,42 @@ module Support
end
end

shared_examples 'accredited provider id validation' do |provider_type, accredited_provider_id, message|
context "provider_type is set to '#{provider_type}' and accredited_provider_id is set to '#{accredited_provider_id}'" do
shared_examples 'accredited provider number validation' do |provider_type, accredited_provider_number, message|
context "provider_type is set to '#{provider_type}' and accredited_provider_number is set to '#{accredited_provider_number}'" do
let(:params) do
{
provider_type:,
accredited_provider: :accredited_provider,
accredited_provider_id:
accredited_provider_number:
}
end

it 'validates the accredited provider id' do
it 'validates the accredited provider number' do
expect(subject).not_to be_valid

expect(subject.errors[:accredited_provider_id]).to match_array(message)
expect(subject.errors[:accredited_provider_number]).to match_array(message)
end
end
end

blank_accredited_provider_id_message = 'Enter an accredited provider ID'
blank_accredited_provider_number_message = 'Enter an accredited provider number'

[nil, ''].each do |blank_accredited_provider_id|
include_examples 'accredited provider id validation', nil, blank_accredited_provider_id, blank_accredited_provider_id_message
include_examples 'accredited provider id validation', :scitt, blank_accredited_provider_id, blank_accredited_provider_id_message
include_examples 'accredited provider id validation', :university, blank_accredited_provider_id, blank_accredited_provider_id_message
[nil, ''].each do |blank_accredited_provider_number|
include_examples 'accredited provider number validation', nil, blank_accredited_provider_number, blank_accredited_provider_number_message
include_examples 'accredited provider number validation', :scitt, blank_accredited_provider_number, blank_accredited_provider_number_message
include_examples 'accredited provider number validation', :university, blank_accredited_provider_number, blank_accredited_provider_number_message
end

invalid_accredited_provider_id_message = 'Enter a valid accredited provider ID'
invalid_accredited_provider_number_message = 'Enter a valid accredited provider number'

%w[a aaaa 12345 54321 abcde 1 5].each do |invalid_accredited_provider_id|
include_examples 'accredited provider id validation', nil, invalid_accredited_provider_id, invalid_accredited_provider_id_message
include_examples 'accredited provider id validation', :scitt, invalid_accredited_provider_id, invalid_accredited_provider_id_message
include_examples 'accredited provider id validation', :university, invalid_accredited_provider_id, invalid_accredited_provider_id_message
%w[a aaaa 12345 54321 abcde 1 5].each do |invalid_accredited_provider_number|
include_examples 'accredited provider number validation', nil, invalid_accredited_provider_number, invalid_accredited_provider_number_message
include_examples 'accredited provider number validation', :scitt, invalid_accredited_provider_number, invalid_accredited_provider_number_message
include_examples 'accredited provider number validation', :university, invalid_accredited_provider_number, invalid_accredited_provider_number_message
end

include_examples 'accredited provider id validation', :scitt, '1234', invalid_accredited_provider_id_message
include_examples 'accredited provider id validation', :university, '5432', invalid_accredited_provider_id_message
include_examples 'accredited provider number validation', :scitt, '1234', invalid_accredited_provider_number_message
include_examples 'accredited provider number validation', :university, '5432', invalid_accredited_provider_number_message
end

describe '#stash' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

require 'rails_helper'

class AccreditedProviderIdFormatValidatorTest
class AccreditedProviderNumberFormatValidatorTest
include ActiveModel::Validations

attr_accessor :accredited_provider_id
attr_accessor :accredited_provider_number

validates :accredited_provider_id, accredited_provider_id_format: { allow_blank: false }
validates :accredited_provider_number, accredited_provider_number_format: { allow_blank: false }
end

describe AccreditedProviderIdFormatValidator do
describe AccreditedProviderNumberFormatValidator do
let(:accredited_provider) { create(:provider, :accredited_provider, :university) }
let(:accredited_provider_id) { 1234 }
let(:accredited_provider_number) { 1234 }

let(:model) do
model = accredited_provider
model.accredited_provider_id = accredited_provider_id
model.accredited_provider_number = accredited_provider_number
model
end

Expand All @@ -28,7 +28,7 @@ class AccreditedProviderIdFormatValidatorTest
end

context 'with a valid id starting with 5' do
let(:accredited_provider_id) { 5432 }
let(:accredited_provider_number) { 5432 }

it 'does not add an error' do
expect(model).not_to be_valid
Expand All @@ -46,7 +46,7 @@ class AccreditedProviderIdFormatValidatorTest
end

context 'with a valid id starting with 5' do
let(:accredited_provider_id) { 5432 }
let(:accredited_provider_number) { 5432 }

it 'does not add an error' do
expect(model).to be_valid
Expand All @@ -65,7 +65,7 @@ class AccreditedProviderIdFormatValidatorTest
end

context 'with a valid id starting with 5' do
let(:accredited_provider_id) { 5432 }
let(:accredited_provider_number) { 5432 }

it 'adds provider_type error' do
model.valid?
Expand Down

0 comments on commit 843da5d

Please sign in to comment.