diff --git a/.rubocop.yml b/.rubocop.yml index 25c18ef643..b76c048511 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -18,12 +18,18 @@ Lint/UnusedBlockArgument: Exclude: - config/environments/* +Lint/MissingSuper: + Enabled: false + Style/HashEachMethods: Enabled: true Style/HashTransformKeys: Enabled: true +Style/StringConcatenation: + Enabled: false + Style/HashTransformValues: Enabled: true diff --git a/Gemfile.lock b/Gemfile.lock index 044fddbb8a..e79948bfcf 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -351,7 +351,7 @@ GEM rack (2.2.3) rack-attack (6.5.0) rack (>= 1.0, < 3) - rack-oauth2 (1.16.0) + rack-oauth2 (1.17.0) activesupport attr_required httpclient @@ -359,7 +359,7 @@ GEM rack (>= 2.1.0) rack-protection (2.1.0) rack - rack-proxy (0.6.5) + rack-proxy (0.7.0) rack rack-rewrite (1.5.1) rack-test (1.1.0) @@ -439,31 +439,32 @@ GEM rspec-support (3.10.2) rspec_junit_formatter (0.4.1) rspec-core (>= 2, < 4, != 2.12.0) - rubocop (0.87.1) + rubocop (1.15.0) parallel (~> 1.10) - parser (>= 2.7.1.1) + parser (>= 3.0.0.0) rainbow (>= 2.2.2, < 4.0) - regexp_parser (>= 1.7) + regexp_parser (>= 1.8, < 3.0) rexml - rubocop-ast (>= 0.1.0, < 1.0) + rubocop-ast (>= 1.5.0, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 2.0) - rubocop-ast (0.8.0) - parser (>= 2.7.1.5) - rubocop-govuk (3.17.2) - rubocop (= 0.87.1) - rubocop-ast (= 0.8.0) - rubocop-rails (= 2.8.1) + unicode-display_width (>= 1.4.0, < 3.0) + rubocop-ast (1.6.0) + parser (>= 3.0.1.1) + rubocop-govuk (4.0.0) + rubocop (~> 1.15.0) + rubocop-ast (~> 1.6.0) + rubocop-rails (~> 2.10.0) rubocop-rake (= 0.5.1) - rubocop-rspec (= 1.42.0) - rubocop-rails (2.8.1) + rubocop-rspec (~> 2.3.0) + rubocop-rails (2.10.1) activesupport (>= 4.2.0) rack (>= 1.1) - rubocop (>= 0.87.0) + rubocop (>= 1.7.0, < 2.0) rubocop-rake (0.5.1) rubocop - rubocop-rspec (1.42.0) - rubocop (>= 0.87.0) + rubocop-rspec (2.3.0) + rubocop (~> 1.0) + rubocop-ast (>= 1.1.0) ruby-graphviz (1.2.5) rexml ruby-progressbar (1.11.0) @@ -532,7 +533,7 @@ GEM tzinfo (2.0.4) concurrent-ruby (~> 1.0) uk_postcode (2.1.6) - unicode-display_width (1.7.0) + unicode-display_width (2.0.0) uniform_notifier (1.14.2) validate_email (0.1.6) activemodel (>= 3.0) @@ -563,7 +564,7 @@ GEM rack-proxy (>= 0.6.1) railties (>= 5.2) semantic_range (>= 2.3.0) - websocket-driver (0.7.3) + websocket-driver (0.7.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) xpath (3.2.0) diff --git a/app/controllers/candidates/schools_controller.rb b/app/controllers/candidates/schools_controller.rb index 34a26fee5b..dac3c3f853 100644 --- a/app/controllers/candidates/schools_controller.rb +++ b/app/controllers/candidates/schools_controller.rb @@ -40,7 +40,7 @@ def show def location_present? search_params[:location].present? || ( - search_params[:latitude].present? && search_params[:latitude].present? + search_params[:longitude].present? && search_params[:latitude].present? ) end diff --git a/app/controllers/concerns/gitis_authentication.rb b/app/controllers/concerns/gitis_authentication.rb index bd6db92609..25f702bef0 100644 --- a/app/controllers/concerns/gitis_authentication.rb +++ b/app/controllers/concerns/gitis_authentication.rb @@ -3,7 +3,9 @@ module GitisAuthentication include GitisAccess class UnauthorizedCandidate < RuntimeError; end + class UnconfirmedCandidate < RuntimeError; end + class InvalidContact < RuntimeError; end included do diff --git a/app/controllers/schools/base_controller.rb b/app/controllers/schools/base_controller.rb index a9395600c7..07451935d9 100644 --- a/app/controllers/schools/base_controller.rb +++ b/app/controllers/schools/base_controller.rb @@ -1,5 +1,6 @@ module Schools class SchoolNotRegistered < StandardError; end + class MissingURN < StandardError; end class BaseController < ApplicationController @@ -23,7 +24,7 @@ class BaseController < ApplicationController def current_school if current_urn.blank? - sub = current_user.raw_attributes.dig("sub") + sub = current_user.raw_attributes["sub"] raise MissingURN, "school urn is missing, unable to match with school for - user #{sub}" end @@ -44,7 +45,7 @@ def set_site_header_text def retrieve_school(urn) if urn.blank? - sub = current_user.raw_attributes.dig("sub") + sub = current_user.raw_attributes["sub"] raise MissingURN, "school urn is missing, unable to match with school for - user #{sub}" end diff --git a/app/controllers/schools/insecure_sessions_controller.rb b/app/controllers/schools/insecure_sessions_controller.rb index 703e8167c3..df60e16793 100644 --- a/app/controllers/schools/insecure_sessions_controller.rb +++ b/app/controllers/schools/insecure_sessions_controller.rb @@ -8,7 +8,7 @@ def create session[:id_token] = 'abc123' - # NOTE the sub (subscription) param is the user's unique identifier + # NOTE: the sub (subscription) param is the user's unique identifier # on DfE Sign-in and is hard-coded here. It must match the corresponding # value injected into Schools::SessionsController session[:current_user] = OpenIDConnect::ResponseObject::UserInfo.new( diff --git a/app/controllers/schools/sessions_controller.rb b/app/controllers/schools/sessions_controller.rb index c055dc8706..53da361cee 100644 --- a/app/controllers/schools/sessions_controller.rb +++ b/app/controllers/schools/sessions_controller.rb @@ -1,8 +1,12 @@ module Schools class StateMismatchError < StandardError; end + class AuthFailedError < StandardError; end + class InsufficientPrivilegesError < StandardError; end + class SessionExpiredError < StandardError; end + class NoOrganisationError < StandardError; end class SessionsController < ApplicationController diff --git a/app/helpers/schools/confirm_attendance_helper.rb b/app/helpers/schools/confirm_attendance_helper.rb index b2d3948630..3b5c0cd526 100644 --- a/app/helpers/schools/confirm_attendance_helper.rb +++ b/app/helpers/schools/confirm_attendance_helper.rb @@ -1,5 +1,5 @@ module Schools::ConfirmAttendanceHelper - # note we can't use the form builder here because it wraps everything in + # NOTE: we can't use the form builder here because it wraps everything in # form-groups and fieldsets which affect how it's displayed in a table cell def confirm_attendance_radio(builder, booking_id, value, label_text) tag.div(class: "govuk-radios__item") do diff --git a/app/models/bookings/data/school_mass_importer.rb b/app/models/bookings/data/school_mass_importer.rb index fa5e47a9dc..78977c1837 100644 --- a/app/models/bookings/data/school_mass_importer.rb +++ b/app/models/bookings/data/school_mass_importer.rb @@ -113,7 +113,7 @@ def cleanup_website(urn, url) return nil if url_with_prefix =~ /@/ # skip urls that don't look sensible - unless url_with_prefix.match?(/^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,10}(:[0-9]{1,5})?(\/.*)?$/ix) + unless url_with_prefix.match?(/^(http|https):\/\/[a-z0-9]+([\-.]{1}[a-z0-9]+)*\.[a-z]{2,10}(:[0-9]{1,5})?(\/.*)?$/ix) Rails.logger.info "invalid website for #{urn}, #{url}" return nil end diff --git a/app/models/bookings/profile_attributes_convertor.rb b/app/models/bookings/profile_attributes_convertor.rb index 9af44be7e0..fc3df45fa4 100644 --- a/app/models/bookings/profile_attributes_convertor.rb +++ b/app/models/bookings/profile_attributes_convertor.rb @@ -49,9 +49,10 @@ def phase_ids def convert_dbs_profile output[:dbs_policy_conditions] = input[:dbs_requirement_dbs_policy_conditions] - output[:dbs_policy_details] = if input[:dbs_requirement_dbs_policy_conditions] == 'notrequired' + output[:dbs_policy_details] = case input[:dbs_requirement_dbs_policy_conditions] + when 'notrequired' input[:dbs_requirement_no_dbs_policy_details].presence - elsif input[:dbs_requirement_dbs_policy_conditions] == 'inschool' + when 'inschool' input[:dbs_requirement_dbs_policy_details_inschool].presence else input[:dbs_requirement_dbs_policy_details].presence diff --git a/app/models/bookings/school_search.rb b/app/models/bookings/school_search.rb index 0935312be4..9aadc8d94c 100644 --- a/app/models/bookings/school_search.rb +++ b/app/models/bookings/school_search.rb @@ -167,7 +167,7 @@ def valid_geocoder_result?(result) def order_by(option) if (option == 'distance') && coordinates.present? - # note distance isn't actually an attribute of + # NOTE: distance isn't actually an attribute of # Bookings::School so we can't use hash syntax # as Rails will complain 'distance asc' diff --git a/app/models/bookings/school_sync.rb b/app/models/bookings/school_sync.rb index 2c3fec3aaa..451b79dcfa 100644 --- a/app/models/bookings/school_sync.rb +++ b/app/models/bookings/school_sync.rb @@ -40,7 +40,7 @@ def import_and_update end def sync_disabled? - disabled = ENV.fetch('GIAS_SYNC_DISABLED') { false } + disabled = ENV.fetch('GIAS_SYNC_DISABLED', false) disabled.to_s.in?(%w[1 true yes]) end diff --git a/app/models/cookie_preference.rb b/app/models/cookie_preference.rb index ecdfcc80d2..78620cac8f 100644 --- a/app/models/cookie_preference.rb +++ b/app/models/cookie_preference.rb @@ -74,7 +74,7 @@ def rejected_cookies all_cookies - accepted_cookies end - # Note: allowed is not the same as accepted + # NOTE: allowed is not the same as accepted # allowed = 'not explicitly rejected, and maybe explicitly accepted' # accepted = 'explicitly accepted' def allowed?(cookie_category_or_name) diff --git a/app/models/schools/on_boarding/profile_subject.rb b/app/models/schools/on_boarding/profile_subject.rb index 4f958ed8b5..f39c081726 100644 --- a/app/models/schools/on_boarding/profile_subject.rb +++ b/app/models/schools/on_boarding/profile_subject.rb @@ -13,5 +13,5 @@ class Schools::OnBoarding::ProfileSubject < ApplicationRecord validates :subject, presence: true validates :schools_school_profile_id, - uniqueness: { scope: %i[bookings_subject_id] } + uniqueness: { scope: :bookings_subject_id } end diff --git a/app/presenters/candidates/school_presenter.rb b/app/presenters/candidates/school_presenter.rb index bb7047f2e4..3718ed444a 100644 --- a/app/presenters/candidates/school_presenter.rb +++ b/app/presenters/candidates/school_presenter.rb @@ -97,22 +97,19 @@ def secondary_dates_grouped_by_date private def dbs_requirement - case profile.dbs_policy_conditions - when "required" - "Yes" - when "inschool" - "Yes - when in school" - when "notrequired" - 'No - Candidates will be accompanied at all times when in school' - end + { + 'required' => 'Yes', + 'inschool' => 'Yes - when in school', + 'notrequired' => 'No - Candidates will be accompanied at all times when in school' + }[profile.dbs_policy_conditions] end def legacy_dbs_requirement - case profile.dbs_required - when 'always' then 'Yes - Always' - when 'sometimes' then 'Yes - Sometimes' - when 'never' then 'No - Candidates will be accompanied at all times' - end + { + 'always' => 'Yes - Always', + 'sometimes' => 'Yes - Sometimes', + 'never' => 'No - Candidates will be accompanied at all times' + }[profile.dbs_required] end end end diff --git a/app/services/bookings/gitis/api.rb b/app/services/bookings/gitis/api.rb index 5f3dca47cb..8685817990 100644 --- a/app/services/bookings/gitis/api.rb +++ b/app/services/bookings/gitis/api.rb @@ -60,6 +60,7 @@ def patch(url, params, headers = {}) end class UnsupportedAbsoluteUrlError < RuntimeError; end + class ConnectionFailed < RuntimeError def initialize(url) super "Connection Failed: #{url}" @@ -78,6 +79,7 @@ def initialize(resp) end class UnknownUrlError < BadResponseError; end + class AccessDeniedError < BadResponseError; end private @@ -139,7 +141,7 @@ def parse_response(resp) end def parse_entity_id(entity_id) - entity_id&.gsub(%r{\A#{endpoint_url}\/}, '') + entity_id&.gsub(%r{\A#{endpoint_url}/}, '') end end end diff --git a/app/services/bookings/gitis/auth.rb b/app/services/bookings/gitis/auth.rb index e3ea6c957c..060947b3d5 100644 --- a/app/services/bookings/gitis/auth.rb +++ b/app/services/bookings/gitis/auth.rb @@ -29,7 +29,7 @@ def config Rails.application.config.x.gitis end - def token(force_reload = false) + def token(force_reload: false) if !force_reload && (cached_token = fetch_cached_token) && cached_token.present? cached_token elsif (new_token = retrieve_token) diff --git a/app/services/bookings/gitis/entity.rb b/app/services/bookings/gitis/entity.rb index f70d1212ec..edd9816f43 100644 --- a/app/services/bookings/gitis/entity.rb +++ b/app/services/bookings/gitis/entity.rb @@ -1,6 +1,8 @@ module Bookings::Gitis class IdChangedUnexpectedly < RuntimeError; end + class MissingPrimaryKey < RuntimeError; end + class InvalidEntityId < RuntimeError; end class InvalidEntity < RuntimeError @@ -17,7 +19,7 @@ module Entity include ActiveModel::Dirty ID_FORMAT = /\A[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\z/.freeze - BIND_FORMAT = /\A[^\(]+\([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\)\z/.freeze + BIND_FORMAT = /\A[^(]+\([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\)\z/.freeze def self.valid_id?(id) ID_FORMAT.match? id.to_s diff --git a/app/services/bookings/gitis/factory.rb b/app/services/bookings/gitis/factory.rb index 47f658a07a..6a29936065 100644 --- a/app/services/bookings/gitis/factory.rb +++ b/app/services/bookings/gitis/factory.rb @@ -14,7 +14,7 @@ def crm(read_from_cache: false) if Rails.application.config.x.gitis.fake_crm Bookings::Gitis::FakeCrm.new elsif Rails.application.config.x.gitis.caching - Bookings::Gitis::CRM.new caching_store(read_from_cache) + Bookings::Gitis::CRM.new caching_store(read_from_cache: read_from_cache) else Bookings::Gitis::CRM.new store end @@ -42,7 +42,7 @@ def read_write_caching_store store, cache, namespace: NAMESPACE, ttl: TTL, version: VERSION end - def caching_store(read_from_cache = false) + def caching_store(read_from_cache: false) read_from_cache ? read_write_caching_store : write_only_caching_store end diff --git a/app/services/bookings/gitis/store/write_only_cache.rb b/app/services/bookings/gitis/store/write_only_cache.rb index f688a8cbe7..2b4379cb5f 100644 --- a/app/services/bookings/gitis/store/write_only_cache.rb +++ b/app/services/bookings/gitis/store/write_only_cache.rb @@ -3,6 +3,7 @@ module Gitis module Store class WriteOnlyCache attr_reader :store, :cache, :namespace, :ttl, :version + delegate :fetch, to: :store def initialize(store, cache, namespace: nil, ttl: 1.hour, version: 'v1') diff --git a/app/services/candidates/registrations/registration_session.rb b/app/services/candidates/registrations/registration_session.rb index 719b76c898..d27ef9f29f 100644 --- a/app/services/candidates/registrations/registration_session.rb +++ b/app/services/candidates/registrations/registration_session.rb @@ -5,6 +5,7 @@ module Candidates module Registrations class RegistrationSession class NotCompletedError < StandardError; end + class StepNotFound < StandardError; end PENDING_EMAIL_CONFIRMATION_STATUS = 'pending_email_confirmation'.freeze diff --git a/app/services/candidates/registrations/registration_store.rb b/app/services/candidates/registrations/registration_store.rb index 9b890760b8..be17e872f3 100644 --- a/app/services/candidates/registrations/registration_store.rb +++ b/app/services/candidates/registrations/registration_store.rb @@ -5,6 +5,7 @@ class RegistrationStore include Singleton class SessionNotFound < StandardError; end + class NoKey < StandardError; end def initialize diff --git a/app/validators/email_format_validator.rb b/app/validators/email_format_validator.rb index 2cecff0605..9b2a608e72 100644 --- a/app/validators/email_format_validator.rb +++ b/app/validators/email_format_validator.rb @@ -1,5 +1,5 @@ class EmailFormatValidator < ActiveModel::EachValidator - EMAIL_WITH_FULLY_QUALIFIED_HOSTNAME = %r{\A[^\s@]+@[^\.\s]+\.[^\s]+\z}.freeze + EMAIL_WITH_FULLY_QUALIFIED_HOSTNAME = %r{\A[^\s@]+@[^.\s]+\.[^\s]+\z}.freeze def validate_each(record, attribute, value) unless value.present? && is_an_email_uri?(value) && is_fqdn?(value) diff --git a/bin/update b/bin/update deleted file mode 100755 index 67d0d49645..0000000000 --- a/bin/update +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env ruby -require 'fileutils' -include FileUtils - -# path to your application root. -APP_ROOT = File.expand_path('..', __dir__) - -def system!(*args) - system(*args) || abort("\n== Command #{args} failed ==") -end - -chdir APP_ROOT do - # This script is a way to update your development environment automatically. - # Add necessary update steps to this file. - - puts '== Installing dependencies ==' - system! 'gem install bundler --conservative' - system('bundle check') || system!('bundle install') - - puts "\n== Updating database ==" - system! 'bin/rails db:migrate' - - puts "\n== Removing old logs and tempfiles ==" - system! 'bin/rails log:clear tmp:clear' - - puts "\n== Restarting application server ==" - system! 'bin/rails restart' -end diff --git a/config/environments/development.rb b/config/environments/development.rb index f8be319c10..a0213e1c77 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -86,13 +86,13 @@ Bullet.unused_eager_loading_enable = false end - config.x.phase = Integer(ENV.fetch('PHASE') { 10_000 }) + config.x.phase = Integer(ENV.fetch('PHASE', 10_000)) config.x.features = %i[ subject_specific_dates capped_bookings ] config.x.candidates.deactivate_applications = ENV['DEACTIVATE_CANDIDATES'].to_s.presence || false - config.x.google_maps_key = ENV['GOOGLE_MAPS_KEY'].presence || Rails.application.credentials.dig(:google_maps_key) + config.x.google_maps_key = ENV['GOOGLE_MAPS_KEY'].presence || Rails.application.credentials[:google_maps_key] # dfe signin redirects back to https, so force it config.force_ssl = true @@ -100,7 +100,7 @@ # dfe signin config, should be in credentials or env vars config.x.base_url = 'https://localhost:3000' config.x.oidc_client_id = 'schoolexperience' - config.x.oidc_client_secret = Rails.application.credentials.dig(:dfe_pp_signin_secret) + config.x.oidc_client_secret = Rails.application.credentials[:dfe_pp_signin_secret] config.x.oidc_host = 'pp-oidc.signin.education.gov.uk' config.x.oidc_services_list_url = 'https://pp-services.signin.education.gov.uk/my-services' config.x.dfe_sign_in_api_host = 'pp-api.signin.education.gov.uk' @@ -116,7 +116,7 @@ Rails.application.config.x.notify_client = ENV['NOTIFY_CLIENT'] end - config.x.gitis.fake_crm = truthy_strings.include?(String(ENV.fetch('FAKE_CRM') { true })) + config.x.gitis.fake_crm = truthy_strings.include?(String(ENV.fetch('FAKE_CRM', true))) config.x.gitis.fake_crm_uuid = ENV.fetch('FAKE_CRM_UUID', nil) config.x.gitis.auth_client_id = ENV.fetch('CRM_CLIENT_ID', 'notset') config.x.gitis.auth_secret = ENV.fetch('CRM_CLIENT_SECRET', 'notset') diff --git a/config/environments/production.rb b/config/environments/production.rb index cd83cfa1e5..03a1ca5032 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -85,7 +85,7 @@ # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') if ENV["RAILS_LOG_TO_STDOUT"].present? - logger = ActiveSupport::Logger.new(STDOUT) + logger = ActiveSupport::Logger.new($stdout) logger.formatter = config.log_formatter config.logger = ActiveSupport::TaggedLogging.new(logger) end @@ -138,7 +138,7 @@ config.x.default_phase = 4 config.x.phase = Integer(ENV['PHASE'].presence || config.x.default_phase) config.x.candidates.deactivate_applications = ENV['DEACTIVATE_CANDIDATES'].to_s.presence || false - config.x.google_maps_key = ENV['GOOGLE_MAPS_KEY'].presence || Rails.application.credentials.dig(:google_maps_key) + config.x.google_maps_key = ENV['GOOGLE_MAPS_KEY'].presence || Rails.application.credentials[:google_maps_key] config.x.base_url = ENV.fetch('DFE_SIGNIN_BASE_URL') { 'https://schoolexperience.education.gov.uk' } config.x.oidc_client_id = ENV.fetch('DFE_SIGNIN_CLIENT_ID') { 'schoolexperience' } diff --git a/config/environments/servertest.rb b/config/environments/servertest.rb index e2b796e776..685aa5b623 100644 --- a/config/environments/servertest.rb +++ b/config/environments/servertest.rb @@ -23,9 +23,9 @@ config.x.google_maps_key = nil # dfe signin config, should be in credentials or env vars - config.x.base_url = "https://localhost:#{ENV.fetch('PORT') { 3000 }}" + config.x.base_url = "https://localhost:#{ENV.fetch('PORT', 3000)}" config.x.oidc_client_id = 'schoolexperience' - config.x.oidc_client_secret = Rails.application.credentials.dig(:dfe_pp_signin_secret) + config.x.oidc_client_secret = Rails.application.credentials[:dfe_pp_signin_secret] config.x.oidc_host = 'pp-oidc.signin.education.gov.uk' config.x.oidc_services_list_url = 'https://some-oidc.provider.com/my-services' config.x.dfe_sign_in_api_host = 'pp-api.signin.education.gov.uk' diff --git a/config/initializers/canonical_redirect.rb b/config/initializers/canonical_redirect.rb index 20d63b2afd..ea0e637f30 100644 --- a/config/initializers/canonical_redirect.rb +++ b/config/initializers/canonical_redirect.rb @@ -16,7 +16,7 @@ if: proc { |rack_env| ENV['CANONICAL_DOMAIN'].present? && rack_env['HTTP_HOST'] != ENV['CANONICAL_DOMAIN'] && - !rack_env['PATH_INFO'].match?(%r{/(healthcheck|deployment|healthchecks\/[a-z]+)\.txt}) + !rack_env['PATH_INFO'].match?(%r{/(healthcheck|deployment|healthchecks/[a-z]+)\.txt}) } end end diff --git a/config/puma.rb b/config/puma.rb index ba5791011f..94a2893a69 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -4,8 +4,8 @@ # the maximum value specified for Puma. Default is set to 5 threads for minimum # and maximum; this matches the default thread size of Active Record. # -max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } -min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count } +max_threads_count = ENV.fetch("RAILS_MAX_THREADS", 5) +min_threads_count = ENV.fetch("RAILS_MIN_THREADS", max_threads_count) threads min_threads_count, max_threads_count # Specifies the `worker_timeout` threshold that Puma will use to wait before @@ -15,14 +15,14 @@ # Specifies the `port` that Puma will listen on to receive requests; default is 3000. # -listen_port = ENV.fetch("PORT") { 3000 } +listen_port = ENV.fetch("PORT", 3000) # Specifies the `environment` that Puma will run in. # -environment ENV.fetch("RAILS_ENV") { "development" } +environment ENV.fetch("RAILS_ENV", "development") # Specifies the `pidfile` that Puma will use. -pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" } +pidfile ENV.fetch("PIDFILE", "tmp/pids/server.pid") # Specifies the number of `workers` to boot in clustered mode. # Workers are forked web server processes. If using threads and workers together diff --git a/db/migrate/20210622134457_add_unique_index_to_booking_cancellations.rb b/db/migrate/20210622134457_add_unique_index_to_booking_cancellations.rb new file mode 100644 index 0000000000..f4fa720244 --- /dev/null +++ b/db/migrate/20210622134457_add_unique_index_to_booking_cancellations.rb @@ -0,0 +1,11 @@ +class AddUniqueIndexToBookingCancellations < ActiveRecord::Migration[6.1] + def up + remove_index :bookings_placement_request_cancellations, name: "index_cancellations_on_bookings_placement_request_id" + add_index :bookings_placement_request_cancellations, :bookings_placement_request_id, name: "index_cancellations_on_bookings_placement_request_id", unique: true + end + + def down + remove_index :bookings_placement_request_cancellations, name: "index_cancellations_on_bookings_placement_request_id" + add_index :bookings_placement_request_cancellations, :bookings_placement_request_id, name: "index_cancellations_on_bookings_placement_request_id" + end +end diff --git a/db/migrate/20210622155324_add_unique_index_to_bookings_schools_phases.rb b/db/migrate/20210622155324_add_unique_index_to_bookings_schools_phases.rb new file mode 100644 index 0000000000..1d9a21b86f --- /dev/null +++ b/db/migrate/20210622155324_add_unique_index_to_bookings_schools_phases.rb @@ -0,0 +1,8 @@ +class AddUniqueIndexToBookingsSchoolsPhases < ActiveRecord::Migration[6.1] + def change + add_index :bookings_schools_phases, + %i[bookings_school_id bookings_phase_id], + unique: true, + name: "index_bookings_schools_phases_school_id_and_phase_id" + end +end diff --git a/db/migrate/20210622160115_add_unique_index_to_schools_on_boarding_profile_subjects.rb b/db/migrate/20210622160115_add_unique_index_to_schools_on_boarding_profile_subjects.rb new file mode 100644 index 0000000000..1a90a421d4 --- /dev/null +++ b/db/migrate/20210622160115_add_unique_index_to_schools_on_boarding_profile_subjects.rb @@ -0,0 +1,8 @@ +class AddUniqueIndexToSchoolsOnBoardingProfileSubjects < ActiveRecord::Migration[6.1] + def change + add_index :schools_on_boarding_profile_subjects, + %i[schools_school_profile_id bookings_subject_id], + unique: true, + name: "index_profile_subjects_school_profile_id_and_subject_id" + end +end diff --git a/db/schema.rb b/db/schema.rb index 54058f66a1..68f3c938ab 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_01_30_095443) do +ActiveRecord::Schema.define(version: 2021_06_22_160115) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -91,7 +91,7 @@ t.text "extra_details" t.datetime "viewed_at" t.string "rejection_category" - t.index ["bookings_placement_request_id"], name: "index_cancellations_on_bookings_placement_request_id" + t.index ["bookings_placement_request_id"], name: "index_cancellations_on_bookings_placement_request_id", unique: true t.index ["rejection_category"], name: "index_bookings_placement_request_cancellations_category" end @@ -238,6 +238,7 @@ t.integer "bookings_phase_id", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.index ["bookings_school_id", "bookings_phase_id"], name: "index_bookings_schools_phases_school_id_and_phase_id", unique: true end create_table "bookings_schools_subjects", force: :cascade do |t| @@ -319,6 +320,7 @@ t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["bookings_subject_id"], name: "index_profile_subjects_on_school_profile_i" + t.index ["schools_school_profile_id", "bookings_subject_id"], name: "index_profile_subjects_school_profile_id_and_subject_id", unique: true t.index ["schools_school_profile_id"], name: "index_profile_subjects_on_school_profile_id" end diff --git a/features/step_definitions/candidates/schools/show_steps.rb b/features/step_definitions/candidates/schools/show_steps.rb index 84296ab24f..89dab1f2ee 100644 --- a/features/step_definitions/candidates/schools/show_steps.rb +++ b/features/step_definitions/candidates/schools/show_steps.rb @@ -169,9 +169,10 @@ end Given("my school of choice has {string} dates") do |option| - @school = if option == 'fixed' + @school = case option + when 'fixed' FactoryBot.create(:bookings_school, :with_fixed_availability_preference) - elsif option == 'flexible' + when 'flexible' FactoryBot.create(:bookings_school) else raise 'invalid flexibility option' diff --git a/features/step_definitions/schools/placement_request_steps.rb b/features/step_definitions/schools/placement_request_steps.rb index 06589246aa..d8cbf21f73 100644 --- a/features/step_definitions/schools/placement_request_steps.rb +++ b/features/step_definitions/schools/placement_request_steps.rb @@ -127,7 +127,7 @@ end Then("there should be the following buttons:") do |table| - # note that button_to inserts a form with a submit input so + # NOTE: that button_to inserts a form with a submit input so # if we don't find a regular link/button check for that too table.transpose.raw.flatten.each do |button_text| within('.accept-or-reject') do diff --git a/features/support/database_cleaner.rb b/features/support/database_cleaner.rb index ceb3df2013..b7900d1615 100644 --- a/features/support/database_cleaner.rb +++ b/features/support/database_cleaner.rb @@ -29,5 +29,5 @@ DatabaseCleaner.strategy = :deletion, deletion_options Cucumber::Rails::Database.javascript_strategy = :deletion, deletion_options if ENV['DEBUG_DATABASE_CLEANER'].present? - ActiveRecord::Base.logger = Logger.new(STDOUT) + ActiveRecord::Base.logger = Logger.new($stdout) end diff --git a/features/support/feature_helper.rb b/features/support/feature_helper.rb index 2a0fbd8733..83f518ceee 100644 --- a/features/support/feature_helper.rb +++ b/features/support/feature_helper.rb @@ -1,5 +1,5 @@ def delay_page_load if ENV['CUC_DRIVER'].present? || ENV['CUC_PAGE_DELAY'].present? - sleep Integer(ENV.fetch('CUC_PAGE_DELAY') { 0 }) + sleep Integer(ENV.fetch('CUC_PAGE_DELAY', 0)) end end diff --git a/lib/notify/notify_sync.rb b/lib/notify/notify_sync.rb index 2ff05c8fc0..0ee1822b09 100644 --- a/lib/notify/notify_sync.rb +++ b/lib/notify/notify_sync.rb @@ -34,7 +34,7 @@ def pull File.write( File.join( TEMPLATE_PATH, - [rt.name.gsub(/[\ ]/, "").underscore, template_id, 'md'].join('.'), + [rt.name.gsub(/\ /, "").underscore, template_id, 'md'].join('.'), ), reencode(rt.body) ) diff --git a/script/cleanse b/script/cleanse index fe2663ef10..9ff26665b0 100755 --- a/script/cleanse +++ b/script/cleanse @@ -9,4 +9,4 @@ # # $./cleanse < edubasealldata20190220.csv > clean.csv -STDOUT.puts(STDIN.read.scrub.encode(Encoding::UTF_8, universal_newline: true)) +$stdout.puts($stdin.read.scrub.encode(Encoding::UTF_8, universal_newline: true)) diff --git a/spec/controllers/candidates/dashboard_base_controller_spec.rb b/spec/controllers/candidates/dashboard_base_controller_spec.rb index 982b2c68b5..a61b43a2fe 100644 --- a/spec/controllers/candidates/dashboard_base_controller_spec.rb +++ b/spec/controllers/candidates/dashboard_base_controller_spec.rb @@ -1,12 +1,12 @@ require 'rails_helper' -RSpec.describe Candidates::DashboardBaseController, type: :request do - class StubController < Candidates::DashboardBaseController - def index - render plain: 'Authorized' - end +class StubController < Candidates::DashboardBaseController + def index + render plain: 'Authorized' end +end +RSpec.describe Candidates::DashboardBaseController, type: :request do describe "GET #index" do before do Rails.application.routes.send(:eval_block, lambda { diff --git a/spec/controllers/candidates/registrations/subject_and_date_informations_controller_spec.rb b/spec/controllers/candidates/registrations/subject_and_date_informations_controller_spec.rb index a13d65f188..051482bc65 100644 --- a/spec/controllers/candidates/registrations/subject_and_date_informations_controller_spec.rb +++ b/spec/controllers/candidates/registrations/subject_and_date_informations_controller_spec.rb @@ -21,7 +21,7 @@ it('responds with 302') { expect(response.status).to eq 302 } it 'should redirect to the personal information page' do - expect(response.header.dig("Location")).to end_with('schools/11048/registrations/personal_information/new') + expect(response.header["Location"]).to end_with('schools/11048/registrations/personal_information/new') end end end diff --git a/spec/controllers/concerns/dfe_authentication_spec.rb b/spec/controllers/concerns/dfe_authentication_spec.rb index 34af801c95..fecec15d70 100644 --- a/spec/controllers/concerns/dfe_authentication_spec.rb +++ b/spec/controllers/concerns/dfe_authentication_spec.rb @@ -28,7 +28,7 @@ end it 'will request organisation from DfE Sign-in' do - is_expected.to redirect_to %r{\&scope=profile%20organisation%20openid} + is_expected.to redirect_to %r{&scope=profile%20organisation%20openid} end end @@ -40,7 +40,7 @@ end it 'will not request organisation from DfE Sign-in' do - is_expected.to redirect_to %r{\&scope=profile%20openid} + is_expected.to redirect_to %r{&scope=profile%20openid} end end end diff --git a/spec/controllers/concerns/gitis_access_spec.rb b/spec/controllers/concerns/gitis_access_spec.rb index 638b1c8099..7e2184f543 100644 --- a/spec/controllers/concerns/gitis_access_spec.rb +++ b/spec/controllers/concerns/gitis_access_spec.rb @@ -1,22 +1,22 @@ +class ModuleTester + include GitisAccess +end + +class CachedModuleTester + include GitisAccess + self.use_gitis_cache = true +end + describe GitisAccess do let(:factory) { Bookings::Gitis::Factory } before { allow(factory).to receive(:crm) { true } } context 'without configuring caching' do - class ModuleTester - include GitisAccess - end - subject! { ModuleTester.new.gitis_crm } it { expect(factory).to have_received(:crm).with(read_from_cache: false) } end context 'without configuring caching' do - class CachedModuleTester - include GitisAccess - self.use_gitis_cache = true - end - subject! { CachedModuleTester.new.gitis_crm } it { expect(factory).to have_received(:crm).with(read_from_cache: true) } end diff --git a/spec/forms/schools/on_boarding/experience_outline_spec.rb b/spec/forms/schools/on_boarding/experience_outline_spec.rb index 4f5b65b5c1..c1c221f510 100644 --- a/spec/forms/schools/on_boarding/experience_outline_spec.rb +++ b/spec/forms/schools/on_boarding/experience_outline_spec.rb @@ -16,14 +16,14 @@ it { is_expected.to validate_presence_of :teacher_training_details } context 'when teacher_training_url is present' do - INVALID_URLS = ['javascript:alert("oh no!")//http://example.com'].freeze - VALID_URLS = ['https://www.example.com', 'http://example.com'].freeze + invalid_urls = ['javascript:alert("oh no!")//http://example.com'].freeze + valid_urls = ['https://www.example.com', 'http://example.com'].freeze - INVALID_URLS.each do |url| + invalid_urls.each do |url| it { is_expected.not_to allow_value(url).for :teacher_training_url } end - VALID_URLS.each do |url| + valid_urls.each do |url| it { is_expected.to allow_value(url).for :teacher_training_url } end end diff --git a/spec/lib/notify/notify_sync_spec.rb b/spec/lib/notify/notify_sync_spec.rb index 89e982c98f..e70ff6299b 100644 --- a/spec/lib/notify/notify_sync_spec.rb +++ b/spec/lib/notify/notify_sync_spec.rb @@ -52,7 +52,7 @@ after { subject.compare } specify "should state that exact templates match" do - expect(STDOUT).to receive(:puts).with( + expect($stdout).to receive(:puts).with( [ matching_template_id.ljust(18), matching_template_name.ljust(40), @@ -79,7 +79,7 @@ after { subject.compare } specify "should state that local-only templates are missing from remote repository" do - expect(STDOUT).to receive(:puts).with( + expect($stdout).to receive(:puts).with( [ local_only_template_id.ljust(18), "Unknown".ljust(40), @@ -111,7 +111,7 @@ after { subject.compare } specify "should state that local-only templates are missing from local repository" do - expect(STDOUT).to receive(:puts).with( + expect($stdout).to receive(:puts).with( [ remote_only_template_id.ljust(18), remote_only_template_name.ljust(40), diff --git a/spec/models/bookings/data/school_mass_importer_spec.rb b/spec/models/bookings/data/school_mass_importer_spec.rb index fe4488f914..a392886d1b 100644 --- a/spec/models/bookings/data/school_mass_importer_spec.rb +++ b/spec/models/bookings/data/school_mass_importer_spec.rb @@ -3,7 +3,7 @@ describe Bookings::Data::SchoolMassImporter do before do - allow(STDOUT).to receive(:puts).and_return(true) + allow($stdout).to receive(:puts).and_return(true) allow_any_instance_of(Kernel).to receive(:print).and_return(nil) end @@ -36,7 +36,7 @@ let(:school_type_id) { 2 } before do - # note these values are present in spec/sample_data/edubase.csv + # NOTE: these values are present in spec/sample_data/edubase.csv { 1 => 'Early years', 2 => 'Primary (4 to 11)', diff --git a/spec/models/concerns/yaml_model_spec.rb b/spec/models/concerns/yaml_model_spec.rb index 1fe707eaa3..792c15fd9a 100644 --- a/spec/models/concerns/yaml_model_spec.rb +++ b/spec/models/concerns/yaml_model_spec.rb @@ -1,13 +1,14 @@ require 'rails_helper' -describe YamlModel, type: :model do - class YamlTestModel - include YamlModel - id_attribute :dob, :date - attribute :firstname, :string - attribute :lastname, :string - end +class YamlTestModel + include YamlModel + id_attribute :dob, :date + attribute :firstname, :string + attribute :lastname, :string +end + +describe YamlModel, type: :model do let(:described_class) { YamlTestModel } describe '.data_path' do diff --git a/spec/models/feature_spec.rb b/spec/models/feature_spec.rb index 3707b12b78..464762cd42 100644 --- a/spec/models/feature_spec.rb +++ b/spec/models/feature_spec.rb @@ -1,12 +1,12 @@ require 'rails_helper' -describe Feature do - class Tester - def self.hello - 'world' - end +class Tester + def self.hello + 'world' end +end +describe Feature do before { Feature.instance.current_phase = 10 } after { Feature.instance.current_phase = nil } subject { Feature.instance } diff --git a/spec/notify/notify_spec.rb b/spec/notify/notify_spec.rb index 84d975af88..b4ed0ae975 100644 --- a/spec/notify/notify_spec.rb +++ b/spec/notify/notify_spec.rb @@ -2,6 +2,25 @@ require Rails.root.join('spec', 'support', 'notify_fake_client') require Rails.root.join('spec', 'support', 'notify_retryable_erroring_client') +class StubNotification < Notify + attr_accessor :name + + def initialize(to:, name:) + self.name = name + super(to: to) + end + +private + + def template_id + 'ec830a0d-d032-4d4b-a107-xxxxyyyyzzzz' + end + + def personalisation + { name: name } + end +end + describe Notify do include ActiveJob::TestHelper let(:to) { 'somename@somecompany.org' } @@ -53,25 +72,6 @@ end describe 'custom notify_client' do - class StubNotification < Notify - attr_accessor :name - - def initialize(to:, name:) - self.name = name - super(to: to) - end - - private - - def template_id - 'ec830a0d-d032-4d4b-a107-xxxxyyyyzzzz' - end - - def personalisation - { name: name } - end - end - let :recipients do %w[test1@user.com test2@user.com] end diff --git a/spec/services/bookings/gitis/entity_spec.rb b/spec/services/bookings/gitis/entity_spec.rb index 3c8574334a..35ad87502e 100644 --- a/spec/services/bookings/gitis/entity_spec.rb +++ b/spec/services/bookings/gitis/entity_spec.rb @@ -1,5 +1,24 @@ require 'rails_helper' +class Associated + include Bookings::Gitis::Entity + + entity_id_attribute :associatedid + entity_attribute :description + entity_association :testassoc, TestEntity +end + +class TestInternal < TestEntity + entity_attribute :hidden, internal: true +end + +class TeamEntity + include Bookings::Gitis::Entity + + entity_attribute :name + entity_collection :players, TestEntity +end + RSpec.describe Bookings::Gitis::Entity do include_context 'test entity' @@ -212,10 +231,6 @@ end describe "private attributes" do - class TestInternal < TestEntity - entity_attribute :hidden, internal: true - end - it { expect(TestInternal.select_attribute_names).to include('hidden') } it { expect(TestInternal.respond_to?('hidden')).to be false } it { expect(TestInternal.respond_to?('hidden=')).to be false } @@ -238,14 +253,6 @@ class TestInternal < TestEntity TestEntity.new('testentityid' => SecureRandom.uuid, 'firstname' => 'test') end - class Associated - include Bookings::Gitis::Entity - - entity_id_attribute :associatedid - entity_attribute :description - entity_association :testassoc, TestEntity - end - context 'with new instance' do subject { Associated.new('description' => 'test') } @@ -380,13 +387,6 @@ class Associated end describe '.entity_collection' do - class TeamEntity - include Bookings::Gitis::Entity - - entity_attribute :name - entity_collection :players, TestEntity - end - context 'initializing with data' do let(:player1) { SecureRandom.uuid } let(:player2) { SecureRandom.uuid } diff --git a/spec/services/bookings/gitis/factory_spec.rb b/spec/services/bookings/gitis/factory_spec.rb index 16c2d6504c..a35d512de8 100644 --- a/spec/services/bookings/gitis/factory_spec.rb +++ b/spec/services/bookings/gitis/factory_spec.rb @@ -35,12 +35,12 @@ before { allow(factory).to receive(:token).and_return('a.fake.token') } context 'with read_from_cache' do - subject! { factory.caching_store(true) } + subject! { factory.caching_store(read_from_cache: true) } it { is_expected.to be_kind_of Bookings::Gitis::Store::ReadWriteCache } end context 'without read_from_cache' do - subject! { factory.caching_store(false) } + subject! { factory.caching_store(read_from_cache: false) } it { is_expected.to be_kind_of Bookings::Gitis::Store::WriteOnlyCache } end end diff --git a/spec/services/bookings/gitis/store/read_write_cache_spec.rb b/spec/services/bookings/gitis/store/read_write_cache_spec.rb index 2ad1ee9efb..ad015d35e5 100644 --- a/spec/services/bookings/gitis/store/read_write_cache_spec.rb +++ b/spec/services/bookings/gitis/store/read_write_cache_spec.rb @@ -1,12 +1,12 @@ require 'rails_helper' -describe Bookings::Gitis::Store::ReadWriteCache do - class Person - include Bookings::Gitis::Entity - entity_id_attribute :personid - entity_attribute :fullname - end +class Person + include Bookings::Gitis::Entity + entity_id_attribute :personid + entity_attribute :fullname +end +describe Bookings::Gitis::Store::ReadWriteCache do let(:version) { 'v1' } let(:dynamics) { Bookings::Gitis::Store::Dynamics.new 'a.fake.token' } let(:cache) { Rails.cache } diff --git a/spec/services/bookings/gitis/store/write_only_cache_spec.rb b/spec/services/bookings/gitis/store/write_only_cache_spec.rb index bdae3bc57a..c5c47967cd 100644 --- a/spec/services/bookings/gitis/store/write_only_cache_spec.rb +++ b/spec/services/bookings/gitis/store/write_only_cache_spec.rb @@ -1,12 +1,12 @@ require 'rails_helper' -describe Bookings::Gitis::Store::WriteOnlyCache do - class Person - include Bookings::Gitis::Entity - entity_id_attribute :personid - entity_attribute :fullname - end +class Person + include Bookings::Gitis::Entity + entity_id_attribute :personid + entity_attribute :fullname +end +describe Bookings::Gitis::Store::WriteOnlyCache do let(:version) { 'v1' } let(:ttl) { 1.hour } let(:cache) { Rails.cache } diff --git a/spec/services/candidates/registrations/contact_information_spec.rb b/spec/services/candidates/registrations/contact_information_spec.rb index f8e085364f..1d065828e5 100644 --- a/spec/services/candidates/registrations/contact_information_spec.rb +++ b/spec/services/candidates/registrations/contact_information_spec.rb @@ -53,12 +53,12 @@ it { is_expected.to validate_length_of(:phone).is_at_most(50).with_message(too_long_msg) } context 'phone is present' do - VALID_NUMBERS = ['01434 634996', '+441434634996', '01234567890'].freeze - INVALID_NUMBERS = ['7', 'q', '+4414346349'].freeze - BLANK_NUMBERS = ['', ' ', ' '].freeze + valid_numbers = ['01434 634996', '+441434634996', '01234567890'].freeze + invalid_numbers = ['7', 'q', '+4414346349'].freeze + blank_numbers = ['', ' ', ' '].freeze context 'valid numbers' do - VALID_NUMBERS.each do |number| + valid_numbers.each do |number| subject { described_class.new phone: number } before { subject.validate } @@ -69,7 +69,7 @@ end context 'invalid numbers' do - INVALID_NUMBERS.each do |number| + invalid_numbers.each do |number| subject { described_class.new phone: number } before { subject.validate } @@ -80,7 +80,7 @@ end context 'blank number' do - BLANK_NUMBERS.each do |number| + blank_numbers.each do |number| subject { described_class.new phone: number } before { subject.validate } @@ -96,7 +96,7 @@ let(:too_long_msg) { 'Postcode must be 20 characters or fewer' } it { is_expected.to validate_length_of(:postcode).is_at_most(20).with_message(too_long_msg) } - VALID_POSTCODES = [ + valid_postcodes = [ 'DN55 1PT', 'CR2 6XH', 'B33 8TH', @@ -106,17 +106,17 @@ 'ch63 7ns' ].freeze - INVALID_POSTCODES = [ + invalid_postcodes = [ 'horses', 'N0T AP057C0D3', 'B3333 1BB', 'CH3', ].freeze - BLANK_POSTCODES = ['', ' ', ' '].freeze + blank_postcodes = ['', ' ', ' '].freeze context 'valid postcodes' do - VALID_POSTCODES.each do |postcode| + valid_postcodes.each do |postcode| subject { described_class.new postcode: postcode } before { subject.validate } @@ -127,7 +127,7 @@ end context 'invalid postcodes' do - INVALID_POSTCODES.each do |postcode| + invalid_postcodes.each do |postcode| subject { described_class.new postcode: postcode } before { subject.validate } @@ -138,7 +138,7 @@ end context 'blank postcodes' do - BLANK_POSTCODES.each do |postcode| + blank_postcodes.each do |postcode| subject { described_class.new postcode: postcode } before { subject.validate } diff --git a/spec/services/candidates/registrations/registration_as_placement_request_spec.rb b/spec/services/candidates/registrations/registration_as_placement_request_spec.rb index 2e3253eb34..5a506dac06 100644 --- a/spec/services/candidates/registrations/registration_as_placement_request_spec.rb +++ b/spec/services/candidates/registrations/registration_as_placement_request_spec.rb @@ -4,7 +4,7 @@ let(:urn) { 11_048 } subject { described_class.new session } - PII = { + pii = { "full_name" => 'Testy McTest', "email" => 'test@example.com', "building" => "Test building", @@ -41,7 +41,7 @@ context 'PII' do # Redundant given the next spec, but going for clarity! - PII.each do |k, _| + pii.each do |k, _| it "removes #{k}" do expect(subject.attributes[k]).to eq nil end @@ -90,7 +90,7 @@ context 'PII' do # Redundant given the next spec, but going for clarity! - PII.each do |k, _| + pii.each do |k, _| it "removes #{k}" do expect(subject.attributes[k]).to eq nil end diff --git a/spec/services/schools/dfe_sign_in_api/client_spec.rb b/spec/services/schools/dfe_sign_in_api/client_spec.rb index c155849ccb..256a7d3e45 100644 --- a/spec/services/schools/dfe_sign_in_api/client_spec.rb +++ b/spec/services/schools/dfe_sign_in_api/client_spec.rb @@ -1,5 +1,19 @@ require 'rails_helper' +class TestAPI < Schools::DFESignInAPI::Client + def data + response + end + +private + + def endpoint + URI::HTTPS.build \ + host: "some-test-api-host.signin.education.gov.uk", + path: '/testapi' + end +end + describe Schools::DFESignInAPI::Client do describe '.enabled?' do context 'when setting is on and all required environment variables are present' do @@ -95,20 +109,6 @@ receive(:enabled?).and_return true end - class TestAPI < Schools::DFESignInAPI::Client - def data - response - end - - private - - def endpoint - URI::HTTPS.build \ - host: "some-test-api-host.signin.education.gov.uk", - path: '/testapi' - end - end - subject { TestAPI.new.data } { diff --git a/spec/support/rate_limiting_support.rb b/spec/support/rate_limiting_support.rb index c516366389..8eca127724 100644 --- a/spec/support/rate_limiting_support.rb +++ b/spec/support/rate_limiting_support.rb @@ -1,6 +1,6 @@ -include ActiveSupport::Testing::TimeHelpers - shared_examples "an IP-based rate limited endpoint" do |desc, limit, period| + include ActiveSupport::Testing::TimeHelpers + describe desc do let(:memory_store) { ActiveSupport::Cache.lookup_store(:memory_store) } diff --git a/spec/validators/email_format_validator_spec.rb b/spec/validators/email_format_validator_spec.rb index 06d4e9b9c5..48cb3c699a 100644 --- a/spec/validators/email_format_validator_spec.rb +++ b/spec/validators/email_format_validator_spec.rb @@ -1,12 +1,13 @@ require 'rails_helper' -describe EmailFormatValidator do - class TestModel - include ActiveModel::Model - attr_accessor :email_address - validates :email_address, email_format: true - end +class TestModel + include ActiveModel::Model + attr_accessor :email_address + validates :email_address, email_format: true +end + +describe EmailFormatValidator do before { instance.valid? } subject { instance.errors.to_hash }