From c6abf1962d07c9d05a7fb4257657321f1b7dbe52 Mon Sep 17 00:00:00 2001
From: sarahcrack <73823091+sarahcrack@users.noreply.github.com>
Date: Mon, 18 Nov 2024 15:27:52 +0000
Subject: [PATCH] created a todo list to ignore for now, to be fixed in future
---
.rubocop.yml | 7 +
.rubocop_todo.yml | 241 ++++++++++++++++++
app/models/bookings/booking.rb | 2 +-
.../bookings/data/school_mass_importer.rb | 2 +-
.../bookings/gitis/school_experience.rb | 2 +-
.../initializers/filter_active_job_logging.rb | 2 +-
...ique_index_to_bookings_schools_subjects.rb | 2 +-
.../20190205164245_create_delayed_jobs.rb | 2 +-
...15105333_create_schools_school_profiles.rb | 1 -
.../20190430134049_remove_phases_subjects.rb | 6 +-
..._add_bookings_booking_acceptance_fields.rb | 2 +-
db/schema.rb | 90 +++----
.../application_preview_steps.rb | 32 +--
.../subject_and_date_information_steps.rb | 2 +-
.../registrations/verify_your_email_steps.rb | 2 +-
.../candidates/schools/results_steps.rb | 2 +-
.../schools/bookings_steps.rb | 4 +-
.../schools/cancelled_bookings_steps.rb | 2 +-
.../schools/placement_dates/index_steps.rb | 2 +-
.../placement_dates/placement_date_steps.rb | 6 +-
.../schools/placement_request_steps.rb | 2 +-
.../placement_requests/accept_steps.rb | 2 +-
.../schools/previous_bookings_steps.rb | 2 +-
lib/notify/notify_sync.rb | 4 +-
.../booking_feedbacks_controller_spec.rb | 16 +-
.../candidates/feedbacks_controller_spec.rb | 6 +-
.../cancellations_controller_spec.rb | 6 +-
.../application_previews_controller_spec.rb | 2 +-
...vailability_preferences_controller_spec.rb | 10 +-
.../background_checks_controller_spec.rb | 12 +-
.../confirmation_emails_controller_spec.rb | 14 +-
.../contact_informations_controller_spec.rb | 12 +-
.../educations_controller_spec.rb | 34 +--
.../personal_informations_controller_spec.rb | 14 +-
.../placement_preferences_controller_spec.rb | 10 +-
.../placement_requests_controller_spec.rb | 8 +-
...end_confirmation_emails_controller_spec.rb | 2 +-
.../registrations/sign_ins_controller_spec.rb | 20 +-
...t_and_date_informations_controller_spec.rb | 23 +-
.../teaching_preferences_controller_spec.rb | 22 +-
.../school_searches_controller_spec.rb | 1 +
.../candidates/schools_controller_spec.rb | 16 +-
.../candidates/sessions_controller_spec.rb | 7 +-
.../concerns/dfe_authentication_spec.rb | 63 +++--
.../cookie_preferences_controller_spec.rb | 9 +-
spec/controllers/features_controller_spec.rb | 4 +-
.../healthchecks_controller_spec.rb | 2 +-
spec/controllers/pages_controller_spec.rb | 4 +-
...ived_placement_requests_controller_spec.rb | 6 +-
.../cancelled_bookings_controller_spec.rb | 2 +
.../schools/change_schools_controller_spec.rb | 30 ++-
.../confirm_attendance_controller_spec.rb | 21 +-
...notification_deliveries_controller_spec.rb | 4 +-
.../cancellations_controller_spec.rb | 8 +-
.../date_controller_spec.rb | 18 +-
.../confirmed_bookings_controller_spec.rb | 1 +
spec/controllers/schools/contact_us_spec.rb | 10 +-
.../schools/csv_exports_controller_spec.rb | 4 +-
.../schools/dashboards_controller_spec.rb | 10 +-
...insufficient_privileges_controller_spec.rb | 4 +-
.../schools/feedbacks_controller_spec.rb | 6 +-
.../access_needs_details_controller_spec.rb | 19 +-
.../access_needs_policies_controller_spec.rb | 19 +-
.../access_needs_supports_controller_spec.rb | 8 +-
.../admin_contacts_controller_spec.rb | 8 +-
.../administration_fees_controller_spec.rb | 8 +-
.../candidate_dress_codes_controller_spec.rb | 8 +-
...te_experience_schedules_controller_spec.rb | 8 +-
...te_parking_informations_controller_spec.rb | 8 +-
...requirements_selections_controller_spec.rb | 8 +-
.../confirmations_controller_spec.rb | 4 +-
.../on_boarding/dbs_fees_controller_spec.rb | 8 +-
.../dbs_requirements_controller_spec.rb | 8 +-
.../descriptions_controller_spec.rb | 8 +-
.../disability_confidents_controller_spec.rb | 19 +-
.../experience_outlines_controller_spec.rb | 8 +-
.../on_boarding/fees_controller_spec.rb | 11 +-
.../key_stage_lists_controller_spec.rb | 8 +-
.../on_boarding/other_fees_controller_spec.rb | 8 +-
.../phases_lists_controller_spec.rb | 8 +-
.../on_boarding/previews_controller_spec.rb | 2 +-
.../on_boarding/profiles_controller_spec.rb | 2 +-
.../on_boarding/progresses_controller_spec.rb | 2 +-
.../on_boarding/subjects_controller_spec.rb | 21 +-
.../teacher_trainings_controller_spec.rb | 8 +-
...isation_access_requests_controller_spec.rb | 4 +-
.../configurations_controller_spec.rb | 6 +-
.../placement_details_controller_spec.rb | 4 +-
.../publish_dates_controller_spec.rb | 4 +-
.../recurrences_selections_controller_spec.rb | 4 +-
.../review_recurrences_controller_spec.rb | 4 +-
.../subject_selections_controller_spec.rb | 4 +-
.../placement_dates_controller_spec.rb | 4 +-
.../confirm_booking_controller_spec.rb | 3 +-
.../make_changes_controller_spec.rb | 8 +-
...view_confirmation_email_controller_spec.rb | 7 +-
...notification_deliveries_controller_spec.rb | 4 +-
.../cancellations_controller_spec.rb | 8 +-
.../past_attendance_controller_spec.rb | 10 +-
.../under_consideration_controller_spec.rb | 6 +-
.../placement_requests_controller_spec.rb | 11 +-
...opulate_school_profiles_controller_spec.rb | 6 +-
.../previous_bookings_controller_spec.rb | 1 +
.../rejected_requests_controller_spec.rb | 1 +
.../schools/sessions_controller_spec.rb | 41 +--
.../schools/switch_controller_spec.rb | 9 +-
.../withdrawn_requests_controller_spec.rb | 1 +
spec/controllers/schools_controller_spec.rb | 16 +-
spec/factories/api_factory.rb | 6 +-
.../bookings/placement_request_factory.rb | 2 +-
spec/factories/bookings/school_factory.rb | 2 +-
spec/factories/candidates/feedback.rb | 2 +-
.../availability_preference_factory.rb | 2 +-
.../registrations/background_check_factory.rb | 2 +-
.../contact_information_factory.rb | 2 +-
.../registrations/education_factory.rb | 2 +-
.../gitis_registration_session_factory.rb | 2 +-
.../legacy_registration_session.rb | 2 +-
.../personal_information_factory.rb | 2 +-
.../placement_preference_factory.rb | 2 +-
.../registration_session_factory.rb | 2 +-
.../subject_and_date_information_factory.rb | 2 +-
.../teaching_preference_factory.rb | 2 +-
spec/factories/schools/feedback.rb | 2 +-
.../access_needs_detail_factory.rb | 2 +-
.../access_needs_policy_factory.rb | 2 +-
.../access_needs_support_factory.rb | 2 +-
.../on_boarding/admin_contact_factory.rb | 2 +-
.../on_boarding/administration_fee_factory.rb | 2 +-
.../candidate_requirement_factory.rb | 2 +-
...andidate_requirements_selection_factory.rb | 2 +-
.../on_boarding/confirmation_factory.rb | 2 +-
.../schools/on_boarding/dbs_fee_factory.rb | 2 +-
.../on_boarding/dbs_requirement_factory.rb | 2 +-
.../on_boarding/description_factory.rb | 2 +-
.../disability_confident_factory.rb | 2 +-
.../on_boarding/experience_outline_factory.rb | 2 +-
.../schools/on_boarding/fees_factory.rb | 2 +-
.../on_boarding/key_stage_list_factory.rb | 2 +-
.../schools/on_boarding/other_fee_factory.rb | 2 +-
.../on_boarding/phases_list_factory.rb | 2 +-
.../on_boarding/teacher_training_factory.rb | 2 +-
.../candidates/api_registrations_spec.rb | 32 +--
spec/features/cookie_preferences_spec.rb | 6 +-
spec/forms/schools/csv_export_form_spec.rb | 4 +-
.../on_boarding/access_needs_policy_spec.rb | 2 +
.../candidate_experience_schedule_spec.rb | 8 +-
.../candidate_parking_information_spec.rb | 2 +
.../on_boarding/candidate_requirement_spec.rb | 6 +-
.../candidate_requirements_selection_spec.rb | 9 +-
.../schools/on_boarding/current_step_spec.rb | 2 +-
.../forms/schools/on_boarding/dbs_fee_spec.rb | 2 +-
.../on_boarding/dbs_requirement_spec.rb | 24 +-
.../on_boarding/experience_outline_spec.rb | 6 +-
spec/forms/schools/on_boarding/fees_spec.rb | 2 +-
.../on_boarding/from_bookings_school_spec.rb | 6 +-
.../on_boarding/key_stage_list_spec.rb | 10 +-
.../schools/on_boarding/phases_list_spec.rb | 16 +-
.../schools/on_boarding/subject_list_spec.rb | 14 +-
.../on_boarding/teacher_training_spec.rb | 8 +-
spec/forms/schools/on_boarding/wizard_spec.rb | 12 +-
.../configuration_form_spec.rb | 17 +-
.../placement_dates/placement_detail_spec.rb | 36 +--
.../recurrences_selection_spec.rb | 38 +--
.../placement_dates/subject_selection_spec.rb | 8 +-
spec/helpers/application_helper_spec.rb | 16 +-
spec/helpers/candidates/maps_helper_spec.rb | 18 +-
...ubject_and_date_information_helper_spec.rb | 6 +-
.../helpers/candidates/results_helper_spec.rb | 6 +-
spec/helpers/candidates/school_helper_spec.rb | 79 +++---
spec/helpers/link_and_button_helper_spec.rb | 19 +-
spec/helpers/schools/bookings_helper_spec.rb | 9 +-
.../helpers/schools/dashboards_helper_spec.rb | 30 ++-
.../schools/placement_requests_helper_spec.rb | 4 +-
spec/helpers/text_formatting_helper_spec.rb | 8 +-
spec/jobs/bookings/reminder_job_spec.rb | 7 +-
.../placement_request_job_spec.rb | 2 +-
.../send_email_confirmation_job_spec.rb | 2 +-
spec/jobs/cron/heart_beat_job_spec.rb | 4 +-
.../cron/identify_closed_schools_job_spec.rb | 4 +-
.../reminders/add_availability_job_spec.rb | 4 +-
.../jobs/cron/reminders/next_week_job_spec.rb | 4 +-
spec/jobs/cron/reminders/tomorrow_job_spec.rb | 4 +-
...nd_entity_table_checks_to_bigquery_spec.rb | 4 +-
spec/jobs/cron/sync_schools_job_spec.rb | 4 +-
spec/jobs/notify_job_spec.rb | 6 +-
spec/lib/academic_year_spec.rb | 4 +
spec/lib/cloud_front_ip_filter_spec.rb | 4 +-
spec/lib/conversions_spec.rb | 4 +-
spec/lib/encryptor_spec.rb | 4 +-
spec/lib/geocoder_autoexpire_cache_spec.rb | 11 +-
spec/lib/geocoding_response_country_spec.rb | 18 +-
spec/lib/notify/notify_sync_spec.rb | 80 +++---
spec/lib/placement_request_transfer_spec.rb | 4 +-
spec/models/bookings/booking_spec.rb | 85 +++---
spec/models/bookings/candidate_spec.rb | 164 ++++++------
.../bookings/data/gias_data_file_spec.rb | 68 ++---
.../bookings/data/gias_reconciler_spec.rb | 8 +-
.../bookings/data/school_manager_spec.rb | 4 +-
.../data/school_mass_importer_spec.rb | 16 +-
spec/models/bookings/phase_spec.rb | 7 +-
spec/models/bookings/placement_date_spec.rb | 76 +++---
.../bookings/placement_date_subject_spec.rb | 9 +-
.../placement_request/cancellation_spec.rb | 21 +-
.../models/bookings/placement_request_spec.rb | 180 +++++++------
.../profile_attributes_convertor_spec.rb | 30 ++-
.../models/bookings/profile_publisher_spec.rb | 20 +-
spec/models/bookings/profile_spec.rb | 21 ++
.../registration_contact_mapper_spec.rb | 20 +-
spec/models/bookings/school_search_spec.rb | 127 ++++-----
spec/models/bookings/school_spec.rb | 73 +++---
spec/models/bookings/school_sync_spec.rb | 9 +-
spec/models/bookings/school_type_spec.rb | 2 +-
spec/models/bookings/schools_phase_spec.rb | 8 +-
spec/models/bookings/schools_subject_spec.rb | 6 +-
spec/models/bookings/subject_spec.rb | 38 +--
.../candidates/booking_feedback_spec.rb | 6 +-
spec/models/candidates/school_search_spec.rb | 84 +++---
spec/models/candidates/school_spec.rb | 14 +-
spec/models/candidates/session_spec.rb | 9 +-
spec/models/candidates/session_token_spec.rb | 49 ++--
.../candidates/verification_code_spec.rb | 4 +-
.../concerns/encrypted_attributes_spec.rb | 6 +-
.../models/concerns/geographic_search_spec.rb | 3 +-
spec/models/concerns/yaml_model_spec.rb | 12 +-
spec/models/cookie_preference_spec.rb | 35 ++-
spec/models/event_spec.rb | 4 +
spec/models/feature_spec.rb | 10 +-
spec/models/healthcheck_spec.rb | 21 +-
.../models/schools/attendance_records_spec.rb | 10 +-
spec/models/schools/attendance_spec.rb | 23 +-
spec/models/schools/change_school_spec.rb | 22 +-
spec/models/schools/csv_export_spec.rb | 16 +-
.../prepopulate_school_profile_spec.rb | 15 +-
spec/models/schools/school_profile_spec.rb | 148 +++++------
spec/models/user_spec.rb | 3 +-
spec/notify/notify_despatchers/notify_spec.rb | 28 +-
.../candidate_booking_cancellation_spec.rb | 2 +-
.../candidate_booking_confirmation_spec.rb | 22 +-
.../candidate_booking_date_changed_spec.rb | 26 +-
.../candidate_booking_feedback_spec.rb | 6 +-
.../candidate_booking_reminder_spec.rb | 30 +--
...ate_booking_school_cancels_booking_spec.rb | 2 +-
.../notify_email/candidate_magic_link_spec.rb | 2 +-
.../candidate_request_cancellation_spec.rb | 2 +-
...didate_request_confirmation_no_pii_spec.rb | 17 +-
.../candidate_request_rejection_spec.rb | 2 +-
.../candidate_verify_email_link_spec.rb | 2 +-
...al_experience_booking_confirmation_spec.rb | 22 +-
...al_experience_booking_date_changed_spec.rb | 24 +-
...irtual_experience_booking_reminder_spec.rb | 30 +--
.../closed_onboarded_schools_summary_spec.rb | 2 +-
.../school_add_availability_reminder_spec.rb | 2 +-
.../school_booking_cancellation_spec.rb | 2 +-
.../school_registration_confirmation_spec.rb | 2 +-
.../school_request_cancellation_spec.rb | 2 +-
...ool_request_confirmation_link_only_spec.rb | 2 +-
.../notify_email/school_user_invite_spec.rb | 2 +-
.../teacher_booking_cancellation_spec.rb | 2 +-
.../teacher_booking_confirmation_spec.rb | 2 +-
spec/notify/notify_service_spec.rb | 6 +-
.../candidate_booking_confirmation_spec.rb | 2 +-
.../candidate_booking_reminder_spec.rb | 2 +-
...ate_booking_school_cancels_booking_spec.rb | 2 +-
.../candidates/placement_presenter_spec.rb | 5 +-
.../candidates/school_presenter_spec.rb | 17 +-
spec/presenters/facet_tags_presenter_spec.rb | 2 +-
.../on_boarding/preview_presenter_spec.rb | 2 +-
.../school_profile_presenter_spec.rb | 50 ++--
spec/rails_helper.rb | 6 +-
spec/requests/basic_auth_spec.rb | 10 +-
spec/requests/cookie_banner_spec.rb | 1 +
spec/requests/session_expired_spec.rb | 10 +-
spec/requests/tracking_scripts_spec.rb | 10 +-
.../bookings/gitis/contact_fetcher_spec.rb | 44 ++--
.../bookings/gitis/missing_contact_spec.rb | 3 +-
.../bookings/gitis/school_experience_spec.rb | 24 +-
.../bookings/gitis/subject_fetcher_spec.rb | 2 +
spec/services/bookings/reminder_spec.rb | 8 +-
.../registrations/application_preview_spec.rb | 46 ++--
.../availability_preference_spec.rb | 10 +-
.../registrations/contact_information_spec.rb | 16 +-
.../registrations/education_spec.rb | 8 +-
.../gitis_registration_session_spec.rb | 5 +-
.../personal_information_spec.rb | 20 +-
.../placement_preference_spec.rb | 10 +-
.../registration_as_placement_request_spec.rb | 13 +-
.../registration_session_spec.rb | 46 ++--
.../registrations/registration_state_spec.rb | 6 +-
.../registrations/registration_store_spec.rb | 22 +-
.../subject_and_date_information_spec.rb | 52 ++--
.../registrations/teaching_preference_spec.rb | 18 +-
.../schools/dfe_sign_in_api/client_spec.rb | 25 +-
.../dfe_sign_in_api/organisation_spec.rb | 4 +-
.../dfe_sign_in_api/organisations_spec.rb | 6 +-
.../role_checked_organisations_spec.rb | 10 +-
.../schools/dfe_sign_in_api/roles_spec.rb | 13 +-
spec/support/feedback_shared_examples.rb | 10 +-
spec/support/notify_email_shared_examples.rb | 45 ++--
spec/support/rate_limiting_support.rb | 4 +-
.../registration_step_shared_examples.rb | 28 +-
.../on_boarding/school_fee_shared_examples.rb | 6 +-
.../validators/email_format_validator_spec.rb | 7 +-
.../number_of_words_validator_spec.rb | 2 +-
spec/validators/website_validator_spec.rb | 4 +-
.../candidates/home/index.html.erb_spec.rb | 17 +-
.../_form.html.erb_spec.rb | 16 +-
.../sign_ins/show.html.erb_spec.rb | 2 +-
.../sign_ins/update.html.erb_spec.rb | 2 +-
.../candidates/schools/index.html.erb_spec.rb | 17 +-
.../candidates/schools/show.html.erb_spec.rb | 8 +-
.../sessions/create.html.erb_spec.rb | 2 +-
.../candidates/sessions/new.html.erb_spec.rb | 4 +-
.../sessions/update.html.erb_spec.rb | 2 +-
.../change_schools/show.html.erb_spec.rb | 40 +--
.../schools/dashboards/show.html.erb_spec.rb | 9 +-
.../schools/switch/show.html.erb_spec.rb | 7 +-
317 files changed, 2476 insertions(+), 1971 deletions(-)
create mode 100644 .rubocop_todo.yml
diff --git a/.rubocop.yml b/.rubocop.yml
index 5ddfc0dbb4..7b3448d5b5 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -1,3 +1,5 @@
+inherit_from: .rubocop_todo.yml
+
require:
- rubocop-rspec
- rubocop-capybara
@@ -108,3 +110,8 @@ Rails/TimeZone:
Rails/Date:
Enabled: false
+
+AllCops:
+ Exclude:
+ - "node_modules/**/*"
+ - "vendor/**/*"
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml
new file mode 100644
index 0000000000..5c495af513
--- /dev/null
+++ b/.rubocop_todo.yml
@@ -0,0 +1,241 @@
+# This configuration was generated by
+# `rubocop --auto-gen-config`
+# on 2024-11-18 15:25:34 UTC using RuboCop version 1.68.0.
+# The point is for the user to remove these configuration records
+# one by one as the offenses are removed from the code base.
+# Note that changes in the inspected code, or installation of new
+# versions of RuboCop, may require this file to be generated again.
+
+# Offense count: 41
+# This cop supports safe autocorrection (--autocorrect).
+Capybara/CurrentPathExpectation:
+ Enabled: false
+
+# Offense count: 1
+Capybara/VisibilityMatcher:
+ Exclude:
+ - 'features/step_definitions/candidates/schools/filtering_steps.rb'
+
+# Offense count: 1
+# Configuration parameters: DebuggerMethods, DebuggerRequires.
+Lint/Debugger:
+ Exclude:
+ - 'features/step_definitions/common_steps.rb'
+
+# Offense count: 88
+RSpec/AnyInstance:
+ Enabled: false
+
+# Offense count: 616
+# Configuration parameters: Prefixes, AllowedPatterns.
+# Prefixes: when, with, without
+RSpec/ContextWording:
+ Enabled: false
+
+# Offense count: 73
+# Configuration parameters: CountAsOne.
+RSpec/ExampleLength:
+ Max: 31
+
+# Offense count: 4
+RSpec/ExpectInHook:
+ Exclude:
+ - 'spec/controllers/candidates/registrations/sign_ins_controller_spec.rb'
+ - 'spec/jobs/notify_job_spec.rb'
+ - 'spec/services/bookings/gitis/school_experience_spec.rb'
+
+# Offense count: 36
+# Configuration parameters: Max, AllowedIdentifiers, AllowedPatterns.
+RSpec/IndexedLet:
+ Exclude:
+ - 'spec/helpers/candidates/school_helper_spec.rb'
+ - 'spec/jobs/cron/identify_closed_schools_job_spec.rb'
+ - 'spec/models/bookings/data/gias_reconciler_spec.rb'
+ - 'spec/models/bookings/data/school_updater_spec.rb'
+ - 'spec/models/bookings/placement_request_spec.rb'
+ - 'spec/models/candidates/school_search_spec.rb'
+ - 'spec/models/schools/attendance_spec.rb'
+ - 'spec/services/schools/dfe_sign_in_api/role_checked_organisations_spec.rb'
+
+# Offense count: 89
+# Configuration parameters: AssignmentOnly.
+RSpec/InstanceVariable:
+ Enabled: false
+
+# Offense count: 72
+RSpec/LetSetup:
+ Enabled: false
+
+# Offense count: 4
+RSpec/MessageChain:
+ Exclude:
+ - 'spec/models/bookings/placement_date_spec.rb'
+ - 'spec/services/candidates/registrations/dbs_requirments_checker_spec.rb'
+
+# Offense count: 21
+# Configuration parameters: EnforcedStyle.
+# SupportedStyles: have_received, receive
+RSpec/MessageSpies:
+ Exclude:
+ - 'spec/controllers/schools/sessions_controller_spec.rb'
+ - 'spec/jobs/cron/identify_closed_schools_job_spec.rb'
+ - 'spec/lib/notify/notify_sync_spec.rb'
+ - 'spec/models/bookings/booking_spec.rb'
+ - 'spec/models/bookings/school_search_spec.rb'
+ - 'spec/services/schools/dfe_sign_in_api/user_invite_spec.rb'
+ - 'spec/validators/website_validator_spec.rb'
+
+# Offense count: 2
+RSpec/MultipleDescribes:
+ Exclude:
+ - 'spec/jobs/notify_job_spec.rb'
+ - 'spec/notify/notify_despatchers/notify_spec.rb'
+
+# Offense count: 164
+RSpec/MultipleExpectations:
+ Max: 11
+
+# Offense count: 362
+# Configuration parameters: AllowSubject.
+RSpec/MultipleMemoizedHelpers:
+ Max: 15
+
+# Offense count: 1285
+# Configuration parameters: EnforcedStyle, IgnoreSharedExamples.
+# SupportedStyles: always, named_only
+RSpec/NamedSubject:
+ Enabled: false
+
+# Offense count: 706
+# Configuration parameters: AllowedGroups.
+RSpec/NestedGroups:
+ Max: 6
+
+# Offense count: 4
+# Configuration parameters: AllowedPatterns.
+# AllowedPatterns: ^expect_, ^assert_
+RSpec/NoExpectationExample:
+ Exclude:
+ - 'spec/features/candidates/api_registrations_spec.rb'
+ - 'spec/services/bookings/gitis/school_experience_spec.rb'
+
+# Offense count: 2
+RSpec/OverwritingSetup:
+ Exclude:
+ - 'spec/forms/schools/placement_dates/placement_detail_spec.rb'
+ - 'spec/models/schools/change_school_spec.rb'
+
+# Offense count: 6
+RSpec/PendingWithoutReason:
+ Exclude:
+ - 'spec/controllers/healthchecks_controller_spec.rb'
+
+# Offense count: 10
+RSpec/RepeatedDescription:
+ Exclude:
+ - 'spec/controllers/schools/placement_requests_controller_spec.rb'
+ - 'spec/views/candidates/registrations/personal_informations/_form.html.erb_spec.rb'
+
+# Offense count: 5
+RSpec/RepeatedExample:
+ Exclude:
+ - 'spec/models/bookings/school_search_spec.rb'
+ - 'spec/services/bookings/gitis/missing_contact_spec.rb'
+
+# Offense count: 2
+RSpec/RepeatedExampleGroupBody:
+ Exclude:
+ - 'spec/services/candidates/registrations/dbs_requirments_checker_spec.rb'
+
+# Offense count: 14
+RSpec/RepeatedExampleGroupDescription:
+ Exclude:
+ - 'spec/controllers/healthchecks_controller_spec.rb'
+ - 'spec/lib/conversions_spec.rb'
+ - 'spec/models/bookings/booking_spec.rb'
+ - 'spec/models/bookings/schools_phase_spec.rb'
+ - 'spec/models/cookie_preference_spec.rb'
+ - 'spec/presenters/candidates/school_presenter_spec.rb'
+ - 'spec/services/candidates/registrations/subject_and_date_information_spec.rb'
+
+# Offense count: 4
+# This cop supports safe autocorrection (--autocorrect).
+# Configuration parameters: AutoCorrect.
+RSpec/ScatteredSetup:
+ Exclude:
+ - 'spec/controllers/schools/placement_requests_controller_spec.rb'
+
+# Offense count: 5
+# Configuration parameters: Include, CustomTransform, IgnoreMethods, IgnoreMetadata.
+# Include: **/*_spec.rb
+RSpec/SpecFilePathFormat:
+ Exclude:
+ - 'spec/controllers/features_controller_spec.rb'
+ - 'spec/controllers/schools/contact_us_spec.rb'
+ - 'spec/controllers/schools/switch_controller_spec.rb'
+ - 'spec/jobs/cron/send_entity_table_checks_to_bigquery_spec.rb'
+ - 'spec/notify/notify_email/candidate_booking_feedback_spec.rb'
+
+# Offense count: 1
+RSpec/StubbedMock:
+ Exclude:
+ - 'spec/services/bookings/reminder_spec.rb'
+
+# Offense count: 50
+RSpec/SubjectStub:
+ Exclude:
+ - 'spec/forms/schools/placement_dates/placement_detail_spec.rb'
+ - 'spec/lib/notify/notify_sync_spec.rb'
+ - 'spec/models/bookings/data/gias_data_file_spec.rb'
+ - 'spec/models/bookings/placement_request_spec.rb'
+ - 'spec/models/bookings/school_search_spec.rb'
+ - 'spec/models/bookings/school_spec.rb'
+ - 'spec/models/bookings/school_sync_spec.rb'
+ - 'spec/presenters/candidates/placement_presenter_spec.rb'
+ - 'spec/services/candidates/registrations/subject_and_date_information_spec.rb'
+ - 'spec/services/schools/dfe_sign_in_api/client_spec.rb'
+ - 'spec/services/schools/dfe_sign_in_api/organisation_spec.rb'
+ - 'spec/services/schools/dfe_sign_in_api/organisations_spec.rb'
+ - 'spec/services/schools/dfe_sign_in_api/roles_spec.rb'
+ - 'spec/support/registration_step_shared_examples.rb'
+
+# Offense count: 43
+# Configuration parameters: IgnoreNameless, IgnoreSymbolicNames.
+RSpec/VerifiedDoubles:
+ Enabled: false
+
+# Offense count: 36
+# Configuration parameters: Database, Include.
+# SupportedDatabases: mysql, postgresql
+# Include: db/**/*.rb
+Rails/BulkChangeTable:
+ Enabled: false
+
+# Offense count: 8
+# Configuration parameters: Database, Include.
+# SupportedDatabases: mysql
+# Include: db/**/*.rb
+Rails/NotNullColumn:
+ Exclude:
+ - 'db/migrate/20190131110800_add_importable_fields_to_bookings_schools.rb'
+ - 'db/migrate/20190205091721_add_bookings_school_type_id_to_bookings_schools.rb'
+ - 'db/migrate/20190225114124_add_availability_to_placement_requests.rb'
+ - 'db/migrate/20190417081149_add_bookings_school_id_to_schools_school_profile.rb'
+ - 'db/migrate/20190426154201_link_bookings_placement_dates_to_bookings_schools.rb'
+ - 'db/migrate/20190524133255_add_cancelled_by_to_cancellations.rb'
+
+# Offense count: 12
+# Configuration parameters: Include.
+# Include: db/**/*.rb
+Rails/ReversibleMigration:
+ Exclude:
+ - 'db/migrate/20190125085522_make_bookings_schools_fees_default_to_zero.rb'
+ - 'db/migrate/20190125144531_make_subject_and_phase_names_not_nullable.rb'
+ - 'db/migrate/20190225092622_remove_access_needs_and_access_needs_details_from_candidates_registrations_placmenet_requests.rb'
+ - 'db/migrate/20190418180420_allow_bookings_placement_requests_availability_to_be_null.rb'
+ - 'db/migrate/20190426154201_link_bookings_placement_dates_to_bookings_schools.rb'
+ - 'db/migrate/20190510173936_allow_null_for_bookings_profiles_experience_details.rb'
+ - 'db/migrate/20190628082805_set_bookings_schools_enabeld_flag_to_false_by_default.rb'
+ - 'db/migrate/20190724092556_make_bookings_school_contact_email_not_null.rb'
+ - 'db/migrate/20190820073225_make_bookings_profile_dbs_required_nullable.rb'
+ - 'db/migrate/20191031105854_remove_column_default_from_bookings_placement_dates_subject_specific.rb'
diff --git a/app/models/bookings/booking.rb b/app/models/bookings/booking.rb
index 094b918852..f9b2502c9c 100644
--- a/app/models/bookings/booking.rb
+++ b/app/models/bookings/booking.rb
@@ -158,7 +158,7 @@ def populate_contact_details
delegate :status, to: :bookings_placement_request
def placement_start_date_with_duration
- if bookings_placement_request&.placement_date&.present?
+ if bookings_placement_request&.placement_date.present?
[date.to_formatted_s(:govuk), 'for', duration_days].join(' ')
else
date.to_formatted_s(:govuk)
diff --git a/app/models/bookings/data/school_mass_importer.rb b/app/models/bookings/data/school_mass_importer.rb
index 78977c1837..85c8127510 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/services/bookings/gitis/school_experience.rb b/app/services/bookings/gitis/school_experience.rb
index 4bccdba2e5..1e1aa6dd78 100644
--- a/app/services/bookings/gitis/school_experience.rb
+++ b/app/services/bookings/gitis/school_experience.rb
@@ -61,7 +61,7 @@ def from_cancellation(cancellation, status)
date: (cancellation.booking || cancellation.placement_request.placement_date)&.date,
urn: cancellation.school_urn,
school_name: cancellation.school_name,
- teaching_subject_name: (cancellation.booking&.bookings_subject&.name || cancellation.placement_request.subject_first_choice),
+ teaching_subject_name: cancellation.booking&.bookings_subject&.name || cancellation.placement_request.subject_first_choice,
duration: (cancellation.booking || cancellation.placement_request.placement_date)&.duration,
status: status
)
diff --git a/config/initializers/filter_active_job_logging.rb b/config/initializers/filter_active_job_logging.rb
index b8b1370c58..72ebb2512d 100644
--- a/config/initializers/filter_active_job_logging.rb
+++ b/config/initializers/filter_active_job_logging.rb
@@ -2,7 +2,7 @@
unless Rails.env.development?
class ActiveJob::Logging::LogSubscriber
- # activejob-5.2.3/lib/active_job/logging.rb
+ # activejob-5.2.3/lib/active_job/logging.rb
private
diff --git a/db/migrate/20190124124111_add_unique_index_to_bookings_schools_subjects.rb b/db/migrate/20190124124111_add_unique_index_to_bookings_schools_subjects.rb
index c75b5baaf8..6be8f5adc5 100644
--- a/db/migrate/20190124124111_add_unique_index_to_bookings_schools_subjects.rb
+++ b/db/migrate/20190124124111_add_unique_index_to_bookings_schools_subjects.rb
@@ -1,7 +1,7 @@
class AddUniqueIndexToBookingsSchoolsSubjects < ActiveRecord::Migration[5.2]
def change
add_index :bookings_schools_subjects,
- %i{bookings_school_id bookings_subject_id},
+ %i[bookings_school_id bookings_subject_id],
unique: true,
name: "index_bookings_schools_subjects_school_id_and_subject_id"
end
diff --git a/db/migrate/20190205164245_create_delayed_jobs.rb b/db/migrate/20190205164245_create_delayed_jobs.rb
index d10f2400e7..d734750cc8 100644
--- a/db/migrate/20190205164245_create_delayed_jobs.rb
+++ b/db/migrate/20190205164245_create_delayed_jobs.rb
@@ -13,7 +13,7 @@ def self.up
table.timestamps null: true
end
- add_index :delayed_jobs, [:priority, :run_at], name: "delayed_jobs_priority"
+ add_index :delayed_jobs, %i[priority run_at], name: "delayed_jobs_priority"
end
def self.down
diff --git a/db/migrate/20190315105333_create_schools_school_profiles.rb b/db/migrate/20190315105333_create_schools_school_profiles.rb
index 9c8df6143c..4d3e2356df 100644
--- a/db/migrate/20190315105333_create_schools_school_profiles.rb
+++ b/db/migrate/20190315105333_create_schools_school_profiles.rb
@@ -1,7 +1,6 @@
class CreateSchoolsSchoolProfiles < ActiveRecord::Migration[5.2]
def change
create_table :schools_school_profiles do |t|
-
t.timestamps
t.integer :urn, null: false
t.string :candidate_requirement_dbs_requirement
diff --git a/db/migrate/20190430134049_remove_phases_subjects.rb b/db/migrate/20190430134049_remove_phases_subjects.rb
index 03ce1e1c88..128682602e 100644
--- a/db/migrate/20190430134049_remove_phases_subjects.rb
+++ b/db/migrate/20190430134049_remove_phases_subjects.rb
@@ -6,9 +6,9 @@ def change
t.bigint "bookings_subject_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
- t.index ["bookings_phase_id"], name: "index_schools_on_boarding_phase_subjects_on_bookings_phase_id"
- t.index ["bookings_subject_id"], name: "index_schools_on_boarding_phase_subjects_on_bookings_subject_id"
- t.index ["schools_school_profile_id"], name: "index_phase_subjects_on_school_profile_id"
+ t.index %w[bookings_phase_id], name: "index_schools_on_boarding_phase_subjects_on_bookings_phase_id"
+ t.index %w[bookings_subject_id], name: "index_schools_on_boarding_phase_subjects_on_bookings_subject_id"
+ t.index %w[schools_school_profile_id], name: "index_phase_subjects_on_school_profile_id"
end
end
end
diff --git a/db/migrate/20190531141719_add_bookings_booking_acceptance_fields.rb b/db/migrate/20190531141719_add_bookings_booking_acceptance_fields.rb
index 227df8e2d2..4e3b2cae8f 100644
--- a/db/migrate/20190531141719_add_bookings_booking_acceptance_fields.rb
+++ b/db/migrate/20190531141719_add_bookings_booking_acceptance_fields.rb
@@ -3,7 +3,7 @@ def change
add_column :bookings_bookings, :placement_details, :text, null: true
add_column :bookings_bookings, :contact_name, :string, null: true
- add_column :bookings_bookings, :contact_number, :string, null: true
+ add_column :bookings_bookings, :contact_number, :string, null: true
add_column :bookings_bookings, :contact_email, :string, null: true
add_column :bookings_bookings, :location, :text, null: true
diff --git a/db/schema.rb b/db/schema.rb
index 095f91646c..536c92e188 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[7.0].define(version: 2022_11_04_080002) do
+ActiveRecord::Schema[7.0].define(version: 20_221_104_080_002) do
# These are extensions that must be enabled in order to support this database
enable_extension "address_standardizer"
enable_extension "plpgsql"
@@ -33,9 +33,9 @@
t.datetime "accepted_at", precision: nil
t.boolean "attended"
t.string "experience_type"
- t.index ["bookings_placement_request_id"], name: "index_bookings_bookings_on_bookings_placement_request_id", unique: true
- t.index ["bookings_school_id"], name: "index_bookings_bookings_on_bookings_school_id"
- t.index ["bookings_subject_id"], name: "index_bookings_bookings_on_bookings_subject_id"
+ t.index %w[bookings_placement_request_id], name: "index_bookings_bookings_on_bookings_placement_request_id", unique: true
+ t.index %w[bookings_school_id], name: "index_bookings_bookings_on_bookings_school_id"
+ t.index %w[bookings_subject_id], name: "index_bookings_bookings_on_bookings_subject_id"
end
create_table "bookings_candidates", force: :cascade do |t|
@@ -44,7 +44,7 @@
t.datetime "updated_at", precision: nil, null: false
t.datetime "confirmed_at", precision: nil
t.boolean "created_in_gitis", default: false
- t.index ["gitis_uuid"], name: "index_bookings_candidates_on_gitis_uuid", unique: true
+ t.index %w[gitis_uuid], name: "index_bookings_candidates_on_gitis_uuid", unique: true
end
create_table "bookings_phases", force: :cascade do |t|
@@ -54,8 +54,8 @@
t.integer "position"
t.integer "edubase_id"
t.boolean "supports_subjects", default: true, null: false
- t.index ["name"], name: "index_bookings_phases_on_name", unique: true
- t.index ["position"], name: "index_bookings_phases_on_position", unique: true
+ t.index %w[name], name: "index_bookings_phases_on_name", unique: true
+ t.index %w[position], name: "index_bookings_phases_on_position", unique: true
end
create_table "bookings_placement_date_subjects", force: :cascade do |t|
@@ -63,8 +63,8 @@
t.bigint "bookings_subject_id"
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false
- t.index ["bookings_placement_date_id"], name: "index_placement_date_subject_on_date_id"
- t.index ["bookings_subject_id"], name: "index_placement_date_subject_on_subject_id"
+ t.index %w[bookings_placement_date_id], name: "index_placement_date_subject_on_date_id"
+ t.index %w[bookings_subject_id], name: "index_placement_date_subject_on_subject_id"
end
create_table "bookings_placement_dates", force: :cascade do |t|
@@ -83,7 +83,7 @@
t.integer "start_availability_offset", default: 60, null: false
t.boolean "recurring", default: false
t.boolean "publishable", default: false
- t.index ["bookings_school_id"], name: "index_bookings_placement_dates_on_bookings_school_id"
+ t.index %w[bookings_school_id], name: "index_bookings_placement_dates_on_bookings_school_id"
end
create_table "bookings_placement_request_cancellations", force: :cascade do |t|
@@ -108,8 +108,8 @@
t.boolean "wrong_choice_secondary", default: false
t.boolean "wrong_choice_primary", default: false
t.boolean "other", default: false
- 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"
+ t.index %w[bookings_placement_request_id], name: "index_cancellations_on_bookings_placement_request_id", unique: true
+ t.index %w[rejection_category], name: "index_bookings_placement_request_cancellations_category"
end
create_table "bookings_placement_requests", force: :cascade do |t|
@@ -134,11 +134,11 @@
t.bigint "bookings_subject_id"
t.datetime "under_consideration_at", precision: nil
t.string "experience_type"
- t.index ["bookings_placement_date_id"], name: "index_bookings_placement_requests_on_bookings_placement_date_id"
- t.index ["bookings_school_id"], name: "index_bookings_placement_requests_on_bookings_school_id"
- t.index ["bookings_subject_id"], name: "index_bookings_placement_requests_on_bookings_subject_id"
- t.index ["candidate_id"], name: "index_bookings_placement_requests_on_candidate_id"
- t.index ["token"], name: "index_bookings_placement_requests_on_token", unique: true
+ t.index %w[bookings_placement_date_id], name: "index_bookings_placement_requests_on_bookings_placement_date_id"
+ t.index %w[bookings_school_id], name: "index_bookings_placement_requests_on_bookings_school_id"
+ t.index %w[bookings_subject_id], name: "index_bookings_placement_requests_on_bookings_subject_id"
+ t.index %w[candidate_id], name: "index_bookings_placement_requests_on_candidate_id"
+ t.index %w[token], name: "index_bookings_placement_requests_on_token", unique: true
end
create_table "bookings_profiles", force: :cascade do |t|
@@ -194,7 +194,7 @@
t.boolean "has_access_needs_policy"
t.string "access_needs_policy_url"
t.string "dbs_policy_conditions"
- t.index ["school_id"], name: "index_bookings_profiles_on_school_id", unique: true
+ t.index %w[school_id], name: "index_bookings_profiles_on_school_id", unique: true
end
create_table "bookings_school_searches", force: :cascade do |t|
@@ -206,7 +206,7 @@
t.integer "max_fee"
t.integer "page"
t.integer "number_of_results", default: 0
- t.geography "coordinates", limit: {:srid=>4326, :type=>"st_point", :geographic=>true}
+ t.geography "coordinates", limit: { srid: 4326, type: "st_point", geographic: true }
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false
t.uuid "analytics_tracking_uuid"
@@ -220,12 +220,12 @@
t.integer "edubase_id"
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false
- t.index ["name"], name: "index_bookings_school_types_on_name", unique: true
+ t.index %w[name], name: "index_bookings_school_types_on_name", unique: true
end
create_table "bookings_schools", force: :cascade do |t|
t.string "name", limit: 128, null: false
- t.geography "coordinates", limit: {:srid=>4326, :type=>"st_point", :geographic=>true}
+ t.geography "coordinates", limit: { srid: 4326, type: "st_point", geographic: true }
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false
t.integer "fee", default: 0, null: false
@@ -250,9 +250,9 @@
t.integer "views", default: 0, null: false
t.uuid "dfe_signin_organisation_uuid"
t.string "experience_type", default: "inschool", null: false
- t.index ["coordinates"], name: "index_bookings_schools_on_coordinates", using: :gist
- t.index ["name"], name: "index_bookings_schools_on_name"
- t.index ["urn"], name: "index_bookings_schools_on_urn", unique: true
+ t.index %w[coordinates], name: "index_bookings_schools_on_coordinates", using: :gist
+ t.index %w[name], name: "index_bookings_schools_on_name"
+ t.index %w[urn], name: "index_bookings_schools_on_urn", unique: true
end
create_table "bookings_schools_phases", force: :cascade do |t|
@@ -260,7 +260,7 @@
t.integer "bookings_phase_id", null: false
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false
- t.index ["bookings_school_id", "bookings_phase_id"], name: "index_bookings_schools_phases_school_id_and_phase_id", unique: true
+ t.index %w[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|
@@ -268,7 +268,7 @@
t.integer "bookings_subject_id", null: false
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false
- t.index ["bookings_school_id", "bookings_subject_id"], name: "index_bookings_schools_subjects_school_id_and_subject_id", unique: true
+ t.index %w[bookings_school_id bookings_subject_id], name: "index_bookings_schools_subjects_school_id_and_subject_id", unique: true
end
create_table "bookings_subjects", force: :cascade do |t|
@@ -277,8 +277,8 @@
t.datetime "updated_at", precision: nil, null: false
t.boolean "hidden", default: false
t.boolean "secondary_subject", default: true, null: false
- t.index ["hidden"], name: "index_bookings_subjects_on_hidden"
- t.index ["name"], name: "index_bookings_subjects_on_name", unique: true
+ t.index %w[hidden], name: "index_bookings_subjects_on_hidden"
+ t.index %w[name], name: "index_bookings_subjects_on_name", unique: true
end
create_table "candidates_booking_feedbacks", force: :cascade do |t|
@@ -290,7 +290,7 @@
t.integer "effect_on_decision"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
- t.index ["bookings_booking_id"], name: "index_candidates_booking_feedbacks_on_bookings_booking_id", unique: true
+ t.index %w[bookings_booking_id], name: "index_candidates_booking_feedbacks_on_bookings_booking_id", unique: true
end
create_table "candidates_session_tokens", force: :cascade do |t|
@@ -300,8 +300,8 @@
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false
t.datetime "confirmed_at", precision: nil
- t.index ["candidate_id"], name: "index_candidates_session_tokens_on_candidate_id"
- t.index ["token"], name: "index_candidates_session_tokens_on_token", unique: true
+ t.index %w[candidate_id], name: "index_candidates_session_tokens_on_candidate_id"
+ t.index %w[token], name: "index_candidates_session_tokens_on_token", unique: true
end
create_table "delayed_jobs", force: :cascade do |t|
@@ -317,7 +317,7 @@
t.datetime "created_at", precision: nil
t.datetime "updated_at", precision: nil
t.string "cron"
- t.index ["priority", "run_at"], name: "delayed_jobs_priority"
+ t.index %w[priority run_at], name: "delayed_jobs_priority"
end
create_table "events", force: :cascade do |t|
@@ -328,8 +328,8 @@
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false
t.integer "bookings_candidate_id"
- t.index ["bookings_candidate_id"], name: "index_events_on_bookings_candidate_id"
- t.index ["bookings_school_id"], name: "index_events_on_bookings_school_id"
+ t.index %w[bookings_candidate_id], name: "index_events_on_bookings_candidate_id"
+ t.index %w[bookings_school_id], name: "index_events_on_bookings_school_id"
end
create_table "feedbacks", force: :cascade do |t|
@@ -352,9 +352,9 @@
t.bigint "resource_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
- t.index ["name", "resource_type", "resource_id"], name: "index_roles_on_name_and_resource_type_and_resource_id"
- t.index ["name"], name: "index_roles_on_name"
- t.index ["resource_type", "resource_id"], name: "index_roles_on_resource"
+ t.index %w[name resource_type resource_id], name: "index_roles_on_name_and_resource_type_and_resource_id"
+ t.index %w[name], name: "index_roles_on_name"
+ t.index %w[resource_type resource_id], name: "index_roles_on_resource"
end
create_table "schools_on_boarding_profile_subjects", force: :cascade do |t|
@@ -362,9 +362,9 @@
t.bigint "bookings_subject_id"
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, 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"
+ t.index %w[bookings_subject_id], name: "index_profile_subjects_on_school_profile_i"
+ t.index %w[schools_school_profile_id bookings_subject_id], name: "index_profile_subjects_school_profile_id_and_subject_id", unique: true
+ t.index %w[schools_school_profile_id], name: "index_profile_subjects_on_school_profile_id"
end
create_table "schools_school_profiles", force: :cascade do |t|
@@ -447,14 +447,14 @@
t.string "dbs_requirement_dbs_policy_conditions"
t.text "dbs_requirement_dbs_policy_details_inschool"
t.boolean "candidate_dress_code_step_completed", default: false
- t.index ["bookings_school_id"], name: "index_schools_school_profiles_on_bookings_school_id"
+ t.index %w[bookings_school_id], name: "index_schools_school_profiles_on_bookings_school_id"
end
create_table "users", force: :cascade do |t|
t.string "sub"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
- t.index ["sub"], name: "index_users_on_sub", unique: true
+ t.index %w[sub], name: "index_users_on_sub", unique: true
end
create_table "users_roles", id: false, force: :cascade do |t|
@@ -462,9 +462,9 @@
t.bigint "role_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
- t.index ["role_id"], name: "index_users_roles_on_role_id"
- t.index ["user_id", "role_id"], name: "index_users_roles_on_user_id_and_role_id"
- t.index ["user_id"], name: "index_users_roles_on_user_id"
+ t.index %w[role_id], name: "index_users_roles_on_role_id"
+ t.index %w[user_id role_id], name: "index_users_roles_on_user_id_and_role_id"
+ t.index %w[user_id], name: "index_users_roles_on_user_id"
end
add_foreign_key "bookings_bookings", "bookings_placement_requests"
diff --git a/features/step_definitions/candidates/registrations/application_preview_steps.rb b/features/step_definitions/candidates/registrations/application_preview_steps.rb
index 331a7d340a..88f022e3f5 100644
--- a/features/step_definitions/candidates/registrations/application_preview_steps.rb
+++ b/features/step_definitions/candidates/registrations/application_preview_steps.rb
@@ -47,8 +47,8 @@
fill_in 'Last name', with: 'mctest'
fill_in 'Email address', with: 'unknown@example.com'
click_button 'Continue'
- expect(page.current_path).to eq \
- "/candidates/schools/#{@school.urn}/registrations/contact_information/new"
+ expect(page).to have_current_path \
+ "/candidates/schools/#{@school.urn}/registrations/contact_information/new", ignore_query: true
end
Given("I have filled in my contact information successfully") do
@@ -60,16 +60,16 @@
fill_in 'Postcode', with: 'TE57 1NG'
fill_in 'UK telephone number', with: '01234567890'
click_button 'Continue'
- expect(page.current_path).to eq \
- "/candidates/schools/#{@school.urn}/registrations/education/new"
+ expect(page).to have_current_path \
+ "/candidates/schools/#{@school.urn}/registrations/education/new", ignore_query: true
end
Given("I have filled in my education details successfully") do
choose 'Graduate or postgraduate'
fill_in "What subject are you studying?", with: "Physics"
click_button 'Continue'
- expect(page.current_path).to eq \
- "/candidates/schools/#{@school.urn}/registrations/teaching_preference/new"
+ expect(page).to have_current_path \
+ "/candidates/schools/#{@school.urn}/registrations/teaching_preference/new", ignore_query: true
end
Given("I have filled in my teaching preferences successfully") do
@@ -77,24 +77,24 @@
select 'Physics', from: 'First choice'
select 'Mathematics', from: 'Second choice'
click_button 'Continue'
- expect(page.current_path).to eq \
- "/candidates/schools/#{@school.urn}/registrations/placement_preference/new"
+ expect(page).to have_current_path \
+ "/candidates/schools/#{@school.urn}/registrations/placement_preference/new", ignore_query: true
end
Given("I have filled in my placement preferences for fixed dates successfully") do
fill_in 'Enter what you want to get out of your placement', with: 'I enjoy teaching'
click_button 'Continue'
- expect(page.current_path).to eq \
- "/candidates/schools/#{@school.urn}/registrations/background_check/new"
+ expect(page).to have_current_path \
+ "/candidates/schools/#{@school.urn}/registrations/background_check/new", ignore_query: true
end
Given("I have filled in my placement preferences successfully") do
fill_in 'Enter what you want to get out of your placement', with: 'I enjoy teaching'
click_button 'Continue'
- expect(page.current_path).to eq \
- "/candidates/schools/#{@school.urn}/registrations/availability_preference/new"
+ expect(page).to have_current_path \
+ "/candidates/schools/#{@school.urn}/registrations/availability_preference/new", ignore_query: true
end
Given("I have filled in my availability preferences successfully") do
@@ -102,16 +102,16 @@
click_button 'Continue'
- expect(page.current_path).to eq \
- "/candidates/schools/#{@school.urn}/registrations/background_check/new"
+ expect(page).to have_current_path \
+ "/candidates/schools/#{@school.urn}/registrations/background_check/new", ignore_query: true
end
Given("I have filled in my background checks successfully") do
# Submit registrations/background_check form successfully
choose 'Yes'
click_button 'Continue'
- expect(page.current_path).to eq \
- "/candidates/schools/#{@school.urn}/registrations/application_preview"
+ expect(page).to have_current_path \
+ "/candidates/schools/#{@school.urn}/registrations/application_preview", ignore_query: true
end
Given("my school has flexible dates") do
diff --git a/features/step_definitions/candidates/registrations/subject_and_date_information_steps.rb b/features/step_definitions/candidates/registrations/subject_and_date_information_steps.rb
index af5cc8ae8e..f922ede6cc 100644
--- a/features/step_definitions/candidates/registrations/subject_and_date_information_steps.rb
+++ b/features/step_definitions/candidates/registrations/subject_and_date_information_steps.rb
@@ -75,7 +75,7 @@
end
Then("I should see the duration listed in each radio button label") do
- page.all('label').each do |label|
+ page.all('label').find_each do |label|
expect(label.text).to match("(1 day)")
end
end
diff --git a/features/step_definitions/candidates/registrations/verify_your_email_steps.rb b/features/step_definitions/candidates/registrations/verify_your_email_steps.rb
index e04917a179..623f2e4d79 100644
--- a/features/step_definitions/candidates/registrations/verify_your_email_steps.rb
+++ b/features/step_definitions/candidates/registrations/verify_your_email_steps.rb
@@ -45,5 +45,5 @@
end
Given "I should not have been kicked back to the start of the wizard" do
- expect(page.current_path).not_to match(/subject_and_date_information/)
+ expect(page).to have_no_current_path(/subject_and_date_information/)
end
diff --git a/features/step_definitions/candidates/schools/results_steps.rb b/features/step_definitions/candidates/schools/results_steps.rb
index b67e874cd8..63608b7083 100644
--- a/features/step_definitions/candidates/schools/results_steps.rb
+++ b/features/step_definitions/candidates/schools/results_steps.rb
@@ -43,7 +43,7 @@
Then("each result should have the following information") do |table|
attributes = table.raw.flatten
- page.all('ul > li.school-result').each do |result|
+ page.all('ul > li.school-result').find_each do |result|
attributes.each do |attribute|
expect(result).to have_css('strong', text: attribute)
end
diff --git a/features/step_definitions/schools/bookings_steps.rb b/features/step_definitions/schools/bookings_steps.rb
index cf8c92411d..4aa2fae25c 100644
--- a/features/step_definitions/schools/bookings_steps.rb
+++ b/features/step_definitions/schools/bookings_steps.rb
@@ -106,7 +106,7 @@
Then("every booking should contain a link to view more details") do
within('#bookings') do
- page.all('.booking').each do |sr|
+ page.all('.booking').find_each do |sr|
within(sr) do
booking_id = sr['data-booking']
expect(page).to have_link('View', href: schools_booking_path(booking_id))
@@ -117,7 +117,7 @@
Then("every booking should contain a title starting with {string}") do |string|
within('#bookings') do
- page.all('.booking').each do |sr|
+ page.all('.booking').find_each do |sr|
within(sr) do
expect(page).to have_css('h2', text: /#{string}/)
end
diff --git a/features/step_definitions/schools/cancelled_bookings_steps.rb b/features/step_definitions/schools/cancelled_bookings_steps.rb
index d19f26cc42..d132552666 100644
--- a/features/step_definitions/schools/cancelled_bookings_steps.rb
+++ b/features/step_definitions/schools/cancelled_bookings_steps.rb
@@ -52,7 +52,7 @@
Then("every booking should contain a link to view cancelled booking details") do
within('#bookings') do
- page.all('.booking').each do |sr|
+ page.all('.booking').find_each do |sr|
within(sr) do
booking_id = sr['data-booking']
expect(page).to have_link('View', href: schools_cancelled_booking_path(booking_id))
diff --git a/features/step_definitions/schools/placement_dates/index_steps.rb b/features/step_definitions/schools/placement_dates/index_steps.rb
index b32113141e..3ef5b95903 100644
--- a/features/step_definitions/schools/placement_dates/index_steps.rb
+++ b/features/step_definitions/schools/placement_dates/index_steps.rb
@@ -39,7 +39,7 @@
end
Then "I should be on the Are you sure you want to close this date page" do
- expect(page.current_path).to eq schools_placement_date_close_path(placement_date_id: Bookings::PlacementDate.last.id)
+ expect(page).to have_current_path schools_placement_date_close_path(placement_date_id: Bookings::PlacementDate.last.id), ignore_query: true
end
Then("there should be a {string} link to the new placement date page") do |string|
diff --git a/features/step_definitions/schools/placement_dates/placement_date_steps.rb b/features/step_definitions/schools/placement_dates/placement_date_steps.rb
index eca11a3cef..5ddf52d803 100644
--- a/features/step_definitions/schools/placement_dates/placement_date_steps.rb
+++ b/features/step_definitions/schools/placement_dates/placement_date_steps.rb
@@ -67,7 +67,7 @@
end
Given("I uncheck all dates") do
- page.all("input[type=checkbox]").each(&:uncheck)
+ page.all("input[type=checkbox]").find_each(&:uncheck)
end
When "I select {string} recurrence and enter a valid date" do |recurrence_type|
@@ -148,8 +148,8 @@
end
Then "I should be on the new configuration page for this date" do
- expect(page.current_path).to eq \
- path_for('new configuration', placement_date_id: @school.bookings_placement_dates.last.id)
+ expect(page).to have_current_path \
+ path_for('new configuration', placement_date_id: @school.bookings_placement_dates.last.id), ignore_query: true
end
Then "I should see a list of subjects the school offers" do
diff --git a/features/step_definitions/schools/placement_request_steps.rb b/features/step_definitions/schools/placement_request_steps.rb
index 60daf96061..d311a29e18 100644
--- a/features/step_definitions/schools/placement_request_steps.rb
+++ b/features/step_definitions/schools/placement_request_steps.rb
@@ -105,7 +105,7 @@
Then("every request should contain a title starting with {string}") do |string|
within('#placement-requests') do
- page.all('.placement-request').each do |sr|
+ page.all('.placement-request').find_each do |sr|
within(sr) do
expect(page).to have_css('h2', text: /#{string}/)
end
diff --git a/features/step_definitions/schools/placement_requests/accept_steps.rb b/features/step_definitions/schools/placement_requests/accept_steps.rb
index d89d010d5e..27838eb835 100644
--- a/features/step_definitions/schools/placement_requests/accept_steps.rb
+++ b/features/step_definitions/schools/placement_requests/accept_steps.rb
@@ -11,7 +11,7 @@
Then("every row of the booking details list should have a {string} link") do |string|
within('#booking-details') do
- page.all('div.govuk-summary-list__row').each do |row|
+ page.all('div.govuk-summary-list__row').find_each do |row|
expect(row).to have_link(string)
end
end
diff --git a/features/step_definitions/schools/previous_bookings_steps.rb b/features/step_definitions/schools/previous_bookings_steps.rb
index 428040c064..6ae0303907 100644
--- a/features/step_definitions/schools/previous_bookings_steps.rb
+++ b/features/step_definitions/schools/previous_bookings_steps.rb
@@ -68,7 +68,7 @@
Then("every booking should contain a link to view previous booking details") do
within('#bookings') do
- page.all('.booking').each do |sr|
+ page.all('.booking').find_each do |sr|
within(sr) do
booking_id = sr['data-booking']
expect(page).to have_link('View', href: schools_previous_booking_path(booking_id))
diff --git a/lib/notify/notify_sync.rb b/lib/notify/notify_sync.rb
index 0ee1822b09..1bd571c135 100644
--- a/lib/notify/notify_sync.rb
+++ b/lib/notify/notify_sync.rb
@@ -23,7 +23,7 @@ def compare
# Any templates remaining aren't present locally
if remote_templates_copy.size.positive?
- remote_templates_copy.each do |_, template|
+ remote_templates_copy.each_value do |template|
puts output_line(template.id, template.name, "Missing local template")
end
end
@@ -66,7 +66,7 @@ def client
def local_templates
Dir.glob(File.join(TEMPLATE_PATH, "*.md")).each.with_object({}) do |path, hash|
- template_id = path.match(/\.(?[A-z0-9\-]+)\.md$/)[:template_id]
+ template_id = path.match(/\.(?[A-z0-9-]+)\.md$/)[:template_id]
hash[template_id] = File.read(path).chomp
end
end
diff --git a/spec/controllers/candidates/booking_feedbacks_controller_spec.rb b/spec/controllers/candidates/booking_feedbacks_controller_spec.rb
index 351ceb8802..cde64ac720 100644
--- a/spec/controllers/candidates/booking_feedbacks_controller_spec.rb
+++ b/spec/controllers/candidates/booking_feedbacks_controller_spec.rb
@@ -32,30 +32,30 @@
let(:token) { placement_request.token }
describe "#new" do
- include_context "invalid requests"
-
subject(:perform_request) do
get new_candidates_booking_feedback_path(token)
response
end
+ include_context "invalid requests"
+
it { is_expected.to render_template(:new) }
end
describe "#create" do
+ subject(:perform_request) do
+ post candidates_booking_feedback_path(token, params: params)
+ response
+ end
+
include_context "invalid requests"
let(:attributes) { attributes_for(:candidates_booking_feedback) }
let(:params) { { candidates_booking_feedback: attributes } }
let(:created_feedback) { Candidates::BookingFeedback.last }
- subject(:perform_request) do
- post candidates_booking_feedback_path(token, params: params)
- response
- end
-
it { is_expected.to redirect_to(created_feedback) }
- it { expect { perform_request }.to change { Candidates::BookingFeedback.count }.by(1) }
+ it { expect { perform_request }.to change(Candidates::BookingFeedback, :count).by(1) }
it "creates feedback associated to the booking" do
perform_request
diff --git a/spec/controllers/candidates/feedbacks_controller_spec.rb b/spec/controllers/candidates/feedbacks_controller_spec.rb
index 15f6a4aaab..bd12d6cbd9 100644
--- a/spec/controllers/candidates/feedbacks_controller_spec.rb
+++ b/spec/controllers/candidates/feedbacks_controller_spec.rb
@@ -1,7 +1,7 @@
require 'rails_helper'
describe Candidates::FeedbacksController, type: :request do
- context '#new' do
+ describe '#new' do
before do
get '/candidates/feedbacks/new'
end
@@ -15,7 +15,7 @@
end
end
- context '#create' do
+ describe '#create' do
let :feedback_params do
{ candidates_feedback: feedback.attributes }
end
@@ -50,7 +50,7 @@
end
end
- context '#show' do
+ describe '#show' do
let :feedback do
FactoryBot.create :candidates_feedback
end
diff --git a/spec/controllers/candidates/placement_requests/cancellations_controller_spec.rb b/spec/controllers/candidates/placement_requests/cancellations_controller_spec.rb
index 1361b90d96..340f2307d0 100644
--- a/spec/controllers/candidates/placement_requests/cancellations_controller_spec.rb
+++ b/spec/controllers/candidates/placement_requests/cancellations_controller_spec.rb
@@ -45,7 +45,7 @@
receive(:write_to_gitis_contact)
end
- context '#new' do
+ describe '#new' do
before do
get "/candidates/placement_requests/#{placement_request.token}/cancellation/new"
end
@@ -84,7 +84,7 @@
end
end
- context '#create' do
+ describe '#create' do
let :cancellation_params do
{ bookings_placement_request_cancellation: cancellation.attributes }
end
@@ -322,7 +322,7 @@
end
end
- context '#show' do
+ describe '#show' do
before do
get \
"/candidates/placement_requests/#{placement_request.token}/cancellation"
diff --git a/spec/controllers/candidates/registrations/application_previews_controller_spec.rb b/spec/controllers/candidates/registrations/application_previews_controller_spec.rb
index 8f0ccb7f69..6c8237e8e9 100644
--- a/spec/controllers/candidates/registrations/application_previews_controller_spec.rb
+++ b/spec/controllers/candidates/registrations/application_previews_controller_spec.rb
@@ -4,7 +4,7 @@
include_context 'Stubbed candidates school'
include_context 'Stubbed current_registration'
- context '#show' do
+ describe '#show' do
before do
get '/candidates/schools/urn/registrations/application_preview'
end
diff --git a/spec/controllers/candidates/registrations/availability_preferences_controller_spec.rb b/spec/controllers/candidates/registrations/availability_preferences_controller_spec.rb
index 81371d47b1..ff71cd0fd5 100644
--- a/spec/controllers/candidates/registrations/availability_preferences_controller_spec.rb
+++ b/spec/controllers/candidates/registrations/availability_preferences_controller_spec.rb
@@ -16,7 +16,7 @@
end
context 'without existing availability_preference in session' do
- context '#new' do
+ describe '#new' do
before do
get '/candidates/schools/11048/registrations/availability_preference/new'
end
@@ -30,7 +30,7 @@
end
end
- context '#create' do
+ describe '#create' do
let :availability_preference_params do
{
candidates_registrations_availability_preference: \
@@ -85,7 +85,7 @@
registration_session.save existing_availability_preference
end
- context '#new' do
+ describe '#new' do
before do
get '/candidates/schools/11048/registrations/availability_preference/new'
end
@@ -100,7 +100,7 @@
end
end
- context '#edit' do
+ describe '#edit' do
before do
get '/candidates/schools/11048/registrations/availability_preference/edit'
end
@@ -115,7 +115,7 @@
end
end
- context '#update' do
+ describe '#update' do
let :availability_preference_params do
{
candidates_registrations_availability_preference: \
diff --git a/spec/controllers/candidates/registrations/background_checks_controller_spec.rb b/spec/controllers/candidates/registrations/background_checks_controller_spec.rb
index 3249fe1c86..ea55e91d85 100644
--- a/spec/controllers/candidates/registrations/background_checks_controller_spec.rb
+++ b/spec/controllers/candidates/registrations/background_checks_controller_spec.rb
@@ -19,7 +19,7 @@
]
end
- context '#new' do
+ describe '#new' do
before do
get '/candidates/schools/11048/registrations/background_check/new'
end
@@ -29,7 +29,7 @@
end
end
- context '#create' do
+ describe '#create' do
let :background_check_params do
{
candidates_registrations_background_check: \
@@ -91,7 +91,7 @@
]
end
- context '#new' do
+ describe '#new' do
before do
get '/candidates/schools/11048/registrations/background_check/new'
end
@@ -126,7 +126,7 @@
registration_session.save existing_background_check
end
- context '#new' do
+ describe '#new' do
before do
get '/candidates/schools/11048/registrations/background_check/new'
end
@@ -140,7 +140,7 @@
end
end
- context '#edit' do
+ describe '#edit' do
before do
get '/candidates/schools/11048/registrations/background_check/edit'
end
@@ -154,7 +154,7 @@
end
end
- context '#update' do
+ describe '#update' do
let :background_check_params do
{
candidates_registrations_background_check: \
diff --git a/spec/controllers/candidates/registrations/confirmation_emails_controller_spec.rb b/spec/controllers/candidates/registrations/confirmation_emails_controller_spec.rb
index fd410a22f8..957e1f07b1 100644
--- a/spec/controllers/candidates/registrations/confirmation_emails_controller_spec.rb
+++ b/spec/controllers/candidates/registrations/confirmation_emails_controller_spec.rb
@@ -27,22 +27,22 @@
receive(:perform_later)
end
- context '#create' do
+ describe '#create' do
let(:skip_confirmation_emails) { false }
before { allow(Feature).to receive(:enabled?).with(:skip_candidate_confirmation_emails) { skip_confirmation_emails } }
context 'skipped step' do
- before { registration_store.send :delete, 'some-uuid' } # ensure key not left lying around
+ # ensure key not left lying around
+ before do
+ registration_store.send :delete, 'some-uuid'
+ post candidates_school_registrations_confirmation_email_path(school)
+ end
let :registration_session do
FactoryBot.build :registration_session, with: []
end
- before do
- post candidates_school_registrations_confirmation_email_path(school)
- end
-
it "doesn't store the session" do
expect {
registration_store.retrieve! registration_session.uuid
@@ -151,7 +151,7 @@
end
end
- context '#show' do
+ describe '#show' do
before do
get candidates_school_registrations_confirmation_email_path school
end
diff --git a/spec/controllers/candidates/registrations/contact_informations_controller_spec.rb b/spec/controllers/candidates/registrations/contact_informations_controller_spec.rb
index 602cdca9ca..006c261eec 100644
--- a/spec/controllers/candidates/registrations/contact_informations_controller_spec.rb
+++ b/spec/controllers/candidates/registrations/contact_informations_controller_spec.rb
@@ -11,7 +11,7 @@
FactoryBot.build :registration_session, with: %i[personal_information]
end
- context '#new' do
+ describe '#new' do
before do
get '/candidates/schools/11048/registrations/contact_information/new'
end
@@ -21,7 +21,7 @@
end
end
- context '#create' do
+ describe '#create' do
let :contact_information_params do
{
candidates_registrations_contact_information: \
@@ -75,7 +75,7 @@
with: %i[personal_information]
end
- context '#new' do
+ describe '#new' do
before do
get '/candidates/schools/11048/registrations/contact_information/new'
end
@@ -107,7 +107,7 @@
registration_session.save existing_contact_information
end
- context '#new' do
+ describe '#new' do
before do
get '/candidates/schools/11048/registrations/contact_information/new'
end
@@ -122,7 +122,7 @@
end
end
- context '#edit' do
+ describe '#edit' do
before do
get '/candidates/schools/11048/registrations/contact_information/edit'
end
@@ -136,7 +136,7 @@
end
end
- context '#update' do
+ describe '#update' do
let :contact_information_params do
{
candidates_registrations_contact_information: \
diff --git a/spec/controllers/candidates/registrations/educations_controller_spec.rb b/spec/controllers/candidates/registrations/educations_controller_spec.rb
index b454fa87eb..b22fd23ae8 100644
--- a/spec/controllers/candidates/registrations/educations_controller_spec.rb
+++ b/spec/controllers/candidates/registrations/educations_controller_spec.rb
@@ -11,7 +11,7 @@
end
let!(:school) { create(:bookings_school, urn: 11_048) }
- context '#new' do
+ describe '#new' do
context 'without existing education in session' do
before do
get '/candidates/schools/11048/registrations/education/new'
@@ -34,9 +34,6 @@
before do
registration_session.save education
- end
-
- before do
get '/candidates/schools/11048/registrations/education/new'
end
@@ -51,7 +48,7 @@
end
end
- context '#create' do
+ describe '#create' do
let :education_params do
{ candidates_registrations_education: education.attributes }
end
@@ -92,16 +89,13 @@
end
end
- context '#edit' do
+ describe '#edit' do
let :education do
FactoryBot.build :education
end
before do
registration_session.save education
- end
-
- before do
get '/candidates/schools/11048/registrations/education/edit'
end
@@ -114,19 +108,18 @@
end
end
- context '#update' do
+ describe '#update' do
let :existing_education do
FactoryBot.build :education
end
+ let :education_params do
+ { candidates_registrations_education: education.attributes }
+ end
before do
registration_session.save existing_education
end
- let :education_params do
- { candidates_registrations_education: education.attributes }
- end
-
context 'invalid' do
before do
patch '/candidates/schools/11048/registrations/education',
@@ -174,17 +167,16 @@
end
context 'unsetting explanation when changed from other' do
+ subject do
+ patch '/candidates/schools/11048/registrations/education', params: params
+ end
+
let :education do
FactoryBot.build \
:education,
degree_stage: 'Other',
degree_stage_explaination: 'On an important quest'
end
-
- before do
- registration_session.save education
- end
-
let(:degree_stage) { 'Final year' }
let(:degree_subject) { 'Art' }
let(:params) do
@@ -196,8 +188,8 @@
}
end
- subject do
- patch '/candidates/schools/11048/registrations/education', params: params
+ before do
+ registration_session.save education
end
specify 'should set degree_stage_explaination to nil' do
diff --git a/spec/controllers/candidates/registrations/personal_informations_controller_spec.rb b/spec/controllers/candidates/registrations/personal_informations_controller_spec.rb
index a7612e6063..253348e4b6 100644
--- a/spec/controllers/candidates/registrations/personal_informations_controller_spec.rb
+++ b/spec/controllers/candidates/registrations/personal_informations_controller_spec.rb
@@ -13,7 +13,7 @@
end
context 'without existing personal information in the session' do
- context '#new' do
+ describe '#new' do
before do
get '/candidates/schools/10020/registrations/personal_information/new'
end
@@ -23,7 +23,7 @@
end
end
- context '#create' do
+ describe '#create' do
let :personal_information_params do
{
candidates_registrations_personal_information: \
@@ -126,7 +126,7 @@
end
it "does not send a verification email" do
- expect(NotifyFakeClient.deliveries.length).to eql(0)
+ expect(NotifyFakeClient.deliveries.length).to be(0)
end
it 'redirects to the next step' do
@@ -144,7 +144,7 @@
Candidates::Registrations::GitisRegistrationSession.new({ 'urn' => '10020' }, gitis_contact)
end
- context '#new' do
+ describe '#new' do
before do
get '/candidates/schools/10020/registrations/personal_information/new'
end
@@ -174,7 +174,7 @@
registration_session.save existing_personal_information
end
- context '#new' do
+ describe '#new' do
before do
get '/candidates/schools/10020/registrations/personal_information/new'
end
@@ -189,7 +189,7 @@
end
end
- context '#edit' do
+ describe '#edit' do
before do
get '/candidates/schools/10020/registrations/personal_information/edit'
end
@@ -203,7 +203,7 @@
end
end
- context '#update' do
+ describe '#update' do
let :personal_information_params do
{
candidates_registrations_personal_information: \
diff --git a/spec/controllers/candidates/registrations/placement_preferences_controller_spec.rb b/spec/controllers/candidates/registrations/placement_preferences_controller_spec.rb
index 205725ba44..7ccdb01614 100644
--- a/spec/controllers/candidates/registrations/placement_preferences_controller_spec.rb
+++ b/spec/controllers/candidates/registrations/placement_preferences_controller_spec.rb
@@ -15,7 +15,7 @@
end
context 'without existing placement_preference in session' do
- context '#new' do
+ describe '#new' do
before do
get '/candidates/schools/11048/registrations/placement_preference/new'
end
@@ -29,7 +29,7 @@
end
end
- context '#create' do
+ describe '#create' do
let :placement_preference_params do
{
candidates_registrations_placement_preference: \
@@ -84,7 +84,7 @@
registration_session.save existing_placement_preference
end
- context '#new' do
+ describe '#new' do
before do
get '/candidates/schools/11048/registrations/placement_preference/new'
end
@@ -99,7 +99,7 @@
end
end
- context '#edit' do
+ describe '#edit' do
before do
get '/candidates/schools/11048/registrations/placement_preference/edit'
end
@@ -114,7 +114,7 @@
end
end
- context '#update' do
+ describe '#update' do
let :placement_preference_params do
{
candidates_registrations_placement_preference: \
diff --git a/spec/controllers/candidates/registrations/placement_requests_controller_spec.rb b/spec/controllers/candidates/registrations/placement_requests_controller_spec.rb
index 28914ca7d5..9dba31cc4a 100644
--- a/spec/controllers/candidates/registrations/placement_requests_controller_spec.rb
+++ b/spec/controllers/candidates/registrations/placement_requests_controller_spec.rb
@@ -22,7 +22,7 @@
registration_session
allow(Candidates::Registrations::PlacementRequestJob).to \
- receive(:perform_later) { true }
+ receive(:perform_later).and_return(true)
allow(Bookings::Gitis::SchoolExperience).to \
receive(:from_placement_request) { school_experience }
@@ -31,8 +31,8 @@
receive(:write_to_gitis_contact)
end
- context '#create' do
- before :each do
+ describe '#create' do
+ before do
@placement_request_count = Bookings::PlacementRequest.count
end
@@ -178,7 +178,7 @@
end
end
- context '#show' do
+ describe '#show' do
before do
get \
"/candidates/schools/#{school.urn}/registrations/placement_request?uuid=#{uuid}"
diff --git a/spec/controllers/candidates/registrations/resend_confirmation_emails_controller_spec.rb b/spec/controllers/candidates/registrations/resend_confirmation_emails_controller_spec.rb
index dc20767f67..65e5a966f6 100644
--- a/spec/controllers/candidates/registrations/resend_confirmation_emails_controller_spec.rb
+++ b/spec/controllers/candidates/registrations/resend_confirmation_emails_controller_spec.rb
@@ -13,7 +13,7 @@
receive :perform_later
end
- context '#create' do
+ describe '#create' do
context 'session found' do
context 'session not pending email confirmation' do
before do
diff --git a/spec/controllers/candidates/registrations/sign_ins_controller_spec.rb b/spec/controllers/candidates/registrations/sign_ins_controller_spec.rb
index ea31e3e463..f61ea77fd6 100644
--- a/spec/controllers/candidates/registrations/sign_ins_controller_spec.rb
+++ b/spec/controllers/candidates/registrations/sign_ins_controller_spec.rb
@@ -23,7 +23,7 @@
before { get candidates_school_registrations_sign_in_path(school_id) }
- it "should return HTTP success" do
+ it "returns HTTP success" do
expect(response).to have_http_status(:success)
end
end
@@ -48,12 +48,12 @@
context "with a valid code" do
before { perform_request }
- it "will redirect_to ContactInformation step" do
+ it "redirect_toes ContactInformation step" do
expect(response).to \
redirect_to new_candidates_school_registrations_contact_information_path(school_id)
end
- it "will create a confirmed candidate" do
+ it "creates a confirmed candidate" do
candidate = Bookings::Candidate.find_by(gitis_uuid: sign_up.candidate_id)
expect(candidate).to be_confirmed
end
@@ -64,7 +64,7 @@
before { perform_request }
- it "will show error screen" do
+ it "shows error screen" do
expect(response).to have_http_status(:success)
expect(response.body).to include("Please enter the latest verification code sent to your email address")
end
@@ -78,7 +78,7 @@
receive(:delete_registration_sessions!)
end
- it "will redirect_to ContactInformation step" do
+ it "redirect_toes ContactInformation step" do
perform_request
expect(response).to \
@@ -91,8 +91,8 @@
let(:sign_up) { build(:api_schools_experience_sign_up_with_name, candidate_id: gitis_contact_attrs[:candidate_id]) }
- it "will not create another Candidate and redirect_to ConfirmationInformation step" do
- expect { perform_request }.not_to(change { Bookings::Candidate.count })
+ it "does not create another Candidate and redirect_to ConfirmationInformation step" do
+ expect { perform_request }.not_to(change(Bookings::Candidate, :count))
expect(response).to \
redirect_to new_candidates_school_registrations_contact_information_path(school_id)
@@ -104,12 +104,12 @@
before { perform_request }
- it "will redirect_to ContactInformation step" do
+ it "redirect_toes ContactInformation step" do
expect(response).to \
redirect_to new_candidates_school_registrations_contact_information_path(school_id)
end
- it "will have confirmed candidate" do
+ it "has confirmed candidate" do
candidate = Bookings::Candidate.find_by(gitis_uuid: sign_up.candidate_id)
expect(candidate).to be_confirmed
end
@@ -128,7 +128,7 @@
end
end
- it "will issue a verification code and redirect to the show page" do
+ it "issues a verification code and redirect to the show page" do
perform_request
expect(response).to \
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 051482bc65..4aa8fa7859 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
@@ -20,7 +20,7 @@
it('responds with 302') { expect(response.status).to eq 302 }
- it 'should redirect to the personal information page' do
+ it 'redirects to the personal information page' do
expect(response.header["Location"]).to end_with('schools/11048/registrations/personal_information/new')
end
end
@@ -59,6 +59,8 @@
end
context 'when the school has primary dates' do
+ subject! { post subject_and_date_info_path, params: params }
+
let(:primary_placement_date) { create(:bookings_placement_date, bookings_school: school, supports_subjects: false) }
let(:params) do
{
@@ -68,8 +70,6 @@
}
end
- subject! { post subject_and_date_info_path, params: params }
-
specify 'correctly stores the primary placement date in the registration session' do
persisted_session = \
Candidates::Registrations::RegistrationStore.instance.retrieve! session['registrations']['11048']
@@ -80,16 +80,18 @@
end
context 'when no parameters are supplied' do
+ subject { post subject_and_date_info_path, params: params }
+
let(:params) do
{}
end
- subject { post subject_and_date_info_path, params: params }
-
specify { expect { subject }.to raise_error(ActionController::ParameterMissing, /candidates_registrations_subject_and_date_information/) }
end
context 'when the school has secondary non-subject-specific dates' do
+ subject! { post subject_and_date_info_path, params: params }
+
let(:secondary_placement_date) { create(:bookings_placement_date, bookings_school: school, supports_subjects: true) }
let(:params) do
{
@@ -99,8 +101,6 @@
}
end
- subject! { post subject_and_date_info_path, params: params }
-
specify 'correctly stores the secondary placement date in the registration session' do
persisted_session = \
Candidates::Registrations::RegistrationStore.instance.retrieve! session['registrations']['11048']
@@ -119,19 +119,16 @@
end
context 'when the school has secondary subject-specific dates' do
- let(:bookings_subject) { create(:bookings_subject) }
-
- before { school.subjects << bookings_subject }
+ subject! { post subject_and_date_info_path, params: params }
+ let(:bookings_subject) { create(:bookings_subject) }
let(:secondary_placement_date) do
build(:bookings_placement_date, bookings_school: school, subject_specific: true, supports_subjects: true).tap do |pd|
pd.subjects << bookings_subject
pd.save
end
end
-
let(:placement_date_subject) { secondary_placement_date.placement_date_subjects.first }
-
let(:params) do
{
candidates_registrations_subject_and_date_information: {
@@ -140,7 +137,7 @@
}
end
- subject! { post subject_and_date_info_path, params: params }
+ before { school.subjects << bookings_subject }
specify 'correctly stores the secondary placement date in the registration session' do
persisted_session = \
diff --git a/spec/controllers/candidates/registrations/teaching_preferences_controller_spec.rb b/spec/controllers/candidates/registrations/teaching_preferences_controller_spec.rb
index 4a7d9d0be8..7c9f7e51f5 100644
--- a/spec/controllers/candidates/registrations/teaching_preferences_controller_spec.rb
+++ b/spec/controllers/candidates/registrations/teaching_preferences_controller_spec.rb
@@ -12,7 +12,7 @@
]
end
- context '#new' do
+ describe '#new' do
context 'without existing teaching_preference in the session' do
before do
get '/candidates/schools/11048/registrations/teaching_preference/new'
@@ -35,9 +35,6 @@
before do
registration_session.save teaching_preference
- end
-
- before do
get '/candidates/schools/11048/registrations/teaching_preference/new'
end
@@ -56,7 +53,7 @@
end
end
- context '#create' do
+ describe '#create' do
let :teaching_preference_params do
{
candidates_registrations_teaching_preference: \
@@ -101,16 +98,13 @@
end
end
- context '#edit' do
+ describe '#edit' do
let :exisitng_teaching_preference do
FactoryBot.build :teaching_preference
end
before do
registration_session.save exisitng_teaching_preference
- end
-
- before do
get '/candidates/schools/11048/registrations/teaching_preference/edit'
end
@@ -124,15 +118,10 @@
end
end
- context '#update' do
+ describe '#update' do
let :exisitng_teaching_preference do
FactoryBot.build :teaching_preference
end
-
- before do
- registration_session.save exisitng_teaching_preference
- end
-
let :teaching_preference_params do
{
candidates_registrations_teaching_preference: \
@@ -141,8 +130,9 @@
end
before do
+ registration_session.save exisitng_teaching_preference
patch '/candidates/schools/11048/registrations/teaching_preference',
- params: teaching_preference_params
+ params: teaching_preference_params
end
context 'invalid' do
diff --git a/spec/controllers/candidates/school_searches_controller_spec.rb b/spec/controllers/candidates/school_searches_controller_spec.rb
index cb6058485c..e501ce6ec3 100644
--- a/spec/controllers/candidates/school_searches_controller_spec.rb
+++ b/spec/controllers/candidates/school_searches_controller_spec.rb
@@ -21,6 +21,7 @@
get new_candidates_school_search_path
response
end
+
it { is_expected.to redirect_to candidates_root_path }
end
end
diff --git a/spec/controllers/candidates/schools_controller_spec.rb b/spec/controllers/candidates/schools_controller_spec.rb
index e157f4bad3..ada3e02964 100644
--- a/spec/controllers/candidates/schools_controller_spec.rb
+++ b/spec/controllers/candidates/schools_controller_spec.rb
@@ -93,9 +93,10 @@
end
context "GET #show" do
+ subject! { req }
+
let(:school) { create(:bookings_school) }
let(:req) { get candidates_school_path(school) }
- subject! { req }
it "returns http success" do
expect(response).to have_http_status(:success)
@@ -106,11 +107,12 @@
end
it "assigns the the school" do
- expect(assigns(:school)).to_not be_nil
+ expect(assigns(:school)).not_to be_nil
end
context 'counting' do
let!(:count) { school.views }
+
before { req }
specify 'count should have increased when viewed' do
@@ -137,6 +139,7 @@
get candidates_schools_path
response
end
+
it { is_expected.to redirect_to candidates_root_path }
end
@@ -145,6 +148,7 @@
get candidates_school_path(school)
response
end
+
it { is_expected.to redirect_to candidates_root_path }
end
end
@@ -159,20 +163,24 @@
describe '#show' do
context 'when in whitelist' do
- let(:whitelist) { school.urn.to_s }
subject do
get candidates_school_path(school)
response
end
+
+ let(:whitelist) { school.urn.to_s }
+
it { is_expected.to have_rendered 'show' }
end
context 'when not in whitelist' do
- let(:whitelist) { '-1' }
subject do
get candidates_school_path(school)
response
end
+
+ let(:whitelist) { '-1' }
+
it { is_expected.to redirect_to candidates_root_path }
end
end
diff --git a/spec/controllers/candidates/sessions_controller_spec.rb b/spec/controllers/candidates/sessions_controller_spec.rb
index c757cb2414..4fac12d2e8 100644
--- a/spec/controllers/candidates/sessions_controller_spec.rb
+++ b/spec/controllers/candidates/sessions_controller_spec.rb
@@ -67,6 +67,7 @@
context 'with missing details' do
let(:invalid_creds) { { candidates_session: { email: 'invalid' } } }
+
before { post candidates_signin_path, params: invalid_creds }
it "returns http redirect to /candidates" do
@@ -98,7 +99,7 @@
expect(response).to redirect_to(candidates_dashboard_path)
end
- it "will create a confirmed candidate" do
+ it "creates a confirmed candidate" do
candidate = Bookings::Candidate.find_by(gitis_uuid: sign_up.candidate_id)
expect(candidate).to be_confirmed
end
@@ -109,7 +110,7 @@
before { perform_request }
- it "will show error screen" do
+ it "shows error screen" do
expect(response).to have_http_status(:success)
expect(response.body).to include("Please enter the latest verification code sent to your email address")
end
@@ -122,7 +123,7 @@
before { get candidates_signout_path }
it "empties the gitis_contact session and redirects to the dashboard sign in" do
- expect(session[:gitis_contact]).to be nil
+ expect(session[:gitis_contact]).to be_nil
expect(response).to redirect_to(candidates_dashboard_path)
end
end
diff --git a/spec/controllers/concerns/dfe_authentication_spec.rb b/spec/controllers/concerns/dfe_authentication_spec.rb
index 85e6bf348b..b4ee3b85c0 100644
--- a/spec/controllers/concerns/dfe_authentication_spec.rb
+++ b/spec/controllers/concerns/dfe_authentication_spec.rb
@@ -4,15 +4,15 @@
# testing is much easier with an _actual_ controller, so
# let's use Dashboards
describe Schools::DashboardsController, type: :controller do
- it { expect(described_class.ancestors).to include(DFEAuthentication) }
-
+ let(:auth_host) { Rails.application.config.x.oidc_host }
+ let(:teacher_user) { create(:user) }
let(:teacher_session) do
OpenIDConnect::ResponseObject::UserInfo.new(
sub: teacher_user.sub
)
end
- let(:teacher_user) { create(:user) }
- let(:auth_host) { Rails.application.config.x.oidc_host }
+
+ it { expect(described_class.ancestors).to include(DFEAuthentication) }
describe 'login redirect' do
subject do
@@ -28,29 +28,29 @@
context 'and ChangeSchool not enabled' do
let(:allow_change_school) { false }
- it 'will redirect to DfE Sign in' do
- is_expected.to redirect_to %r{#{Regexp.quote(auth_host)}}
+ it 'redirects to DfE Sign in' do
+ expect(subject).to redirect_to %r{#{Regexp.quote(auth_host)}}
end
- it 'will request organisation from DfE Sign-in' do
- is_expected.to redirect_to %r{&scope=profile%20organisation%20openid}
+ it 'requests organisation from DfE Sign-in' do
+ expect(subject).to redirect_to %r{&scope=profile%20organisation%20openid}
end
end
context 'and ChangeSchool enabled' do
let(:allow_change_school) { true }
- it 'will redirect to DfE Sign in' do
- is_expected.to redirect_to %r{#{Regexp.quote(auth_host)}}
+ it 'redirects to DfE Sign in' do
+ expect(subject).to redirect_to %r{#{Regexp.quote(auth_host)}}
end
- it 'will not request organisation from DfE Sign-in' do
- is_expected.to redirect_to %r{&scope=profile%20openid}
+ it 'does not request organisation from DfE Sign-in' do
+ expect(subject).to redirect_to %r{&scope=profile%20openid}
end
end
end
- context '#current_user' do
+ describe '#current_user' do
context 'when the current_user is set' do
before do
subject.instance_variable_set(:@current_user, teacher_user)
@@ -62,8 +62,10 @@
end
context 'when the current user is not set' do
- before { get :show }
- before { controller.session[:current_user] = teacher_session }
+ before do
+ get :show
+ controller.session[:current_user] = teacher_session
+ end
specify 'should retrieve the current user from the session' do
expect(subject.send(:current_user)).to eql(teacher_user)
@@ -71,19 +73,19 @@
end
end
- context '#user_signed_in?' do
+ describe '#user_signed_in?' do
context 'when a user is signed in' do
before do
subject.instance_variable_set(:@current_user, teacher_user)
end
- it 'should be true' do
+ it 'is true' do
expect(subject.send(:user_signed_in?)).to be(true)
end
end
context 'when a user is not signed in' do
- it 'should be false' do
+ it 'is false' do
expect(subject.send(:user_signed_in?)).to be(false)
end
end
@@ -91,7 +93,7 @@
describe '#school_urns' do
before do
- allow(Schools::DFESignInAPI::Client).to receive(:enabled?) { true }
+ allow(Schools::DFESignInAPI::Client).to receive(:enabled?).and_return(true)
allow(controller).to receive(:retrieve_school_uuids).and_return \
SecureRandom.uuid => 4,
@@ -111,19 +113,21 @@
SecureRandom.uuid => 3
}
end
+
it { expect(subject.send(:school_urns)).to eql [1, 2, 3] }
end
context 'with forced reload' do
before { controller.session[:urns] = [1, 2, 3] }
+
it { expect(subject.send(:school_urns, reload: true)).to eql [4, 5, 6] }
it { expect(controller).not_to have_received(:retrieve_school_uuids) }
end
context 'when DfE Sign-in API is disabled' do
before do
- allow(Schools::DFESignInAPI::Client).to receive(:enabled?) { false }
- allow(controller).to receive(:current_urn) { 1 }
+ allow(Schools::DFESignInAPI::Client).to receive(:enabled?).and_return(false)
+ allow(controller).to receive(:current_urn).and_return(1)
end
it { expect(subject.send(:school_urns)).to eql [1] }
@@ -132,20 +136,27 @@
end
describe '#other_school_urns' do
- before { allow(controller).to receive(:school_urns) { [1, 2, 3] } }
- before { allow(controller).to receive(:current_school) { build(:bookings_school, urn: 2) } }
+ before do
+ allow(controller).to receive(:school_urns).and_return([1, 2, 3])
+ allow(controller).to receive(:current_school) { build(:bookings_school, urn: 2) }
+ end
+
it { expect(subject.send(:other_school_urns)).to eql [1, 3] }
end
describe '#has_other_schools' do
context 'when other schools' do
- before { allow(controller).to receive(:other_school_urns) { [1, 2] } }
+ before { allow(controller).to receive(:other_school_urns).and_return([1, 2]) }
+
it { expect(subject.send(:has_other_schools?)).to be true }
end
context 'when only one school' do
- before { allow(Schools::DFESignInAPI::Client).to receive(:enabled?) { true } }
- before { allow(controller).to receive(:other_school_urns) { [] } }
+ before do
+ allow(Schools::DFESignInAPI::Client).to receive(:enabled?).and_return(true)
+ allow(controller).to receive(:other_school_urns).and_return([])
+ end
+
it { expect(subject.send(:has_other_schools?)).to be false }
end
end
diff --git a/spec/controllers/cookie_preferences_controller_spec.rb b/spec/controllers/cookie_preferences_controller_spec.rb
index b29722aefb..39e5558fcc 100644
--- a/spec/controllers/cookie_preferences_controller_spec.rb
+++ b/spec/controllers/cookie_preferences_controller_spec.rb
@@ -1,16 +1,19 @@
require 'rails_helper'
describe CookiePreferencesController, type: :request do
- let(:cookie_name) { 'cookie_preference-v1' }
subject { response }
+ let(:cookie_name) { 'cookie_preference-v1' }
+
describe "#show" do
before { get cookie_preference_path }
+
it { is_expected.to redirect_to(edit_cookie_preference_path) }
end
describe "#edit" do
before { get edit_cookie_preference_path }
+
it { expect(subject.body).to match 'Edit your cookie settings' }
end
@@ -19,17 +22,20 @@
context "with valid" do
let(:params) { { cookie_preference: { analytics: false } } }
+
it { is_expected.to redirect_to edit_cookie_preference_path }
it do
expect(cookies[cookie_name]).to \
eql({ 'analytics' => false, 'required' => true }.to_json)
end
+
it { expect(cookies['analytics_tracking_uuid']).to be_blank }
end
context "with all" do
let(:params) { { cookie_preference: { all: 'true' } } }
+
it { is_expected.to redirect_to edit_cookie_preference_path }
it do
@@ -40,6 +46,7 @@
context "with invalid" do
let(:params) { { cookie_preference: {} } }
+
it { expect(subject.body).to match 'Edit your cookie settings' }
it { expect(cookies[cookie_name]).to be_nil }
end
diff --git a/spec/controllers/features_controller_spec.rb b/spec/controllers/features_controller_spec.rb
index 2c25d63f89..03b87b6755 100644
--- a/spec/controllers/features_controller_spec.rb
+++ b/spec/controllers/features_controller_spec.rb
@@ -6,10 +6,10 @@
before { allow(Feature).to receive(:config).and_return(mock_config) }
describe '#index' do
- before { get feature_flags_path }
-
subject { response.body }
+ before { get feature_flags_path }
+
it "shows a table with the correct markers" do
assert_response :success
diff --git a/spec/controllers/healthchecks_controller_spec.rb b/spec/controllers/healthchecks_controller_spec.rb
index 1fac6f85b7..208040c7fc 100644
--- a/spec/controllers/healthchecks_controller_spec.rb
+++ b/spec/controllers/healthchecks_controller_spec.rb
@@ -20,7 +20,7 @@
allow(ENV).to receive(:[]).with("REDIS_URL").and_return \
"redis://localhost:6379/1"
- allow(REDIS).to receive(:ping) { "PONG" }
+ allow(REDIS).to receive(:ping).and_return("PONG")
allow(ApplicationRecord).to \
receive(:connected?).and_return(true)
diff --git a/spec/controllers/pages_controller_spec.rb b/spec/controllers/pages_controller_spec.rb
index 41032c252b..a1217ebd88 100644
--- a/spec/controllers/pages_controller_spec.rb
+++ b/spec/controllers/pages_controller_spec.rb
@@ -12,7 +12,7 @@
describe 'maintenance mode' do
before do
- allow(Rails.application.config.x).to receive(:maintenance_mode) { true }
+ allow(Rails.application.config.x).to receive(:maintenance_mode).and_return(true)
Rails.application.reload_routes!
end
@@ -21,7 +21,7 @@
Rails.application.reload_routes!
end
- it "will show the maintenance page" do
+ it "shows the maintenance page" do
get root_path
expect(response).to have_http_status(:service_unavailable)
expect(response).to have_attributes body: /service is unavailable/i
diff --git a/spec/controllers/schools/archived_placement_requests_controller_spec.rb b/spec/controllers/schools/archived_placement_requests_controller_spec.rb
index 88132439ef..cbf72f256f 100644
--- a/spec/controllers/schools/archived_placement_requests_controller_spec.rb
+++ b/spec/controllers/schools/archived_placement_requests_controller_spec.rb
@@ -14,13 +14,13 @@
describe '#index' do
subject { response }
- it { is_expected.to have_http_status :success }
- it { is_expected.to render_template 'index' }
-
before do
get schools_archived_placement_requests_path
end
+ it { is_expected.to have_http_status :success }
+ it { is_expected.to render_template 'index' }
+
context 'when flex dates' do
before { create :placement_request, created_at: 3.months.ago, school: school }
diff --git a/spec/controllers/schools/cancelled_bookings_controller_spec.rb b/spec/controllers/schools/cancelled_bookings_controller_spec.rb
index 50f939f0fd..fcf686b26e 100644
--- a/spec/controllers/schools/cancelled_bookings_controller_spec.rb
+++ b/spec/controllers/schools/cancelled_bookings_controller_spec.rb
@@ -14,6 +14,7 @@
describe '#index' do
let(:cancelled_by_school) { create_list(:bookings_booking, 3, :cancelled_by_school, bookings_school: school) }
let(:cancelled_by_candidate) { create_list(:bookings_booking, 2, :cancelled_by_candidate, bookings_school: school) }
+
before { get schools_cancelled_bookings_path }
it { expect(response).to have_http_status(:success) }
@@ -26,6 +27,7 @@
describe '#show' do
let(:cancelled_booking) { create :bookings_booking, :cancelled_by_school, bookings_school: school }
+
before { get schools_cancelled_booking_path(cancelled_booking) }
it { expect(response).to have_http_status(:success) }
diff --git a/spec/controllers/schools/change_schools_controller_spec.rb b/spec/controllers/schools/change_schools_controller_spec.rb
index 199def175f..40d069048f 100644
--- a/spec/controllers/schools/change_schools_controller_spec.rb
+++ b/spec/controllers/schools/change_schools_controller_spec.rb
@@ -15,24 +15,26 @@
end
describe '#show' do
- before do
- allow_any_instance_of(described_class).to \
- receive(:current_urn) { current_urn }
- end
-
subject do
get '/schools/change'
response
end
+ before do
+ allow_any_instance_of(described_class).to \
+ receive(:current_urn) { current_urn }
+ end
+
context 'with URN set' do
let(:current_urn) { old_school.urn }
+
it { is_expected.to have_http_status :success }
it { is_expected.to have_rendered :show }
end
context 'with no URN set' do
let(:current_urn) { nil }
+
it { is_expected.to have_http_status :success }
it { is_expected.to have_rendered :show }
end
@@ -42,7 +44,10 @@
let(:params) { { schools_change_school: { change_to_urn: new_school.urn } } }
context 'when internal school chooser is enabled' do
+ subject { post('/schools/change', params: params) }
+
let(:urns) { [old_school, new_school].map(&:urn) }
+ let(:change_school_page) { get '/schools/change' }
before do
allow_any_instance_of(Schools::DFESignInAPI::RoleCheckedOrganisations).to \
@@ -51,9 +56,6 @@
SecureRandom.uuid => new_school.urn
end
- let(:change_school_page) { get '/schools/change' }
- subject { post('/schools/change', params: params) }
-
context 'when the request access to another school option is chosen' do
let(:params) { { schools_change_school: { change_to_urn: "request access" } } }
@@ -75,23 +77,25 @@
end
context 'when internal changing is disabled' do
+ subject { post('/schools/change', params: params) }
+
let(:enable_school_change) { false }
let(:change_school_page) { get '/schools/change' }
- subject { post('/schools/change', params: params) }
-
specify 'should fail with a 403: forbidden' do
- expect(subject).to eql(403)
+ expect(subject).to be(403)
end
end
context 'when no existing urn set' do
+ subject! { post('/schools/change', params: params) }
+
let(:urns) { [old_school, new_school].map(&:urn) }
let(:change_school_page) { get '/schools/change' }
let(:new_school_uuid) { SecureRandom.uuid }
before do
- allow_any_instance_of(described_class).to receive(:current_urn) { nil }
+ allow_any_instance_of(described_class).to receive(:current_urn).and_return(nil)
allow_any_instance_of(Schools::DFESignInAPI::Organisations).to \
receive(:uuids).and_return new_school_uuid => new_school.urn
@@ -102,8 +106,6 @@
receive(:has_school_experience_role?).and_return(true)
end
- subject! { post('/schools/change', params: params) }
-
it { is_expected.to redirect_to(schools_dashboard_path) }
it 'calls roles API appropriately' do
diff --git a/spec/controllers/schools/confirm_attendance_controller_spec.rb b/spec/controllers/schools/confirm_attendance_controller_spec.rb
index 96144055c1..b93d257d61 100644
--- a/spec/controllers/schools/confirm_attendance_controller_spec.rb
+++ b/spec/controllers/schools/confirm_attendance_controller_spec.rb
@@ -12,12 +12,23 @@
describe '#show' do
subject { get(schools_confirm_attendance_path) }
+
it 'renders the show template' do
expect(subject).to render_template(:show)
end
end
describe '#update' do
+ subject! do
+ put(
+ schools_confirm_attendance_path,
+ params: {
+ attended.id => 'true',
+ unattended.id => 'false',
+ }
+ )
+ end
+
before do
allow(Bookings::Gitis::SchoolExperience).to \
receive(:from_booking) { school_experience }
@@ -50,16 +61,6 @@
end
end
- subject! do
- put(
- schools_confirm_attendance_path,
- params: {
- attended.id => 'true',
- unattended.id => 'false',
- }
- )
- end
-
specify 'should set the attended record attended' do
expect(attended.reload.attended).to be(true)
end
diff --git a/spec/controllers/schools/confirmed_bookings/cancellations/notification_deliveries_controller_spec.rb b/spec/controllers/schools/confirmed_bookings/cancellations/notification_deliveries_controller_spec.rb
index 7122fc43dd..cbfe18ff62 100644
--- a/spec/controllers/schools/confirmed_bookings/cancellations/notification_deliveries_controller_spec.rb
+++ b/spec/controllers/schools/confirmed_bookings/cancellations/notification_deliveries_controller_spec.rb
@@ -41,7 +41,7 @@
end
end
- context '#create' do
+ describe '#create' do
before do
post schools_booking_cancellation_notification_delivery_path \
booking
@@ -130,7 +130,7 @@
end
end
- context '#show' do
+ describe '#show' do
let :placement_request do
FactoryBot.create \
:placement_request, :cancelled_by_school, school: school
diff --git a/spec/controllers/schools/confirmed_bookings/cancellations_controller_spec.rb b/spec/controllers/schools/confirmed_bookings/cancellations_controller_spec.rb
index 07db8fc9dc..1fc3d54900 100644
--- a/spec/controllers/schools/confirmed_bookings/cancellations_controller_spec.rb
+++ b/spec/controllers/schools/confirmed_bookings/cancellations_controller_spec.rb
@@ -19,7 +19,7 @@
create(:bookings_booking, bookings_placement_request: placement_request, bookings_school: school)
end
- context '#new' do
+ describe '#new' do
before do
get new_schools_booking_cancellation_path(booking)
end
@@ -51,7 +51,7 @@
end
end
- context '#create' do
+ describe '#create' do
let :cancellation_params do
{ bookings_placement_request_cancellation: cancellation.attributes }
end
@@ -115,7 +115,7 @@
end
end
- context '#edit' do
+ describe '#edit' do
before do
get edit_schools_booking_cancellation_path(booking.id)
end
@@ -148,7 +148,7 @@
end
end
- context '#update' do
+ describe '#update' do
before do
patch schools_booking_cancellation_path(booking, params: cancellation_params)
end
diff --git a/spec/controllers/schools/confirmed_bookings/date_controller_spec.rb b/spec/controllers/schools/confirmed_bookings/date_controller_spec.rb
index 0c0db2c8c3..e1c7be38a4 100644
--- a/spec/controllers/schools/confirmed_bookings/date_controller_spec.rb
+++ b/spec/controllers/schools/confirmed_bookings/date_controller_spec.rb
@@ -24,12 +24,14 @@
end
specify do
- is_expected.to render_template(:uneditable)
+ expect(subject).to render_template(:uneditable)
end
end
end
describe '#update' do
+ subject { patch schools_booking_date_path(booking.id, params: params) }
+
let(:new_date) { 3.weeks.from_now.to_date }
let(:params) do
{ bookings_booking: { date: new_date.to_formatted_s(:govuk) } }
@@ -37,8 +39,6 @@
let(:old_date) { booking.date }
- subject { patch schools_booking_date_path(booking.id, params: params) }
-
specify 'should redirect to the booking page' do
expect(subject).to redirect_to(schools_booking_date_path(booking))
end
@@ -60,17 +60,16 @@
end
specify do
- is_expected.to render_template(:uneditable)
+ expect(subject).to render_template(:uneditable)
end
end
context 'events' do
before do
allow(Event).to receive(:create).and_return(true)
+ subject
end
- before { subject }
-
specify 'should add an event' do
expect(Event).to have_received(:create).with(
event_type: :booking_date_changed,
@@ -95,10 +94,9 @@
api = GetIntoTeachingApiClient::SchoolsExperienceApi.new
booking.gitis_contact = api.get_schools_experience_sign_up(booking.contact_uuid)
+ subject
end
- before { subject }
-
context "when it's an in school experience" do
specify 'should send a candidate booking date changed email with the correct values' do
expect(NotifyEmail::CandidateBookingDateChanged).to have_received(:from_booking).with(
@@ -127,13 +125,13 @@
end
context 'updating with same date' do
+ subject! { patch schools_booking_date_path(booking.id, params: params) }
+
let(:date) { booking.date }
let(:params) do
{ bookings_booking: { date: date.to_formatted_s(:govuk) } }
end
- subject! { patch schools_booking_date_path(booking.id, params: params) }
-
specify("should render edit page") do
expect(response).to have_http_status 200
expect(response).to have_attributes body: /change the booking date/i
diff --git a/spec/controllers/schools/confirmed_bookings_controller_spec.rb b/spec/controllers/schools/confirmed_bookings_controller_spec.rb
index 561c184afc..e95edf09ef 100644
--- a/spec/controllers/schools/confirmed_bookings_controller_spec.rb
+++ b/spec/controllers/schools/confirmed_bookings_controller_spec.rb
@@ -23,6 +23,7 @@
describe '#show' do
let(:booking) { create(:bookings_booking, :accepted, bookings_school: school) }
+
before { get schools_booking_path(booking) }
it { expect(response).to have_http_status(:success) }
diff --git a/spec/controllers/schools/contact_us_spec.rb b/spec/controllers/schools/contact_us_spec.rb
index cc50c5a39c..b1923259b7 100644
--- a/spec/controllers/schools/contact_us_spec.rb
+++ b/spec/controllers/schools/contact_us_spec.rb
@@ -2,6 +2,11 @@
require Rails.root.join("spec", "controllers", "schools", "session_context")
describe Schools::ContactUsController, type: :request do
+ subject do
+ get schools_contact_us_path
+ Nokogiri.parse(response.body)
+ end
+
shared_examples 'return to manage' do
it "has a 'Return to manage school experience' button" do
expect(subject.search(".govuk-button").any? { |button| button.content == "Go to dashboard" }).to be(false)
@@ -16,11 +21,6 @@
end
end
- subject do
- get schools_contact_us_path
- Nokogiri.parse(response.body)
- end
-
context "when signed in" do
include_context "logged in DfE user"
diff --git a/spec/controllers/schools/csv_exports_controller_spec.rb b/spec/controllers/schools/csv_exports_controller_spec.rb
index 0b5088ae4d..9d5764057e 100644
--- a/spec/controllers/schools/csv_exports_controller_spec.rb
+++ b/spec/controllers/schools/csv_exports_controller_spec.rb
@@ -2,10 +2,10 @@
require Rails.root.join("spec", "controllers", "schools", "session_context")
describe Schools::CsvExportsController, type: :request do
- include_context "logged in DfE user for school with profile"
-
subject { page_request && response }
+ include_context "logged in DfE user for school with profile"
+
describe "#show" do
let(:page_request) { get schools_csv_export_path }
diff --git a/spec/controllers/schools/dashboards_controller_spec.rb b/spec/controllers/schools/dashboards_controller_spec.rb
index d02e7637ea..b5a8e77615 100644
--- a/spec/controllers/schools/dashboards_controller_spec.rb
+++ b/spec/controllers/schools/dashboards_controller_spec.rb
@@ -8,10 +8,10 @@
end
context 'when logged in' do
- include_context "logged in DfE user"
-
subject! { get '/schools/dashboard' }
+ include_context "logged in DfE user"
+
it 'sets the correct school' do
expect(assigns(:school)).to eq(school)
end
@@ -23,14 +23,16 @@
context 'when not logged in' do
subject { get '/schools/dashboard' }
+
it_behaves_like "a protected page"
end
end
context "when the school doesn't exist" do
- include_context "logged in DfE user"
subject { get '/schools/dashboard' }
+ include_context "logged in DfE user"
+
before do
@current_user_school.destroy!
end
@@ -47,7 +49,7 @@
allow(Schools::ChangeSchool).to \
receive(:allow_school_change_in_app?) { allow_school_change }
- allow_any_instance_of(described_class).to receive(:current_urn) { nil }
+ allow_any_instance_of(described_class).to receive(:current_urn).and_return(nil)
get '/schools/dashboard'
end
diff --git a/spec/controllers/schools/errors/insufficient_privileges_controller_spec.rb b/spec/controllers/schools/errors/insufficient_privileges_controller_spec.rb
index 0c0679b250..b7af202f7c 100644
--- a/spec/controllers/schools/errors/insufficient_privileges_controller_spec.rb
+++ b/spec/controllers/schools/errors/insufficient_privileges_controller_spec.rb
@@ -2,10 +2,10 @@
require_relative '../session_context'
describe Schools::Errors::InsufficientPrivilegesController, type: :request do
- include_context "logged in DfE user"
-
subject { get(schools_errors_inaccessible_school_path) && response }
+ include_context "logged in DfE user"
+
describe "#show" do
it { is_expected.to have_http_status :success }
it { expect(subject.body).to match "Request organisation access" }
diff --git a/spec/controllers/schools/feedbacks_controller_spec.rb b/spec/controllers/schools/feedbacks_controller_spec.rb
index d35afaeecf..f2bdb86240 100644
--- a/spec/controllers/schools/feedbacks_controller_spec.rb
+++ b/spec/controllers/schools/feedbacks_controller_spec.rb
@@ -4,7 +4,7 @@
describe Schools::FeedbacksController, type: :request do
include_context "logged in DfE user"
- context '#new' do
+ describe '#new' do
before do
get '/schools/feedbacks/new'
end
@@ -18,7 +18,7 @@
end
end
- context '#create' do
+ describe '#create' do
let :feedback_params do
{ schools_feedback: feedback.attributes }
end
@@ -57,7 +57,7 @@
end
end
- context '#show' do
+ describe '#show' do
let :feedback do
FactoryBot.create :schools_feedback
end
diff --git a/spec/controllers/schools/on_boarding/access_needs_details_controller_spec.rb b/spec/controllers/schools/on_boarding/access_needs_details_controller_spec.rb
index 8cabb167ef..d626e15391 100644
--- a/spec/controllers/schools/on_boarding/access_needs_details_controller_spec.rb
+++ b/spec/controllers/schools/on_boarding/access_needs_details_controller_spec.rb
@@ -5,12 +5,6 @@
include_context "logged in DfE user"
let(:task_progress_on_boarding) { false }
-
- before do
- allow(Feature).to receive(:enabled?).with(:task_progress_on_boarding)
- .and_return(task_progress_on_boarding)
- end
-
let! :school_profile do
FactoryBot.create \
:school_profile,
@@ -29,7 +23,12 @@
:with_access_needs_support
end
- context '#new' do
+ before do
+ allow(Feature).to receive(:enabled?).with(:task_progress_on_boarding)
+ .and_return(task_progress_on_boarding)
+ end
+
+ describe '#new' do
before do
get '/schools/on_boarding/access_needs_detail/new'
end
@@ -44,7 +43,7 @@
end
end
- context '#create' do
+ describe '#create' do
let :params do
{
schools_on_boarding_access_needs_detail: access_needs_detail.attributes
@@ -96,7 +95,7 @@
end
end
- context '#edit' do
+ describe '#edit' do
let! :school_profile do
FactoryBot.create :school_profile, :completed
end
@@ -115,7 +114,7 @@
end
end
- context '#update' do
+ describe '#update' do
let! :school_profile do
FactoryBot.create :school_profile, :completed
end
diff --git a/spec/controllers/schools/on_boarding/access_needs_policies_controller_spec.rb b/spec/controllers/schools/on_boarding/access_needs_policies_controller_spec.rb
index 8cf072c57a..97da593dab 100644
--- a/spec/controllers/schools/on_boarding/access_needs_policies_controller_spec.rb
+++ b/spec/controllers/schools/on_boarding/access_needs_policies_controller_spec.rb
@@ -5,12 +5,6 @@
include_context "logged in DfE user"
let(:task_progress_on_boarding) { false }
-
- before do
- allow(Feature).to receive(:enabled?).with(:task_progress_on_boarding)
- .and_return(task_progress_on_boarding)
- end
-
let! :school_profile do
FactoryBot.create \
:school_profile,
@@ -31,7 +25,12 @@
:with_disability_confident
end
- context '#new' do
+ before do
+ allow(Feature).to receive(:enabled?).with(:task_progress_on_boarding)
+ .and_return(task_progress_on_boarding)
+ end
+
+ describe '#new' do
before do
get '/schools/on_boarding/access_needs_policy/new'
end
@@ -46,7 +45,7 @@
end
end
- context '#create' do
+ describe '#create' do
let :params do
{
schools_on_boarding_access_needs_policy: access_needs_policy.attributes
@@ -97,7 +96,7 @@
end
end
- context '#edit' do
+ describe '#edit' do
let! :school_profile do
FactoryBot.create :school_profile, :completed
end
@@ -116,7 +115,7 @@
end
end
- context '#update' do
+ describe '#update' do
let! :school_profile do
FactoryBot.create :school_profile, :completed
end
diff --git a/spec/controllers/schools/on_boarding/access_needs_supports_controller_spec.rb b/spec/controllers/schools/on_boarding/access_needs_supports_controller_spec.rb
index f5debc8adc..d4965089d5 100644
--- a/spec/controllers/schools/on_boarding/access_needs_supports_controller_spec.rb
+++ b/spec/controllers/schools/on_boarding/access_needs_supports_controller_spec.rb
@@ -11,7 +11,7 @@
.and_return(task_progress_on_boarding)
end
- context '#new' do
+ describe '#new' do
let! :school_profile do
FactoryBot.create \
:school_profile,
@@ -41,7 +41,7 @@
end
end
- context '#create' do
+ describe '#create' do
let! :school_profile do
FactoryBot.create \
:school_profile,
@@ -111,7 +111,7 @@
end
end
- context '#edit' do
+ describe '#edit' do
let! :school_profile do
FactoryBot.create :school_profile, :completed
end
@@ -130,7 +130,7 @@
end
end
- context '#update' do
+ describe '#update' do
let! :school_profile do
FactoryBot.create :school_profile, :completed
end
diff --git a/spec/controllers/schools/on_boarding/admin_contacts_controller_spec.rb b/spec/controllers/schools/on_boarding/admin_contacts_controller_spec.rb
index 1c23014e5a..276fd1a4f9 100644
--- a/spec/controllers/schools/on_boarding/admin_contacts_controller_spec.rb
+++ b/spec/controllers/schools/on_boarding/admin_contacts_controller_spec.rb
@@ -11,7 +11,7 @@
.and_return(task_progress_on_boarding)
end
- context '#new' do
+ describe '#new' do
let! :school_profile do
FactoryBot.create \
:school_profile,
@@ -47,7 +47,7 @@
end
end
- context '#create' do
+ describe '#create' do
let! :school_profile do
FactoryBot.create \
:school_profile,
@@ -119,7 +119,7 @@
end
end
- context '#edit' do
+ describe '#edit' do
let! :school_profile do
FactoryBot.create :school_profile, :completed
end
@@ -137,7 +137,7 @@
end
end
- context '#update' do
+ describe '#update' do
let! :school_profile do
FactoryBot.create :school_profile, :completed
end
diff --git a/spec/controllers/schools/on_boarding/administration_fees_controller_spec.rb b/spec/controllers/schools/on_boarding/administration_fees_controller_spec.rb
index 69e638a3b3..c0a741c3c6 100644
--- a/spec/controllers/schools/on_boarding/administration_fees_controller_spec.rb
+++ b/spec/controllers/schools/on_boarding/administration_fees_controller_spec.rb
@@ -17,7 +17,7 @@
.and_return(task_progress_on_boarding)
end
- context '#new' do
+ describe '#new' do
before do
get '/schools/on_boarding/administration_fee/new'
end
@@ -32,7 +32,7 @@
end
end
- context '#edit' do
+ describe '#edit' do
let! :school_profile do
FactoryBot.create :school_profile, :completed
end
@@ -51,7 +51,7 @@
end
end
- context '#create' do
+ describe '#create' do
let :params do
{ schools_on_boarding_administration_fee: administration_fee.attributes }
end
@@ -71,7 +71,7 @@
end
it "doesn't marks the step as complete" do
- expect(school_profile.reload.administration_fee_step_completed).to_not be true
+ expect(school_profile.reload.administration_fee_step_completed).not_to be true
end
it 'rerenders the new form' do
diff --git a/spec/controllers/schools/on_boarding/candidate_dress_codes_controller_spec.rb b/spec/controllers/schools/on_boarding/candidate_dress_codes_controller_spec.rb
index 246f603827..20b811d2dc 100644
--- a/spec/controllers/schools/on_boarding/candidate_dress_codes_controller_spec.rb
+++ b/spec/controllers/schools/on_boarding/candidate_dress_codes_controller_spec.rb
@@ -12,7 +12,7 @@
.and_return(task_progress_on_boarding)
end
- context '#new' do
+ describe '#new' do
let! :school_profile do
FactoryBot.create \
:school_profile,
@@ -41,7 +41,7 @@
end
end
- context '#create' do
+ describe '#create' do
let! :school_profile do
FactoryBot.create \
:school_profile,
@@ -103,7 +103,7 @@
end
end
- context '#edit' do
+ describe '#edit' do
let! :school_profile do
FactoryBot.create :school_profile, :completed
end
@@ -122,7 +122,7 @@
end
end
- context '#update' do
+ describe '#update' do
let! :school_profile do
FactoryBot.create :school_profile, :completed
end
diff --git a/spec/controllers/schools/on_boarding/candidate_experience_schedules_controller_spec.rb b/spec/controllers/schools/on_boarding/candidate_experience_schedules_controller_spec.rb
index 8b6d37870c..70e2196836 100644
--- a/spec/controllers/schools/on_boarding/candidate_experience_schedules_controller_spec.rb
+++ b/spec/controllers/schools/on_boarding/candidate_experience_schedules_controller_spec.rb
@@ -12,7 +12,7 @@
.and_return(task_progress_on_boarding)
end
- context '#new' do
+ describe '#new' do
let! :school_profile do
FactoryBot.create \
:school_profile,
@@ -43,7 +43,7 @@
end
end
- context '#create' do
+ describe '#create' do
let! :school_profile do
FactoryBot.create \
:school_profile,
@@ -112,7 +112,7 @@
end
end
- context '#edit' do
+ describe '#edit' do
let! :school_profile do
FactoryBot.create :school_profile, :completed
end
@@ -131,7 +131,7 @@
end
end
- context '#update' do
+ describe '#update' do
let! :school_profile do
FactoryBot.create :school_profile, :completed
end
diff --git a/spec/controllers/schools/on_boarding/candidate_parking_informations_controller_spec.rb b/spec/controllers/schools/on_boarding/candidate_parking_informations_controller_spec.rb
index eb97f920de..dc6dab3164 100644
--- a/spec/controllers/schools/on_boarding/candidate_parking_informations_controller_spec.rb
+++ b/spec/controllers/schools/on_boarding/candidate_parking_informations_controller_spec.rb
@@ -12,7 +12,7 @@
.and_return(task_progress_on_boarding)
end
- context '#new' do
+ describe '#new' do
let! :school_profile do
FactoryBot.create \
:school_profile,
@@ -42,7 +42,7 @@
end
end
- context '#create' do
+ describe '#create' do
let! :school_profile do
FactoryBot.create \
:school_profile,
@@ -110,7 +110,7 @@
end
end
- context '#edit' do
+ describe '#edit' do
let! :school_profile do
FactoryBot.create :school_profile, :completed
end
@@ -129,7 +129,7 @@
end
end
- context '#update' do
+ describe '#update' do
let! :school_profile do
FactoryBot.create :school_profile, :completed
end
diff --git a/spec/controllers/schools/on_boarding/candidate_requirements_selections_controller_spec.rb b/spec/controllers/schools/on_boarding/candidate_requirements_selections_controller_spec.rb
index dcf5263f7b..fe79d8e9d5 100644
--- a/spec/controllers/schools/on_boarding/candidate_requirements_selections_controller_spec.rb
+++ b/spec/controllers/schools/on_boarding/candidate_requirements_selections_controller_spec.rb
@@ -15,7 +15,7 @@
.and_return(task_progress_on_boarding)
end
- context '#new' do
+ describe '#new' do
before do
get '/schools/on_boarding/candidate_requirements_selection/new'
end
@@ -30,7 +30,7 @@
end
end
- context '#create' do
+ describe '#create' do
let :params do
{
schools_on_boarding_candidate_requirements_selection: \
@@ -82,7 +82,7 @@
end
end
- context '#edit' do
+ describe '#edit' do
let! :school_profile do
FactoryBot.create :school_profile, \
:completed, :with_candidate_requirements_selection
@@ -102,7 +102,7 @@
end
end
- context '#update' do
+ describe '#update' do
let! :school_profile do
FactoryBot.create :school_profile, \
:completed, :with_candidate_requirements_selection
diff --git a/spec/controllers/schools/on_boarding/confirmations_controller_spec.rb b/spec/controllers/schools/on_boarding/confirmations_controller_spec.rb
index 5386030a3b..b740295d73 100644
--- a/spec/controllers/schools/on_boarding/confirmations_controller_spec.rb
+++ b/spec/controllers/schools/on_boarding/confirmations_controller_spec.rb
@@ -8,7 +8,7 @@
FactoryBot.create :school_profile, :completed
end
- context '#create' do
+ describe '#create' do
let :params do
{
schools_on_boarding_confirmation: confirmation.attributes
@@ -56,7 +56,7 @@
end
end
- context '#show' do
+ describe '#show' do
context 'when the profile is incomplete' do
before do
get '/schools/on_boarding/confirmation'
diff --git a/spec/controllers/schools/on_boarding/dbs_fees_controller_spec.rb b/spec/controllers/schools/on_boarding/dbs_fees_controller_spec.rb
index 5c50064b47..1fd15d1027 100644
--- a/spec/controllers/schools/on_boarding/dbs_fees_controller_spec.rb
+++ b/spec/controllers/schools/on_boarding/dbs_fees_controller_spec.rb
@@ -19,7 +19,7 @@
.and_return(task_progress_on_boarding)
end
- context '#new' do
+ describe '#new' do
before do
get '/schools/on_boarding/dbs_fee/new'
end
@@ -33,7 +33,7 @@
end
end
- context '#edit' do
+ describe '#edit' do
let! :school_profile do
FactoryBot.create :school_profile, :completed
end
@@ -52,7 +52,7 @@
end
end
- context '#create' do
+ describe '#create' do
let :params do
{ schools_on_boarding_dbs_fee: dbs_fee.attributes }
end
@@ -71,7 +71,7 @@
end
it "doesn't mark the step as complete" do
- expect(school_profile.reload.dbs_fee_step_completed).to_not be true
+ expect(school_profile.reload.dbs_fee_step_completed).not_to be true
end
it 'rerenders the new form' do
diff --git a/spec/controllers/schools/on_boarding/dbs_requirements_controller_spec.rb b/spec/controllers/schools/on_boarding/dbs_requirements_controller_spec.rb
index 3e4d190aae..4b485c4b39 100644
--- a/spec/controllers/schools/on_boarding/dbs_requirements_controller_spec.rb
+++ b/spec/controllers/schools/on_boarding/dbs_requirements_controller_spec.rb
@@ -11,7 +11,7 @@
.and_return(task_progress_on_boarding)
end
- context '#new' do
+ describe '#new' do
let! :school_profile do
create :school_profile
end
@@ -28,7 +28,7 @@
end
end
- context '#create' do
+ describe '#create' do
let! :school_profile do
create :school_profile
end
@@ -81,7 +81,7 @@
end
end
- context '#edit' do
+ describe '#edit' do
let! :school_profile do
create :school_profile, :completed
end
@@ -98,7 +98,7 @@
end
end
- context '#update' do
+ describe '#update' do
let! :school_profile do
create :school_profile, :completed
end
diff --git a/spec/controllers/schools/on_boarding/descriptions_controller_spec.rb b/spec/controllers/schools/on_boarding/descriptions_controller_spec.rb
index 816483e95d..a4de4e3316 100644
--- a/spec/controllers/schools/on_boarding/descriptions_controller_spec.rb
+++ b/spec/controllers/schools/on_boarding/descriptions_controller_spec.rb
@@ -12,7 +12,7 @@
.and_return(task_progress_on_boarding)
end
- context '#new' do
+ describe '#new' do
let! :school_profile do
FactoryBot.create \
:school_profile,
@@ -39,7 +39,7 @@
end
end
- context '#create' do
+ describe '#create' do
let! :school_profile do
FactoryBot.create \
:school_profile,
@@ -124,7 +124,7 @@
end
end
- context '#edit' do
+ describe '#edit' do
let! :school_profile do
FactoryBot.create :school_profile, :completed
end
@@ -142,7 +142,7 @@
end
end
- context '#update' do
+ describe '#update' do
let! :school_profile do
FactoryBot.create :school_profile, :completed
end
diff --git a/spec/controllers/schools/on_boarding/disability_confidents_controller_spec.rb b/spec/controllers/schools/on_boarding/disability_confidents_controller_spec.rb
index b5826dec2b..a9118bad86 100644
--- a/spec/controllers/schools/on_boarding/disability_confidents_controller_spec.rb
+++ b/spec/controllers/schools/on_boarding/disability_confidents_controller_spec.rb
@@ -5,12 +5,6 @@
include_context "logged in DfE user"
let(:task_progress_on_boarding) { false }
-
- before do
- allow(Feature).to receive(:enabled?).with(:task_progress_on_boarding)
- .and_return(task_progress_on_boarding)
- end
-
let! :school_profile do
FactoryBot.create \
:school_profile,
@@ -30,7 +24,12 @@
:with_access_needs_detail
end
- context '#new' do
+ before do
+ allow(Feature).to receive(:enabled?).with(:task_progress_on_boarding)
+ .and_return(task_progress_on_boarding)
+ end
+
+ describe '#new' do
before do
get '/schools/on_boarding/disability_confident/new'
end
@@ -45,7 +44,7 @@
end
end
- context '#create' do
+ describe '#create' do
let :params do
{
schools_on_boarding_disability_confident: \
@@ -98,7 +97,7 @@
end
end
- context '#edit' do
+ describe '#edit' do
let! :school_profile do
FactoryBot.create :school_profile, :completed
end
@@ -117,7 +116,7 @@
end
end
- context '#update' do
+ describe '#update' do
let! :school_profile do
FactoryBot.create :school_profile, :completed
end
diff --git a/spec/controllers/schools/on_boarding/experience_outlines_controller_spec.rb b/spec/controllers/schools/on_boarding/experience_outlines_controller_spec.rb
index 40a87defe8..eb968170de 100644
--- a/spec/controllers/schools/on_boarding/experience_outlines_controller_spec.rb
+++ b/spec/controllers/schools/on_boarding/experience_outlines_controller_spec.rb
@@ -11,7 +11,7 @@
.and_return(task_progress_on_boarding)
end
- context '#new' do
+ describe '#new' do
let! :school_profile do
FactoryBot.create \
:school_profile,
@@ -45,7 +45,7 @@
end
end
- context '#create' do
+ describe '#create' do
let! :school_profile do
FactoryBot.create \
:school_profile,
@@ -103,7 +103,7 @@
end
end
- context '#edit' do
+ describe '#edit' do
let! :school_profile do
FactoryBot.create :school_profile, :completed
end
@@ -121,7 +121,7 @@
end
end
- context '#update' do
+ describe '#update' do
let! :school_profile do
FactoryBot.create :school_profile, :completed
end
diff --git a/spec/controllers/schools/on_boarding/fees_controller_spec.rb b/spec/controllers/schools/on_boarding/fees_controller_spec.rb
index f2d23047fa..6109957cf8 100644
--- a/spec/controllers/schools/on_boarding/fees_controller_spec.rb
+++ b/spec/controllers/schools/on_boarding/fees_controller_spec.rb
@@ -4,7 +4,7 @@
describe Schools::OnBoarding::FeesController, type: :request do
include_context "logged in DfE user"
- context '#new' do
+ describe '#new' do
let! :school_profile do
FactoryBot.create :school_profile,
:with_dbs_requirement,
@@ -15,9 +15,6 @@
before do
allow(Feature).to receive(:enabled?).with(:task_progress_on_boarding)
.and_return(task_progress_on_boarding)
- end
-
- before do
get '/schools/on_boarding/fees/new'
end
@@ -30,7 +27,7 @@
end
end
- context '#create' do
+ describe '#create' do
let! :school_profile do
FactoryBot.create :school_profile,
:with_dbs_requirement,
@@ -84,7 +81,7 @@
end
end
- context '#edit' do
+ describe '#edit' do
let! :school_profile do
FactoryBot.create :school_profile, :completed
end
@@ -102,7 +99,7 @@
end
end
- context '#update' do
+ describe '#update' do
let! :school_profile do
FactoryBot.create :school_profile, :completed
end
diff --git a/spec/controllers/schools/on_boarding/key_stage_lists_controller_spec.rb b/spec/controllers/schools/on_boarding/key_stage_lists_controller_spec.rb
index 155428b0c7..603a075293 100644
--- a/spec/controllers/schools/on_boarding/key_stage_lists_controller_spec.rb
+++ b/spec/controllers/schools/on_boarding/key_stage_lists_controller_spec.rb
@@ -12,7 +12,7 @@
.and_return(task_progress_on_boarding)
end
- context '#new' do
+ describe '#new' do
let! :school_profile do
FactoryBot.create \
:school_profile,
@@ -39,7 +39,7 @@
end
end
- context '#create' do
+ describe '#create' do
let! :school_profile do
FactoryBot.create \
:school_profile,
@@ -97,7 +97,7 @@
end
end
- context '#edit' do
+ describe '#edit' do
let! :school_profile do
FactoryBot.create :school_profile, :completed
end
@@ -115,7 +115,7 @@
end
end
- context '#update' do
+ describe '#update' do
let! :school_profile do
FactoryBot.create :school_profile, :completed
end
diff --git a/spec/controllers/schools/on_boarding/other_fees_controller_spec.rb b/spec/controllers/schools/on_boarding/other_fees_controller_spec.rb
index 3cc461df1c..0d6d82915c 100644
--- a/spec/controllers/schools/on_boarding/other_fees_controller_spec.rb
+++ b/spec/controllers/schools/on_boarding/other_fees_controller_spec.rb
@@ -21,7 +21,7 @@
.and_return(task_progress_on_boarding)
end
- context '#new' do
+ describe '#new' do
before do
get '/schools/on_boarding/other_fee/new'
end
@@ -35,7 +35,7 @@
end
end
- context '#edit' do
+ describe '#edit' do
let! :school_profile do
FactoryBot.create :school_profile, :completed
end
@@ -54,7 +54,7 @@
end
end
- context '#create' do
+ describe '#create' do
let :params do
{ schools_on_boarding_other_fee: other_fee.attributes }
end
@@ -73,7 +73,7 @@
end
it "doesn't mark the step as complete" do
- expect(school_profile.reload.other_fee_step_completed).to_not be true
+ expect(school_profile.reload.other_fee_step_completed).not_to be true
end
it 'rerenders the new form' do
diff --git a/spec/controllers/schools/on_boarding/phases_lists_controller_spec.rb b/spec/controllers/schools/on_boarding/phases_lists_controller_spec.rb
index 851402b5e6..4b48613d8a 100644
--- a/spec/controllers/schools/on_boarding/phases_lists_controller_spec.rb
+++ b/spec/controllers/schools/on_boarding/phases_lists_controller_spec.rb
@@ -12,7 +12,7 @@
.and_return(task_progress_on_boarding)
end
- context '#new' do
+ describe '#new' do
let! :school_profile do
FactoryBot.create \
:school_profile,
@@ -37,7 +37,7 @@
end
end
- context '#create' do
+ describe '#create' do
let! :school_profile do
FactoryBot.create \
:school_profile,
@@ -96,7 +96,7 @@
end
end
- context '#edit' do
+ describe '#edit' do
let! :school_profile do
FactoryBot.create :school_profile, :completed
end
@@ -114,7 +114,7 @@
end
end
- context '#update' do
+ describe '#update' do
let! :school_profile do
FactoryBot.create :school_profile, :completed
end
diff --git a/spec/controllers/schools/on_boarding/previews_controller_spec.rb b/spec/controllers/schools/on_boarding/previews_controller_spec.rb
index b0611cac42..949ae578d6 100644
--- a/spec/controllers/schools/on_boarding/previews_controller_spec.rb
+++ b/spec/controllers/schools/on_boarding/previews_controller_spec.rb
@@ -24,7 +24,7 @@
FactoryBot.create :bookings_school
end
- context '#show' do
+ describe '#show' do
context 'when profile is not complete' do
let! :school_profile do
FactoryBot.create :school_profile, bookings_school: school
diff --git a/spec/controllers/schools/on_boarding/profiles_controller_spec.rb b/spec/controllers/schools/on_boarding/profiles_controller_spec.rb
index c89a089ae4..d3d60b5d8f 100644
--- a/spec/controllers/schools/on_boarding/profiles_controller_spec.rb
+++ b/spec/controllers/schools/on_boarding/profiles_controller_spec.rb
@@ -25,7 +25,7 @@
FactoryBot.create :school_profile, :completed
end
- context '#show' do
+ describe '#show' do
before do
get '/schools/on_boarding/profile'
end
diff --git a/spec/controllers/schools/on_boarding/progresses_controller_spec.rb b/spec/controllers/schools/on_boarding/progresses_controller_spec.rb
index 4fd86599c5..1d58d28a7a 100644
--- a/spec/controllers/schools/on_boarding/progresses_controller_spec.rb
+++ b/spec/controllers/schools/on_boarding/progresses_controller_spec.rb
@@ -5,7 +5,7 @@
include_context "logged in DfE user"
include_context "stub role check api"
- context "#show" do
+ describe "#show" do
let!(:school_profile) { create(:school_profile, :with_dbs_requirement) }
before { get schools_on_boarding_progress_path }
diff --git a/spec/controllers/schools/on_boarding/subjects_controller_spec.rb b/spec/controllers/schools/on_boarding/subjects_controller_spec.rb
index 7e8f47c0a4..cb671b9e6e 100644
--- a/spec/controllers/schools/on_boarding/subjects_controller_spec.rb
+++ b/spec/controllers/schools/on_boarding/subjects_controller_spec.rb
@@ -8,13 +8,6 @@
let! :bookings_subject do
FactoryBot.create :bookings_subject
end
- let(:task_progress_on_boarding) { false }
-
- before do
- allow(Feature).to receive(:enabled?).with(:task_progress_on_boarding)
- .and_return(task_progress_on_boarding)
- end
-
let! :school_profile do
FactoryBot.create \
:school_profile,
@@ -27,8 +20,14 @@
:with_phases,
:with_key_stage_list
end
+ let(:task_progress_on_boarding) { false }
+
+ before do
+ allow(Feature).to receive(:enabled?).with(:task_progress_on_boarding)
+ .and_return(task_progress_on_boarding)
+ end
- context '#new' do
+ describe '#new' do
before do
get '/schools/on_boarding/subjects/new'
end
@@ -42,7 +41,7 @@
end
end
- context '#create' do
+ describe '#create' do
before do
post '/schools/on_boarding/subjects', params: params
end
@@ -91,7 +90,7 @@
end
end
- context '#edit' do
+ describe '#edit' do
let! :school_profile do
FactoryBot.create :school_profile, :completed
end
@@ -110,7 +109,7 @@
end
end
- context '#update' do
+ describe '#update' do
let! :school_profile do
FactoryBot.create :school_profile, :completed
end
diff --git a/spec/controllers/schools/on_boarding/teacher_trainings_controller_spec.rb b/spec/controllers/schools/on_boarding/teacher_trainings_controller_spec.rb
index 9c41f6c809..f35e865748 100644
--- a/spec/controllers/schools/on_boarding/teacher_trainings_controller_spec.rb
+++ b/spec/controllers/schools/on_boarding/teacher_trainings_controller_spec.rb
@@ -11,7 +11,7 @@
.and_return(task_progress_on_boarding)
end
- context '#new' do
+ describe '#new' do
let! :school_profile do
FactoryBot.create \
:school_profile,
@@ -47,7 +47,7 @@
end
end
- context '#create' do
+ describe '#create' do
let! :school_profile do
FactoryBot.create \
:school_profile,
@@ -120,7 +120,7 @@
end
end
- context '#edit' do
+ describe '#edit' do
let! :school_profile do
FactoryBot.create :school_profile, :completed
end
@@ -138,7 +138,7 @@
end
end
- context '#update' do
+ describe '#update' do
let! :school_profile do
FactoryBot.create :school_profile, :completed
end
diff --git a/spec/controllers/schools/organisation_access_requests_controller_spec.rb b/spec/controllers/schools/organisation_access_requests_controller_spec.rb
index f0bdf900c0..bb0016407d 100644
--- a/spec/controllers/schools/organisation_access_requests_controller_spec.rb
+++ b/spec/controllers/schools/organisation_access_requests_controller_spec.rb
@@ -2,10 +2,10 @@
require Rails.root.join("spec", "controllers", "schools", "session_context")
RSpec.describe Schools::OrganisationAccessRequestsController, type: :request do
- include_context "logged in DfE user"
-
subject { page_request && response }
+ include_context "logged in DfE user"
+
before do
allow(Rails.application.config.x).to \
receive(:dfe_sign_in_request_organisation_url) \
diff --git a/spec/controllers/schools/placement_dates/configurations_controller_spec.rb b/spec/controllers/schools/placement_dates/configurations_controller_spec.rb
index 9a78aedb2c..b620f929f9 100644
--- a/spec/controllers/schools/placement_dates/configurations_controller_spec.rb
+++ b/spec/controllers/schools/placement_dates/configurations_controller_spec.rb
@@ -15,7 +15,7 @@
create :bookings_placement_date, bookings_school: school, published_at: nil
end
- context '#new' do
+ describe '#new' do
before do
get "/schools/placement_dates/#{placement_date.id}/configuration/new"
end
@@ -29,7 +29,7 @@
end
end
- context '#create' do
+ describe '#create' do
let :params do
{
schools_placement_dates_configuration_form: {
@@ -65,7 +65,7 @@
end
it "doesn't update the placement_date" do
- expect(placement_date.max_bookings_count).to be nil
+ expect(placement_date.max_bookings_count).to be_nil
end
end
diff --git a/spec/controllers/schools/placement_dates/placement_details_controller_spec.rb b/spec/controllers/schools/placement_dates/placement_details_controller_spec.rb
index 3eb82e83c3..987d794526 100644
--- a/spec/controllers/schools/placement_dates/placement_details_controller_spec.rb
+++ b/spec/controllers/schools/placement_dates/placement_details_controller_spec.rb
@@ -9,7 +9,7 @@
let(:placement_date) { create :bookings_placement_date, bookings_school: school, supports_subjects: false }
- context '#new' do
+ describe '#new' do
before do
get "/schools/placement_dates/#{placement_date.id}/placement_detail/new"
end
@@ -23,7 +23,7 @@
end
end
- context '#create' do
+ describe '#create' do
subject do
post "/schools/placement_dates/#{placement_date.id}/placement_detail",
params: params
diff --git a/spec/controllers/schools/placement_dates/publish_dates_controller_spec.rb b/spec/controllers/schools/placement_dates/publish_dates_controller_spec.rb
index 996756e1fc..6a7aca1f43 100644
--- a/spec/controllers/schools/placement_dates/publish_dates_controller_spec.rb
+++ b/spec/controllers/schools/placement_dates/publish_dates_controller_spec.rb
@@ -21,7 +21,7 @@
post schools_placement_date_recurrences_selection_path(placement_date.id), params: params
end
- context "#new" do
+ describe "#new" do
before do
get new_schools_placement_date_publish_dates_path(placement_date.id)
end
@@ -29,7 +29,7 @@
it { is_expected.to render_template(:new) }
end
- context "#create" do
+ describe "#create" do
let(:submitted_dates) { date_range }
before do
diff --git a/spec/controllers/schools/placement_dates/recurrences_selections_controller_spec.rb b/spec/controllers/schools/placement_dates/recurrences_selections_controller_spec.rb
index 75657139e8..d41c12fde0 100644
--- a/spec/controllers/schools/placement_dates/recurrences_selections_controller_spec.rb
+++ b/spec/controllers/schools/placement_dates/recurrences_selections_controller_spec.rb
@@ -8,7 +8,7 @@
let(:placement_date) { create :bookings_placement_date, bookings_school: school, supports_subjects: false, recurring: true, published_at: nil }
- context '#new' do
+ describe '#new' do
before do
get new_schools_placement_date_recurrences_selection_path(placement_date.id)
end
@@ -22,7 +22,7 @@
end
end
- context '#create' do
+ describe '#create' do
subject(:perform_request) do
post "/schools/placement_dates/#{placement_date.id}/recurrences_selection", params: params
response
diff --git a/spec/controllers/schools/placement_dates/review_recurrences_controller_spec.rb b/spec/controllers/schools/placement_dates/review_recurrences_controller_spec.rb
index e8e88eceaf..cfbdcaa98e 100644
--- a/spec/controllers/schools/placement_dates/review_recurrences_controller_spec.rb
+++ b/spec/controllers/schools/placement_dates/review_recurrences_controller_spec.rb
@@ -21,7 +21,7 @@
post schools_placement_date_recurrences_selection_path(placement_date.id), params: params
end
- context "#new" do
+ describe "#new" do
before do
get new_schools_placement_date_review_recurrences_path(placement_date.id)
end
@@ -44,7 +44,7 @@
end
end
- context "#create" do
+ describe "#create" do
let(:submitted_dates) { date_range }
before do
diff --git a/spec/controllers/schools/placement_dates/subject_selections_controller_spec.rb b/spec/controllers/schools/placement_dates/subject_selections_controller_spec.rb
index b51bdda6d8..4e26980146 100644
--- a/spec/controllers/schools/placement_dates/subject_selections_controller_spec.rb
+++ b/spec/controllers/schools/placement_dates/subject_selections_controller_spec.rb
@@ -22,7 +22,7 @@
include_context "logged in DfE user"
- context '#new' do
+ describe '#new' do
before do
get "/schools/placement_dates/#{placement_date.id}/subject_selection/new"
end
@@ -36,7 +36,7 @@
end
end
- context '#create' do
+ describe '#create' do
let :params do
{
schools_placement_dates_subject_selection: { subject_ids: subject_ids }
diff --git a/spec/controllers/schools/placement_dates_controller_spec.rb b/spec/controllers/schools/placement_dates_controller_spec.rb
index 8066499095..13a2ade904 100644
--- a/spec/controllers/schools/placement_dates_controller_spec.rb
+++ b/spec/controllers/schools/placement_dates_controller_spec.rb
@@ -46,7 +46,7 @@
end
end
- context '#edit' do
+ describe '#edit' do
let(:placement_date) { create :bookings_placement_date, bookings_school: school }
before { get "/schools/placement_dates/#{placement_date.id}/edit" }
@@ -58,7 +58,7 @@
end
end
- context '#close' do
+ describe '#close' do
let(:placement_date) { create :bookings_placement_date, :active, bookings_school: school }
context 'when confirmed' do
diff --git a/spec/controllers/schools/placement_requests/acceptance/confirm_booking_controller_spec.rb b/spec/controllers/schools/placement_requests/acceptance/confirm_booking_controller_spec.rb
index 55876ccbf9..664c4e8546 100644
--- a/spec/controllers/schools/placement_requests/acceptance/confirm_booking_controller_spec.rb
+++ b/spec/controllers/schools/placement_requests/acceptance/confirm_booking_controller_spec.rb
@@ -5,9 +5,10 @@
include_context "logged in DfE user"
let!(:pr) { create(:bookings_placement_request, school: @current_user_school) }
+
before { create(:bookings_profile, school: @current_user_school) }
- context '#new' do
+ describe '#new' do
before do
get new_schools_placement_request_acceptance_confirm_booking_path(pr.id)
end
diff --git a/spec/controllers/schools/placement_requests/acceptance/make_changes_controller_spec.rb b/spec/controllers/schools/placement_requests/acceptance/make_changes_controller_spec.rb
index 2c307aa9fe..87c5bed2ad 100644
--- a/spec/controllers/schools/placement_requests/acceptance/make_changes_controller_spec.rb
+++ b/spec/controllers/schools/placement_requests/acceptance/make_changes_controller_spec.rb
@@ -10,7 +10,7 @@
create(:bookings_profile, school: @current_user_school)
end
- context '#new' do
+ describe '#new' do
before do
get new_schools_placement_request_acceptance_make_changes_path(pr.id)
end
@@ -20,7 +20,7 @@
end
end
- context '#create' do
+ describe '#create' do
before { post schools_placement_request_acceptance_make_changes_path(pr.id, params: params) }
let(:future_date) { 3.weeks.from_now.to_date }
@@ -32,6 +32,8 @@
let(:experience_type) { "inschool" }
context 'with valid params' do
+ subject { Bookings::Booking.last }
+
let(:params) do
{
bookings_booking: {
@@ -45,8 +47,6 @@
}
end
- subject { Bookings::Booking.last }
-
specify 'should add supplied params to a booking' do
expect(subject.date).to eql(future_date)
expect(subject.bookings_subject_id).to eql(bookings_subject.id)
diff --git a/spec/controllers/schools/placement_requests/acceptance/preview_confirmation_email_controller_spec.rb b/spec/controllers/schools/placement_requests/acceptance/preview_confirmation_email_controller_spec.rb
index 838e08414f..17270cfaed 100644
--- a/spec/controllers/schools/placement_requests/acceptance/preview_confirmation_email_controller_spec.rb
+++ b/spec/controllers/schools/placement_requests/acceptance/preview_confirmation_email_controller_spec.rb
@@ -32,7 +32,7 @@
api.get_schools_experience_sign_up(pr.contact_uuid)
end
- context '#edit' do
+ describe '#edit' do
before do
get edit_schools_placement_request_acceptance_preview_confirmation_email_path(pr.id)
end
@@ -44,7 +44,7 @@
end
end
- context '#update' do
+ describe '#update' do
before do
allow(Bookings::Gitis::SchoolExperience).to \
receive(:from_booking) { school_experience }
@@ -60,12 +60,11 @@
allow(NotifySms::CandidateBookingConfirmation).to receive(:new) do
candidate_booking_confirmation_sms
end
+ patch schools_placement_request_acceptance_preview_confirmation_email_path(pr.id, params)
end
let(:params) { { bookings_booking: { candidate_instructions: 'Come to the main reception' } } }
- before { patch schools_placement_request_acceptance_preview_confirmation_email_path(pr.id, params) }
-
specify 'should send a candidate booking confirmation notification email' do
expect(NotifyEmail::CandidateBookingConfirmation).to have_received(:from_booking)
end
diff --git a/spec/controllers/schools/placement_requests/cancellations/notification_deliveries_controller_spec.rb b/spec/controllers/schools/placement_requests/cancellations/notification_deliveries_controller_spec.rb
index aaefdc31a7..f58bf0f1f8 100644
--- a/spec/controllers/schools/placement_requests/cancellations/notification_deliveries_controller_spec.rb
+++ b/spec/controllers/schools/placement_requests/cancellations/notification_deliveries_controller_spec.rb
@@ -32,7 +32,7 @@
receive(:write_to_gitis_contact)
end
- context '#create' do
+ describe '#create' do
before do
post schools_placement_request_cancellation_notification_delivery_path \
placement_request
@@ -102,7 +102,7 @@
end
end
- context '#show' do
+ describe '#show' do
let :placement_request do
FactoryBot.create \
:placement_request, :cancelled_by_school, school: school
diff --git a/spec/controllers/schools/placement_requests/cancellations_controller_spec.rb b/spec/controllers/schools/placement_requests/cancellations_controller_spec.rb
index 9113d91194..715e86018c 100644
--- a/spec/controllers/schools/placement_requests/cancellations_controller_spec.rb
+++ b/spec/controllers/schools/placement_requests/cancellations_controller_spec.rb
@@ -11,7 +11,7 @@
end
end
- context '#new' do
+ describe '#new' do
before do
get "/schools/placement_requests/#{placement_request.id}/cancellation/new"
end
@@ -43,7 +43,7 @@
end
end
- context '#create' do
+ describe '#create' do
let :cancellation_params do
{ bookings_placement_request_cancellation: cancellation.attributes.merge(other: true) }
end
@@ -108,7 +108,7 @@
end
end
- context '#edit' do
+ describe '#edit' do
before do
get "/schools/placement_requests/#{placement_request.id}/cancellation/edit"
end
@@ -141,7 +141,7 @@
end
end
- context '#update' do
+ describe '#update' do
before do
patch "/schools/placement_requests/#{placement_request.id}/cancellation",
params: cancellation_params
diff --git a/spec/controllers/schools/placement_requests/past_attendance_controller_spec.rb b/spec/controllers/schools/placement_requests/past_attendance_controller_spec.rb
index 8ebf388435..854ce5165e 100644
--- a/spec/controllers/schools/placement_requests/past_attendance_controller_spec.rb
+++ b/spec/controllers/schools/placement_requests/past_attendance_controller_spec.rb
@@ -8,6 +8,11 @@
let!(:profile) { create :bookings_profile, school: school }
describe '#index' do
+ subject do
+ get schools_placement_request_past_attendances_path(pr.id)
+ response
+ end
+
let(:booking) do
create :bookings_booking, :accepted, :attended, bookings_school: school,
bookings_placement_request:
@@ -19,11 +24,6 @@
candidate: booking.bookings_placement_request.candidate
end
- subject do
- get schools_placement_request_past_attendances_path(pr.id)
- response
- end
-
it { is_expected.to have_http_status :success }
it { is_expected.to render_template 'index' }
end
diff --git a/spec/controllers/schools/placement_requests/under_consideration_controller_spec.rb b/spec/controllers/schools/placement_requests/under_consideration_controller_spec.rb
index cc615ca7d8..3c46ecc06d 100644
--- a/spec/controllers/schools/placement_requests/under_consideration_controller_spec.rb
+++ b/spec/controllers/schools/placement_requests/under_consideration_controller_spec.rb
@@ -5,16 +5,17 @@
include_context "logged in DfE user"
describe '#place_under_consideration' do
- include_context "logged in DfE user"
-
subject do
put schools_placement_request_schools_placement_requests_place_under_consideration_path(placement_request_id)
response
end
+ include_context "logged in DfE user"
+
context 'when there is a placement request' do
let!(:pr) { create(:bookings_placement_request, school: @current_user_school) }
let(:placement_request_id) { pr.id }
+
before { create(:bookings_profile, school: @current_user_school) }
it { is_expected.to have_http_status :redirect }
@@ -23,6 +24,7 @@
context 'when there is not a placement request' do
let(:placement_request_id) { 1 }
+
before { create(:bookings_profile, school: @current_user_school) }
it { is_expected.to have_http_status :not_found }
diff --git a/spec/controllers/schools/placement_requests_controller_spec.rb b/spec/controllers/schools/placement_requests_controller_spec.rb
index 997c1751ce..e75ccae38b 100644
--- a/spec/controllers/schools/placement_requests_controller_spec.rb
+++ b/spec/controllers/schools/placement_requests_controller_spec.rb
@@ -17,7 +17,7 @@
school.subjects << FactoryBot.create_list(:bookings_subject, 1)
end
- context '#index' do
+ describe '#index' do
let!(:placement_requests) do
FactoryBot.create_list :placement_request, 2, school: school
end
@@ -60,7 +60,7 @@
it 'assigns the placement_requests belonging to the school' do
expect(assigns(:placement_requests)).to match_array school.placement_requests
expect(assigns(:placement_requests).map(&:gitis_contact)).to all \
- be_kind_of GetIntoTeachingApiClient::SchoolsExperienceSignUp
+ be_a GetIntoTeachingApiClient::SchoolsExperienceSignUp
end
it 'renders the index template' do
@@ -70,6 +70,7 @@
context 'after placement requests have been accepted' do
let(:booked) { placement_requests.last }
+
before do
create :bookings_booking, :accepted,
bookings_placement_request: booked,
@@ -86,6 +87,7 @@
context 'after placement requests have been rejected' do
let(:rejected) { placement_requests.last }
+
before do
create :cancellation, :cancelled_by_school,
placement_request: rejected
@@ -119,7 +121,7 @@
ids = placement_requests.map(&:contact_uuid)
allow_any_instance_of(GetIntoTeachingApiClient::SchoolsExperienceApi).to \
receive(:get_schools_experience_sign_ups)
- .with(a_collection_containing_exactly(*ids)) { [] }
+ .with(a_collection_containing_exactly(*ids)).and_return([])
get "/schools/placement_requests"
end
@@ -131,7 +133,7 @@
end
end
- context '#show' do
+ describe '#show' do
context 'with a new placement request' do
before do
get "/schools/placement_requests/#{placement_request.id}"
@@ -170,6 +172,7 @@
context 'cannot find the placement request' do
subject { get(schools_placement_request_path(placement_request.id)) }
+
let(:another_school) { create(:bookings_school) }
let(:placement_request) { create(:bookings_placement_request, school: another_school) }
diff --git a/spec/controllers/schools/prepopulate_school_profiles_controller_spec.rb b/spec/controllers/schools/prepopulate_school_profiles_controller_spec.rb
index c91de40172..b6b0d51dc8 100644
--- a/spec/controllers/schools/prepopulate_school_profiles_controller_spec.rb
+++ b/spec/controllers/schools/prepopulate_school_profiles_controller_spec.rb
@@ -6,6 +6,8 @@
include_context "stub role check api"
describe "#create" do
+ subject { post(schools_prepopulate_school_profiles_path, params: params) }
+
before do
allow_any_instance_of(Schools::DFESignInAPI::RoleCheckedOrganisations).to \
receive(:organisation_uuid_pairs).and_return \
@@ -16,10 +18,8 @@
let(:prepopulate_from_school) { create(:bookings_school, :with_school_profile, :onboarded) }
let(:params) { { schools_prepopulate_school_profile: { prepopulate_from_urn: prepopulate_from_school.urn } } }
- subject { post(schools_prepopulate_school_profiles_path, params: params) }
-
it "prepopulates the school profile" do
- is_expected.to redirect_to(schools_on_boarding_progress_path)
+ expect(subject).to redirect_to(schools_on_boarding_progress_path)
follow_redirect!
diff --git a/spec/controllers/schools/previous_bookings_controller_spec.rb b/spec/controllers/schools/previous_bookings_controller_spec.rb
index a1cd418944..eb4a06261d 100644
--- a/spec/controllers/schools/previous_bookings_controller_spec.rb
+++ b/spec/controllers/schools/previous_bookings_controller_spec.rb
@@ -23,6 +23,7 @@
describe '#show' do
let(:booking) { create :bookings_booking, :previous, :accepted, bookings_school: school }
+
before { get schools_previous_booking_path(booking) }
it { expect(response).to have_http_status(:success) }
diff --git a/spec/controllers/schools/rejected_requests_controller_spec.rb b/spec/controllers/schools/rejected_requests_controller_spec.rb
index 7bdd52d054..01338b35e3 100644
--- a/spec/controllers/schools/rejected_requests_controller_spec.rb
+++ b/spec/controllers/schools/rejected_requests_controller_spec.rb
@@ -26,6 +26,7 @@
describe '#show' do
let(:rejected) { create :placement_request, :cancelled_by_school, school: school }
+
before { get schools_rejected_request_path(rejected) }
it { expect(response).to have_http_status(:success) }
diff --git a/spec/controllers/schools/sessions_controller_spec.rb b/spec/controllers/schools/sessions_controller_spec.rb
index 7ffb81728f..cb4d19e3b5 100644
--- a/spec/controllers/schools/sessions_controller_spec.rb
+++ b/spec/controllers/schools/sessions_controller_spec.rb
@@ -68,15 +68,15 @@
let(:callback) { "/auth/callback?code=#{code}&state=#{state}&session_state=#{session_state}" }
end
- context '#create' do
+ describe '#create' do
let(:return_url) { '/schools/dashboard' }
let(:state) { 'd18ce84b-423e-4696-bee4-b74caa47163e' }
context 'when the user is not yet signed in' do
- include_context 'oidc callback'
-
subject! { get callback }
+ include_context 'oidc callback'
+
specify 'should redirect to the return url' do
expect(response.body).to redirect_to(return_url)
end
@@ -101,7 +101,7 @@
after { get callback }
specify 'should raise an AuthFailed error' do
- expect(response.status).to eql 302
+ expect(response.status).to be 302
expect(response.redirect_url).to end_with('schools/errors/auth_failed')
end
@@ -118,6 +118,7 @@
}.each do |bad_state, description|
context description do
let(:callback) { "/auth/callback?code=#{code}&state=#{bad_state}&session_state=#{session_state}" }
+
after { get callback }
specify 'should raise StateMismatchError' do
@@ -125,7 +126,7 @@
end
specify 'should redirect to an error page' do
- expect(response.status).to eql 302
+ expect(response.status).to be 302
expect(response.redirect_url).to end_with('schools/errors/auth_failed')
end
end
@@ -134,6 +135,7 @@
context 'AuthFailedError' do
let(:code) { nil }
+
after { get callback }
specify 'should raise AuthFailedError' do
@@ -141,7 +143,7 @@
end
specify 'should redirect to an error page' do
- expect(response.status).to eql 302
+ expect(response.status).to be 302
expect(response.redirect_url).to end_with('schools/errors/auth_failed')
end
end
@@ -149,15 +151,14 @@
end
describe 'role checking' do
+ subject! { get callback }
+
include_context 'oidc callback'
before do
- allow(Schools::DFESignInAPI::Client).to receive(:enabled?).and_return(true)
- allow(Schools::DFESignInAPI::Client).to receive(:role_check_enabled?).and_return(true)
+ allow(Schools::DFESignInAPI::Client).to receive_messages(enabled?: true, role_check_enabled?: true)
allow_any_instance_of(Schools::DFESignInAPI::Roles).to receive(:has_school_experience_role?).and_return(false)
end
- subject! { get callback }
-
specify 'should redirect to the insufficient privileges error page' do
expect(subject).to redirect_to(schools_errors_insufficient_privileges_path)
end
@@ -168,6 +169,8 @@
end
context 'when the user is already logged in' do
+ subject { get auth_callback_path }
+
include_context 'oidc callback'
before do
@@ -176,14 +179,14 @@
session_hash[:current_user] = OpenIDConnect::ResponseObject::UserInfo.new(sub: "abc1243", name: 'Milhouse')
end
- subject { get auth_callback_path }
-
specify 'should redirect to the dashboard' do
expect(subject).to redirect_to(schools_dashboard_path)
end
end
context 'when the session has timed out' do
+ subject { get expired_auth_callback_path }
+
let(:message) { 'sessionexpired' }
let(:expired_auth_callback_path) { "/auth/callback?error=#{message}" }
@@ -191,8 +194,6 @@
allow(Rails.logger).to receive(:warn).and_return(true)
end
- subject { get expired_auth_callback_path }
-
specify 'should log that the session has expired' do
subject
expect(Rails.logger).to have_received(:warn).with('DfE Sign-in session expiry error, restarting login process')
@@ -208,18 +209,18 @@
include_context "logged in DfE user"
context 'when a session exists and there is an id_token' do
+ subject { get(logout_schools_session_path) }
+
let(:oidc_host) { 'some-oidc-host' }
let(:id_token) { 'abcdefg123456' }
- before { get(root_path) }
- subject { get(logout_schools_session_path) }
-
before do
+ get(root_path)
allow(OpenIDConnect::Client).to receive(:new)
- .and_return(OpenStruct.new(host: oidc_host))
- end
+ .and_return(OpenStruct.new(host: oidc_host))
- before { session[:id_token] = id_token }
+ session[:id_token] = id_token
+ end
specify 'should redirect to the OpenID Connect end session endpoint with the correct query params' do
expect(subject).to redirect_to(
diff --git a/spec/controllers/schools/switch_controller_spec.rb b/spec/controllers/schools/switch_controller_spec.rb
index 0cb8440e71..d04a6cd43f 100644
--- a/spec/controllers/schools/switch_controller_spec.rb
+++ b/spec/controllers/schools/switch_controller_spec.rb
@@ -3,24 +3,23 @@
describe Schools::SessionsController, type: :request do
include_context "logged in DfE user"
- context '#new' do
+ describe '#new' do
context 'when in-app school changing is enabled' do
+ subject { get new_schools_switch_path }
+
before do
allow(Schools::ChangeSchool).to receive(:allow_school_change_in_app?).and_return(true)
end
- subject { get new_schools_switch_path }
-
it { expect(subject).to redirect_to(schools_change_path) }
end
context 'when in-app school changing is disabled' do
before do
allow(Schools::ChangeSchool).to receive(:allow_school_change_in_app?).and_return(false)
+ get new_schools_switch_path
end
- before { get new_schools_switch_path }
-
specify 'should clear the user from the session' do
expect(session[:current_user]).to be_nil
expect(session[:school_name]).to be_nil
diff --git a/spec/controllers/schools/withdrawn_requests_controller_spec.rb b/spec/controllers/schools/withdrawn_requests_controller_spec.rb
index cb0ba906b5..59dde97d7c 100644
--- a/spec/controllers/schools/withdrawn_requests_controller_spec.rb
+++ b/spec/controllers/schools/withdrawn_requests_controller_spec.rb
@@ -23,6 +23,7 @@
describe '#show' do
let(:withdrawn) { create :placement_request, :cancelled, school: school }
+
before { get schools_withdrawn_request_path(withdrawn) }
it { expect(response).to have_http_status(:success) }
diff --git a/spec/controllers/schools_controller_spec.rb b/spec/controllers/schools_controller_spec.rb
index 3d868d1def..3be9ac80f0 100644
--- a/spec/controllers/schools_controller_spec.rb
+++ b/spec/controllers/schools_controller_spec.rb
@@ -3,21 +3,21 @@
describe SchoolsController, type: :request do
describe '#show' do
- before do
- allow(ENV).to receive(:[]).and_call_original
- allow(ENV).to receive(:[]).with('DFE_SIGNIN_DEACTIVATED') { toggle }
- end
-
subject do
get '/schools'
response
end
+ before do
+ allow(ENV).to receive(:[]).and_call_original
+ allow(ENV).to receive(:[]).with('DFE_SIGNIN_DEACTIVATED') { toggle }
+ end
+
context 'when sign in is enabled' do
let(:toggle) { 'false' }
specify 'should render the correct template' do
- is_expected.to have_rendered :show
+ expect(subject).to have_rendered :show
end
specify 'should show login button' do
@@ -33,7 +33,7 @@
let(:toggle) { '1' }
specify 'should render the correct template' do
- is_expected.to have_rendered :show
+ expect(subject).to have_rendered :show
end
specify 'should not show login button' do
@@ -53,7 +53,7 @@
let(:toggle) { 'custom message' }
specify 'should render the correct template' do
- is_expected.to have_rendered :show
+ expect(subject).to have_rendered :show
end
specify 'should not show login button' do
diff --git a/spec/factories/api_factory.rb b/spec/factories/api_factory.rb
index 9b3c30edbc..dea081cf89 100644
--- a/spec/factories/api_factory.rb
+++ b/spec/factories/api_factory.rb
@@ -1,5 +1,5 @@
FactoryBot.define do
- factory :api_schools_experience_sign_up, class: GetIntoTeachingApiClient::SchoolsExperienceSignUp do
+ factory :api_schools_experience_sign_up, class: 'GetIntoTeachingApiClient::SchoolsExperienceSignUp' do
candidate_id { SecureRandom.uuid }
master_id { nil }
merged { false }
@@ -28,12 +28,12 @@
end
end
- factory :api_privacy_policy, class: GetIntoTeachingApiClient::PrivacyPolicy do
+ factory :api_privacy_policy, class: 'GetIntoTeachingApiClient::PrivacyPolicy' do
id { SecureRandom.uuid }
text { "policy text" }
end
- factory :api_teaching_subject, class: GetIntoTeachingApiClient::TeachingSubject do
+ factory :api_teaching_subject, class: 'GetIntoTeachingApiClient::TeachingSubject' do
id { SecureRandom.uuid }
sequence(:value) { |i| "Gitis Subject #{i}" }
end
diff --git a/spec/factories/bookings/placement_request_factory.rb b/spec/factories/bookings/placement_request_factory.rb
index 1765dd8b71..11669608f0 100644
--- a/spec/factories/bookings/placement_request_factory.rb
+++ b/spec/factories/bookings/placement_request_factory.rb
@@ -1,5 +1,5 @@
FactoryBot.define do
- factory :placement_request, class: Bookings::PlacementRequest do
+ factory :placement_request, class: 'Bookings::PlacementRequest' do
association \
:school,
:with_profile,
diff --git a/spec/factories/bookings/school_factory.rb b/spec/factories/bookings/school_factory.rb
index b9dbd9adea..d9efbcee07 100644
--- a/spec/factories/bookings/school_factory.rb
+++ b/spec/factories/bookings/school_factory.rb
@@ -1,5 +1,5 @@
FactoryBot.define do
- factory :bookings_school, class: Bookings::School do
+ factory :bookings_school, class: 'Bookings::School' do
sequence(:name) { |n| "school #{n}" }
coordinates { Bookings::School::GEOFACTORY.point(-2.241, 53.481) }
fee { 0 }
diff --git a/spec/factories/candidates/feedback.rb b/spec/factories/candidates/feedback.rb
index c6bfeb62a5..33630e02d4 100644
--- a/spec/factories/candidates/feedback.rb
+++ b/spec/factories/candidates/feedback.rb
@@ -1,5 +1,5 @@
FactoryBot.define do
- factory :candidates_feedback, class: Candidates::Feedback do
+ factory :candidates_feedback, class: 'Candidates::Feedback' do
reason_for_using_service { 'something_else' }
reason_for_using_service_explanation { 'testing the software' }
rating { 'very_satisfied' }
diff --git a/spec/factories/candidates/registrations/availability_preference_factory.rb b/spec/factories/candidates/registrations/availability_preference_factory.rb
index e10a4078c6..1a09447743 100644
--- a/spec/factories/candidates/registrations/availability_preference_factory.rb
+++ b/spec/factories/candidates/registrations/availability_preference_factory.rb
@@ -1,5 +1,5 @@
FactoryBot.define do
- factory :availability_preference, class: Candidates::Registrations::AvailabilityPreference do
+ factory :availability_preference, class: 'Candidates::Registrations::AvailabilityPreference' do
urn { 11_048 }
availability { 'Every second Friday' }
end
diff --git a/spec/factories/candidates/registrations/background_check_factory.rb b/spec/factories/candidates/registrations/background_check_factory.rb
index acbf27b510..14d611ac41 100644
--- a/spec/factories/candidates/registrations/background_check_factory.rb
+++ b/spec/factories/candidates/registrations/background_check_factory.rb
@@ -1,5 +1,5 @@
FactoryBot.define do
- factory :background_check, class: Candidates::Registrations::BackgroundCheck do
+ factory :background_check, class: 'Candidates::Registrations::BackgroundCheck' do
urn { 11_048 }
has_dbs_check { true }
end
diff --git a/spec/factories/candidates/registrations/contact_information_factory.rb b/spec/factories/candidates/registrations/contact_information_factory.rb
index ced8ff80bc..457412fcc7 100644
--- a/spec/factories/candidates/registrations/contact_information_factory.rb
+++ b/spec/factories/candidates/registrations/contact_information_factory.rb
@@ -1,5 +1,5 @@
FactoryBot.define do
- factory :contact_information, class: Candidates::Registrations::ContactInformation do
+ factory :contact_information, class: 'Candidates::Registrations::ContactInformation' do
urn { 11_048 }
building { 'New house' }
street { 'Test street' }
diff --git a/spec/factories/candidates/registrations/education_factory.rb b/spec/factories/candidates/registrations/education_factory.rb
index 7af50218de..88b9b7efdb 100644
--- a/spec/factories/candidates/registrations/education_factory.rb
+++ b/spec/factories/candidates/registrations/education_factory.rb
@@ -1,5 +1,5 @@
FactoryBot.define do
- factory :education, class: Candidates::Registrations::Education do
+ factory :education, class: 'Candidates::Registrations::Education' do
urn { 11_048 }
degree_stage { "Other" }
degree_stage_explaination { "Khan academy, level 3" }
diff --git a/spec/factories/candidates/registrations/gitis_registration_session_factory.rb b/spec/factories/candidates/registrations/gitis_registration_session_factory.rb
index 7f2449803c..6f63687cf3 100644
--- a/spec/factories/candidates/registrations/gitis_registration_session_factory.rb
+++ b/spec/factories/candidates/registrations/gitis_registration_session_factory.rb
@@ -1,6 +1,6 @@
FactoryBot.define do
factory :gitis_registration_session, parent: :registration_session,
- class: Candidates::Registrations::GitisRegistrationSession do
+ class: 'Candidates::Registrations::GitisRegistrationSession' do
gitis_contact { build(:api_schools_experience_sign_up_with_name) }
initialize_with do
diff --git a/spec/factories/candidates/registrations/legacy_registration_session.rb b/spec/factories/candidates/registrations/legacy_registration_session.rb
index 5f1e124102..c8e8e92653 100644
--- a/spec/factories/candidates/registrations/legacy_registration_session.rb
+++ b/spec/factories/candidates/registrations/legacy_registration_session.rb
@@ -1,6 +1,6 @@
# TODO: SE-1877 remove this file
FactoryBot.define do
- factory :legacy_registration_session, class: Candidates::Registrations::RegistrationSession do
+ factory :legacy_registration_session, class: 'Candidates::Registrations::RegistrationSession' do
transient do
urn { 11_048 }
bookings_placement_date_id { 16 }
diff --git a/spec/factories/candidates/registrations/personal_information_factory.rb b/spec/factories/candidates/registrations/personal_information_factory.rb
index fb85a502f7..27aecd6dd6 100644
--- a/spec/factories/candidates/registrations/personal_information_factory.rb
+++ b/spec/factories/candidates/registrations/personal_information_factory.rb
@@ -1,5 +1,5 @@
FactoryBot.define do
- factory :personal_information, class: Candidates::Registrations::PersonalInformation do
+ factory :personal_information, class: 'Candidates::Registrations::PersonalInformation' do
urn { 11_048 }
first_name { 'Testy' }
last_name { 'Mc Test' }
diff --git a/spec/factories/candidates/registrations/placement_preference_factory.rb b/spec/factories/candidates/registrations/placement_preference_factory.rb
index 6e9b1da576..e40c3312e1 100644
--- a/spec/factories/candidates/registrations/placement_preference_factory.rb
+++ b/spec/factories/candidates/registrations/placement_preference_factory.rb
@@ -1,5 +1,5 @@
FactoryBot.define do
- factory :placement_preference, class: Candidates::Registrations::PlacementPreference do
+ factory :placement_preference, class: 'Candidates::Registrations::PlacementPreference' do
urn { 11_048 }
objectives { 'Become a teacher' }
end
diff --git a/spec/factories/candidates/registrations/registration_session_factory.rb b/spec/factories/candidates/registrations/registration_session_factory.rb
index 06dfdf228c..7b91a390a0 100644
--- a/spec/factories/candidates/registrations/registration_session_factory.rb
+++ b/spec/factories/candidates/registrations/registration_session_factory.rb
@@ -1,5 +1,5 @@
FactoryBot.define do
- factory :registration_session, class: Candidates::Registrations::RegistrationSession do
+ factory :registration_session, class: 'Candidates::Registrations::RegistrationSession' do
transient do
current_time { DateTime.current }
urn { 11_048 }
diff --git a/spec/factories/candidates/registrations/subject_and_date_information_factory.rb b/spec/factories/candidates/registrations/subject_and_date_information_factory.rb
index 1fb4fd2675..57e906cad3 100644
--- a/spec/factories/candidates/registrations/subject_and_date_information_factory.rb
+++ b/spec/factories/candidates/registrations/subject_and_date_information_factory.rb
@@ -1,5 +1,5 @@
FactoryBot.define do
- factory :subject_and_date_information, class: Candidates::Registrations::SubjectAndDateInformation do
+ factory :subject_and_date_information, class: 'Candidates::Registrations::SubjectAndDateInformation' do
bookings_placement_date_id { create(:bookings_placement_date).id }
bookings_subject_id { nil }
end
diff --git a/spec/factories/candidates/registrations/teaching_preference_factory.rb b/spec/factories/candidates/registrations/teaching_preference_factory.rb
index 46280b4056..236d9200ff 100644
--- a/spec/factories/candidates/registrations/teaching_preference_factory.rb
+++ b/spec/factories/candidates/registrations/teaching_preference_factory.rb
@@ -1,5 +1,5 @@
FactoryBot.define do
- factory :teaching_preference, class: Candidates::Registrations::TeachingPreference do
+ factory :teaching_preference, class: 'Candidates::Registrations::TeachingPreference' do
transient do
school { FactoryBot.create :bookings_school }
end
diff --git a/spec/factories/schools/feedback.rb b/spec/factories/schools/feedback.rb
index e202e1c154..bc8765811d 100644
--- a/spec/factories/schools/feedback.rb
+++ b/spec/factories/schools/feedback.rb
@@ -1,5 +1,5 @@
FactoryBot.define do
- factory :schools_feedback, class: Schools::Feedback do
+ factory :schools_feedback, class: 'Schools::Feedback' do
reason_for_using_service { 'something_else' }
reason_for_using_service_explanation { 'testing the software' }
rating { 'very_satisfied' }
diff --git a/spec/factories/schools/on_boarding/access_needs_detail_factory.rb b/spec/factories/schools/on_boarding/access_needs_detail_factory.rb
index d84ef3c15d..d47495b503 100644
--- a/spec/factories/schools/on_boarding/access_needs_detail_factory.rb
+++ b/spec/factories/schools/on_boarding/access_needs_detail_factory.rb
@@ -1,5 +1,5 @@
FactoryBot.define do
- factory :access_needs_detail, class: Schools::OnBoarding::AccessNeedsDetail do
+ factory :access_needs_detail, class: 'Schools::OnBoarding::AccessNeedsDetail' do
description { 'Here are some details' }
end
end
diff --git a/spec/factories/schools/on_boarding/access_needs_policy_factory.rb b/spec/factories/schools/on_boarding/access_needs_policy_factory.rb
index 735cb47a3c..3e7d5f7ea2 100644
--- a/spec/factories/schools/on_boarding/access_needs_policy_factory.rb
+++ b/spec/factories/schools/on_boarding/access_needs_policy_factory.rb
@@ -1,5 +1,5 @@
FactoryBot.define do
- factory :access_needs_policy, class: Schools::OnBoarding::AccessNeedsPolicy do
+ factory :access_needs_policy, class: 'Schools::OnBoarding::AccessNeedsPolicy' do
has_access_needs_policy { true }
url { 'https://example.com/access-needs-policy' }
end
diff --git a/spec/factories/schools/on_boarding/access_needs_support_factory.rb b/spec/factories/schools/on_boarding/access_needs_support_factory.rb
index a9969e66b1..59d2610545 100644
--- a/spec/factories/schools/on_boarding/access_needs_support_factory.rb
+++ b/spec/factories/schools/on_boarding/access_needs_support_factory.rb
@@ -1,5 +1,5 @@
FactoryBot.define do
- factory :access_needs_support, class: Schools::OnBoarding::AccessNeedsSupport do
+ factory :access_needs_support, class: 'Schools::OnBoarding::AccessNeedsSupport' do
supports_access_needs { true }
end
end
diff --git a/spec/factories/schools/on_boarding/admin_contact_factory.rb b/spec/factories/schools/on_boarding/admin_contact_factory.rb
index 1de6c74d9d..7bf6b0bd42 100644
--- a/spec/factories/schools/on_boarding/admin_contact_factory.rb
+++ b/spec/factories/schools/on_boarding/admin_contact_factory.rb
@@ -1,5 +1,5 @@
FactoryBot.define do
- factory :admin_contact, class: Schools::OnBoarding::AdminContact do
+ factory :admin_contact, class: 'Schools::OnBoarding::AdminContact' do
email { 'g.chalmers@springfield.edu' }
email_secondary { 's.skinner@springfield.edu' }
phone { '+441234567890' }
diff --git a/spec/factories/schools/on_boarding/administration_fee_factory.rb b/spec/factories/schools/on_boarding/administration_fee_factory.rb
index 4e854425bf..c8a71fa426 100644
--- a/spec/factories/schools/on_boarding/administration_fee_factory.rb
+++ b/spec/factories/schools/on_boarding/administration_fee_factory.rb
@@ -1,5 +1,5 @@
FactoryBot.define do
- factory :administration_fee, class: Schools::OnBoarding::AdministrationFee do
+ factory :administration_fee, class: 'Schools::OnBoarding::AdministrationFee' do
amount_pounds { 100.99 }
description { 'Generic administration fee' }
interval { 'Daily' }
diff --git a/spec/factories/schools/on_boarding/candidate_requirement_factory.rb b/spec/factories/schools/on_boarding/candidate_requirement_factory.rb
index 4b14590fb4..1eef0f1718 100644
--- a/spec/factories/schools/on_boarding/candidate_requirement_factory.rb
+++ b/spec/factories/schools/on_boarding/candidate_requirement_factory.rb
@@ -1,5 +1,5 @@
FactoryBot.define do
- factory :candidate_requirement, class: Schools::OnBoarding::CandidateRequirement do
+ factory :candidate_requirement, class: 'Schools::OnBoarding::CandidateRequirement' do
requirements { true }
requirements_details { 'Gotta go fast' }
end
diff --git a/spec/factories/schools/on_boarding/candidate_requirements_selection_factory.rb b/spec/factories/schools/on_boarding/candidate_requirements_selection_factory.rb
index 854208a03c..977e3dd156 100644
--- a/spec/factories/schools/on_boarding/candidate_requirements_selection_factory.rb
+++ b/spec/factories/schools/on_boarding/candidate_requirements_selection_factory.rb
@@ -1,5 +1,5 @@
FactoryBot.define do
- factory :candidate_requirements_selection, class: Schools::OnBoarding::CandidateRequirementsSelection do
+ factory :candidate_requirements_selection, class: 'Schools::OnBoarding::CandidateRequirementsSelection' do
selected_requirements { %w[on_teacher_training_course has_or_working_towards_degree live_locally provide_photo_identification other] }
maximum_distance_from_school { 8 }
photo_identification_details { 'Make sure photo is clear' }
diff --git a/spec/factories/schools/on_boarding/confirmation_factory.rb b/spec/factories/schools/on_boarding/confirmation_factory.rb
index fbc79dd9a3..8f2b63fec4 100644
--- a/spec/factories/schools/on_boarding/confirmation_factory.rb
+++ b/spec/factories/schools/on_boarding/confirmation_factory.rb
@@ -1,5 +1,5 @@
FactoryBot.define do
- factory :confirmation, class: Schools::OnBoarding::Confirmation do
+ factory :confirmation, class: 'Schools::OnBoarding::Confirmation' do
acceptance { true }
end
end
diff --git a/spec/factories/schools/on_boarding/dbs_fee_factory.rb b/spec/factories/schools/on_boarding/dbs_fee_factory.rb
index b51be566f9..f24d7b7961 100644
--- a/spec/factories/schools/on_boarding/dbs_fee_factory.rb
+++ b/spec/factories/schools/on_boarding/dbs_fee_factory.rb
@@ -1,5 +1,5 @@
FactoryBot.define do
- factory :dbs_fee, class: Schools::OnBoarding::DBSFee do
+ factory :dbs_fee, class: 'Schools::OnBoarding::DBSFee' do
amount_pounds { 200 }
description { 'DBS check' }
interval { 'One-off' }
diff --git a/spec/factories/schools/on_boarding/dbs_requirement_factory.rb b/spec/factories/schools/on_boarding/dbs_requirement_factory.rb
index 4409dd2e0d..bedba78146 100644
--- a/spec/factories/schools/on_boarding/dbs_requirement_factory.rb
+++ b/spec/factories/schools/on_boarding/dbs_requirement_factory.rb
@@ -1,5 +1,5 @@
FactoryBot.define do
- factory :dbs_requirement, class: Schools::OnBoarding::DbsRequirement do
+ factory :dbs_requirement, class: 'Schools::OnBoarding::DbsRequirement' do
dbs_policy_conditions { 'required' }
dbs_policy_details { 'Must have recent dbs check' }
no_dbs_policy_details { nil }
diff --git a/spec/factories/schools/on_boarding/description_factory.rb b/spec/factories/schools/on_boarding/description_factory.rb
index eab4ef5f4e..f25d49d146 100644
--- a/spec/factories/schools/on_boarding/description_factory.rb
+++ b/spec/factories/schools/on_boarding/description_factory.rb
@@ -1,5 +1,5 @@
FactoryBot.define do
- factory :description, class: Schools::OnBoarding::Description do
+ factory :description, class: 'Schools::OnBoarding::Description' do
details { 'Horse archery' }
end
end
diff --git a/spec/factories/schools/on_boarding/disability_confident_factory.rb b/spec/factories/schools/on_boarding/disability_confident_factory.rb
index c5286826b0..3c4fec93a3 100644
--- a/spec/factories/schools/on_boarding/disability_confident_factory.rb
+++ b/spec/factories/schools/on_boarding/disability_confident_factory.rb
@@ -1,5 +1,5 @@
FactoryBot.define do
- factory :disability_confident, class: Schools::OnBoarding::DisabilityConfident do
+ factory :disability_confident, class: 'Schools::OnBoarding::DisabilityConfident' do
is_disability_confident { true }
end
end
diff --git a/spec/factories/schools/on_boarding/experience_outline_factory.rb b/spec/factories/schools/on_boarding/experience_outline_factory.rb
index c1de941296..f4cf112aba 100644
--- a/spec/factories/schools/on_boarding/experience_outline_factory.rb
+++ b/spec/factories/schools/on_boarding/experience_outline_factory.rb
@@ -1,5 +1,5 @@
FactoryBot.define do
- factory :experience_outline, class: Schools::OnBoarding::ExperienceOutline do
+ factory :experience_outline, class: 'Schools::OnBoarding::ExperienceOutline' do
candidate_experience { 'Mostly teaching' }
end
end
diff --git a/spec/factories/schools/on_boarding/fees_factory.rb b/spec/factories/schools/on_boarding/fees_factory.rb
index 878ac2b36d..236c9ae9b4 100644
--- a/spec/factories/schools/on_boarding/fees_factory.rb
+++ b/spec/factories/schools/on_boarding/fees_factory.rb
@@ -1,5 +1,5 @@
FactoryBot.define do
- factory :fees, class: Schools::OnBoarding::Fees do
+ factory :fees, class: 'Schools::OnBoarding::Fees' do
selected_fees { %w[administration_fees dbs_fees other_fees] }
dbs_fees_specified { true }
end
diff --git a/spec/factories/schools/on_boarding/key_stage_list_factory.rb b/spec/factories/schools/on_boarding/key_stage_list_factory.rb
index 9b8fae3d3c..52e4b5fa3b 100644
--- a/spec/factories/schools/on_boarding/key_stage_list_factory.rb
+++ b/spec/factories/schools/on_boarding/key_stage_list_factory.rb
@@ -1,5 +1,5 @@
FactoryBot.define do
- factory :key_stage_list, class: Schools::OnBoarding::KeyStageList do
+ factory :key_stage_list, class: 'Schools::OnBoarding::KeyStageList' do
early_years { true }
key_stage_1 { true }
key_stage_2 { true }
diff --git a/spec/factories/schools/on_boarding/other_fee_factory.rb b/spec/factories/schools/on_boarding/other_fee_factory.rb
index eda3c23fa8..964cefe9b1 100644
--- a/spec/factories/schools/on_boarding/other_fee_factory.rb
+++ b/spec/factories/schools/on_boarding/other_fee_factory.rb
@@ -1,5 +1,5 @@
FactoryBot.define do
- factory :other_fee, class: Schools::OnBoarding::OtherFee do
+ factory :other_fee, class: 'Schools::OnBoarding::OtherFee' do
amount_pounds { 300 }
description { 'Falconry lessons' }
interval { 'One-off' }
diff --git a/spec/factories/schools/on_boarding/phases_list_factory.rb b/spec/factories/schools/on_boarding/phases_list_factory.rb
index fac17a388c..b9c2008841 100644
--- a/spec/factories/schools/on_boarding/phases_list_factory.rb
+++ b/spec/factories/schools/on_boarding/phases_list_factory.rb
@@ -1,5 +1,5 @@
FactoryBot.define do
- factory :phases_list, class: Schools::OnBoarding::PhasesList do
+ factory :phases_list, class: 'Schools::OnBoarding::PhasesList' do
primary { true }
secondary { true }
college { true }
diff --git a/spec/factories/schools/on_boarding/teacher_training_factory.rb b/spec/factories/schools/on_boarding/teacher_training_factory.rb
index 64b02af1b7..6273c0706c 100644
--- a/spec/factories/schools/on_boarding/teacher_training_factory.rb
+++ b/spec/factories/schools/on_boarding/teacher_training_factory.rb
@@ -1,5 +1,5 @@
FactoryBot.define do
- factory :teacher_training, class: Schools::OnBoarding::TeacherTraining do
+ factory :teacher_training, class: 'Schools::OnBoarding::TeacherTraining' do
provides_teacher_training { true }
teacher_training_details { 'We offer teach training in house' }
teacher_training_url { 'https://example.com' }
diff --git a/spec/features/candidates/api_registrations_spec.rb b/spec/features/candidates/api_registrations_spec.rb
index 4b86e253ad..7bc42be516 100644
--- a/spec/features/candidates/api_registrations_spec.rb
+++ b/spec/features/candidates/api_registrations_spec.rb
@@ -108,8 +108,8 @@ def complete_sign_in_step
end
def complete_contact_information_step
- expect(page.current_path).to eq \
- "/candidates/schools/#{school_urn}/registrations/contact_information/new"
+ expect(page).to have_current_path \
+ "/candidates/schools/#{school_urn}/registrations/contact_information/new", ignore_query: true
# Submit contact information form with errors
fill_in 'Address line 1', with: ''
@@ -127,8 +127,8 @@ def complete_contact_information_step
end
def complete_education_step
- expect(page.current_path).to eq \
- "/candidates/schools/#{school_urn}/registrations/education/new"
+ expect(page).to have_current_path \
+ "/candidates/schools/#{school_urn}/registrations/education/new", ignore_query: true
# Submit registrations/education form with errors
choose 'Graduate or postgraduate'
@@ -142,8 +142,8 @@ def complete_education_step
end
def complete_teaching_preference_step
- expect(page.current_path).to eq \
- "/candidates/schools/#{school_urn}/registrations/teaching_preference/new"
+ expect(page).to have_current_path \
+ "/candidates/schools/#{school_urn}/registrations/teaching_preference/new", ignore_query: true
# Submit registrations/teaching_preference form with errors
choose "I’m very sure and think I’ll apply"
@@ -157,8 +157,8 @@ def complete_teaching_preference_step
end
def complete_placement_preference_step
- expect(page.current_path).to eq \
- "/candidates/schools/#{school_urn}/registrations/placement_preference/new"
+ expect(page).to have_current_path \
+ "/candidates/schools/#{school_urn}/registrations/placement_preference/new", ignore_query: true
# Submit registrations/placement_preference form with errors
fill_in 'Enter what you want to get out of your placement', with: ''
@@ -171,8 +171,8 @@ def complete_placement_preference_step
end
def complete_availability_preference_step
- expect(page.current_path).to eq \
- "/candidates/schools/#{school_urn}/registrations/availability_preference/new"
+ expect(page).to have_current_path \
+ "/candidates/schools/#{school_urn}/registrations/availability_preference/new", ignore_query: true
# Submit registrations/availability_preference form with errors
fill_in 'Enter your availability', with: ''
@@ -185,8 +185,8 @@ def complete_availability_preference_step
end
def complete_background_step
- expect(page.current_path).to eq \
- "/candidates/schools/#{school_urn}/registrations/background_check/new"
+ expect(page).to have_current_path \
+ "/candidates/schools/#{school_urn}/registrations/background_check/new", ignore_query: true
# Submit registrations/background_check form with errors
click_button 'Continue'
@@ -198,8 +198,8 @@ def complete_background_step
end
def complete_application_preview_step(name: 'testy mctest', email: nil, button_text: 'Accept and send')
- expect(page.current_path).to eq \
- "/candidates/schools/#{school_urn}/registrations/application_preview"
+ expect(page).to have_current_path \
+ "/candidates/schools/#{school_urn}/registrations/application_preview", ignore_query: true
# Expect preview to match the data we successfully submited
expect(page).to have_text "Full name #{name}"
@@ -248,7 +248,7 @@ def swap_back_to_education_step
def get_bounced_to_contact_information_step
visit "/candidates/schools/#{school_urn}/registrations/application_preview"
- expect(page.current_path).to eq \
- "/candidates/schools/#{school_urn}/registrations/contact_information/new"
+ expect(page).to have_current_path \
+ "/candidates/schools/#{school_urn}/registrations/contact_information/new", ignore_query: true
end
end
diff --git a/spec/features/cookie_preferences_spec.rb b/spec/features/cookie_preferences_spec.rb
index 81350696cb..d57cdc3d2c 100644
--- a/spec/features/cookie_preferences_spec.rb
+++ b/spec/features/cookie_preferences_spec.rb
@@ -7,7 +7,7 @@
click_on "Submit feedback"
click_on "Accept analytics cookies"
- expect(page.current_path).to eq(root_path)
+ expect(page).to have_current_path(root_path, ignore_query: true)
end
scenario "a user accepts the cookies from valid path" do
@@ -15,7 +15,7 @@
click_on "Accept analytics cookies"
- expect(page.current_path).to eq(root_path)
+ expect(page).to have_current_path(root_path, ignore_query: true)
end
scenario "a user accepts the cookies from a blacklisted path" do
@@ -23,6 +23,6 @@
click_on "Accept analytics cookies"
- expect(page.current_path).to eq(edit_cookie_preference_path)
+ expect(page).to have_current_path(edit_cookie_preference_path, ignore_query: true)
end
end
diff --git a/spec/forms/schools/csv_export_form_spec.rb b/spec/forms/schools/csv_export_form_spec.rb
index 0ed6f20d48..247e784ba5 100644
--- a/spec/forms/schools/csv_export_form_spec.rb
+++ b/spec/forms/schools/csv_export_form_spec.rb
@@ -29,11 +29,11 @@
context "when not valid" do
subject { described_class.new }
- it "should not be valid" do
+ it "is not valid" do
expect(subject).not_to be_valid
end
- it "should have errors" do
+ it "has errors" do
subject.valid?
expect(subject.errors.messages[:from_date]).to include "You must specify the From date"
expect(subject.errors.messages[:to_date]).to include "You must specify the To date"
diff --git a/spec/forms/schools/on_boarding/access_needs_policy_spec.rb b/spec/forms/schools/on_boarding/access_needs_policy_spec.rb
index 5572c1c953..d8d70ab91c 100644
--- a/spec/forms/schools/on_boarding/access_needs_policy_spec.rb
+++ b/spec/forms/schools/on_boarding/access_needs_policy_spec.rb
@@ -11,11 +11,13 @@
context 'when has policy' do
before { subject.has_access_needs_policy = true }
+
it { is_expected.to validate_presence_of :url }
end
context 'when doesnt have policy' do
before { subject.has_access_needs_policy = false }
+
it { is_expected.not_to validate_presence_of :url }
end
end
diff --git a/spec/forms/schools/on_boarding/candidate_experience_schedule_spec.rb b/spec/forms/schools/on_boarding/candidate_experience_schedule_spec.rb
index f36c950740..96f8c4ff38 100644
--- a/spec/forms/schools/on_boarding/candidate_experience_schedule_spec.rb
+++ b/spec/forms/schools/on_boarding/candidate_experience_schedule_spec.rb
@@ -22,8 +22,8 @@
context 'valid times' do
valid_times.each do |vt|
specify "should allow #{vt} to be assigned to both start_time, end_time" do
- is_expected.to allow_value(vt).for(:start_time)
- is_expected.to allow_value(vt).for(:end_time)
+ expect(subject).to allow_value(vt).for(:start_time)
+ expect(subject).to allow_value(vt).for(:end_time)
end
end
end
@@ -31,8 +31,8 @@
context 'invalid times' do
invalid_times.each do |ivt|
specify "should not allow #{ivt} to be assigned to both start_time, end_time" do
- is_expected.not_to allow_value(ivt).for(:start_time)
- is_expected.not_to allow_value(ivt).for(:end_time)
+ expect(subject).not_to allow_value(ivt).for(:start_time)
+ expect(subject).not_to allow_value(ivt).for(:end_time)
end
end
end
diff --git a/spec/forms/schools/on_boarding/candidate_parking_information_spec.rb b/spec/forms/schools/on_boarding/candidate_parking_information_spec.rb
index b086bf0306..7595a80fe7 100644
--- a/spec/forms/schools/on_boarding/candidate_parking_information_spec.rb
+++ b/spec/forms/schools/on_boarding/candidate_parking_information_spec.rb
@@ -12,12 +12,14 @@
context 'when parking_provided' do
subject { described_class.new parking_provided: true }
+
it { is_expected.to validate_presence_of :parking_details }
it { is_expected.not_to validate_presence_of :nearby_parking_details }
end
context 'when not parking_provided' do
subject { described_class.new parking_provided: false }
+
it { is_expected.not_to validate_presence_of :parking_details }
it { is_expected.to validate_presence_of :nearby_parking_details }
end
diff --git a/spec/forms/schools/on_boarding/candidate_requirement_spec.rb b/spec/forms/schools/on_boarding/candidate_requirement_spec.rb
index 72b6d79fca..07a7d53777 100644
--- a/spec/forms/schools/on_boarding/candidate_requirement_spec.rb
+++ b/spec/forms/schools/on_boarding/candidate_requirement_spec.rb
@@ -9,14 +9,14 @@
context 'validations' do
context 'requirements' do
it do
- is_expected.not_to allow_value(nil).for :requirements
+ expect(subject).not_to allow_value(nil).for :requirements
end
context 'when requirements is true' do
subject { described_class.new requirements: true }
it do
- is_expected.to validate_presence_of :requirements_details
+ expect(subject).to validate_presence_of :requirements_details
end
end
@@ -24,7 +24,7 @@
subject { described_class.new requirements: false }
it do
- is_expected.not_to validate_presence_of :requirements_details
+ expect(subject).not_to validate_presence_of :requirements_details
end
end
end
diff --git a/spec/forms/schools/on_boarding/candidate_requirements_selection_spec.rb b/spec/forms/schools/on_boarding/candidate_requirements_selection_spec.rb
index f0585f6f8c..4060b3fefd 100644
--- a/spec/forms/schools/on_boarding/candidate_requirements_selection_spec.rb
+++ b/spec/forms/schools/on_boarding/candidate_requirements_selection_spec.rb
@@ -28,7 +28,7 @@
end
it 'removes maximum_distance_from_school' do
- expect(subject.maximum_distance_from_school).to be nil
+ expect(subject.maximum_distance_from_school).to be_nil
end
end
@@ -51,7 +51,7 @@
end
it 'removes photo_identification_details' do
- expect(subject.photo_identification_details).to be nil
+ expect(subject.photo_identification_details).to be_nil
end
end
@@ -74,7 +74,7 @@
end
it 'removes other_details' do
- expect(subject.other_details).to be nil
+ expect(subject.other_details).to be_nil
end
end
end
@@ -97,6 +97,7 @@
context 'maximum_distance_from_school' do
context 'when the live_locally is selected' do
before { subject.selected_requirements = %w[live_locally] }
+
it { is_expected.to validate_presence_of :maximum_distance_from_school }
end
@@ -108,6 +109,7 @@
context 'photo_identification_details' do
context 'when provide_photo_identification is selected' do
before { subject.selected_requirements = %w[provide_photo_identification] }
+
it { is_expected.to validate_presence_of :photo_identification_details }
end
@@ -119,6 +121,7 @@
context 'other details' do
context 'when other is selected' do
before { subject.selected_requirements = %w[other] }
+
it { is_expected.to validate_presence_of :other_details }
end
diff --git a/spec/forms/schools/on_boarding/current_step_spec.rb b/spec/forms/schools/on_boarding/current_step_spec.rb
index 473a0413e4..ce8622bd4e 100644
--- a/spec/forms/schools/on_boarding/current_step_spec.rb
+++ b/spec/forms/schools/on_boarding/current_step_spec.rb
@@ -9,7 +9,7 @@
FactoryBot.create :bookings_phase, :college
end
- context '.for' do
+ describe '.for' do
let :returned_step do
described_class.for school_profile
end
diff --git a/spec/forms/schools/on_boarding/dbs_fee_spec.rb b/spec/forms/schools/on_boarding/dbs_fee_spec.rb
index 4422123cea..f72bfabc5e 100644
--- a/spec/forms/schools/on_boarding/dbs_fee_spec.rb
+++ b/spec/forms/schools/on_boarding/dbs_fee_spec.rb
@@ -3,7 +3,7 @@
describe Schools::OnBoarding::DBSFee, type: :model do
it_behaves_like 'a school fee'
- context '#interval' do
+ describe '#interval' do
it 'defaults to "One-off"' do
expect(described_class.new.interval).to eq 'One-off'
end
diff --git a/spec/forms/schools/on_boarding/dbs_requirement_spec.rb b/spec/forms/schools/on_boarding/dbs_requirement_spec.rb
index 8a19e6d4e6..236a16bd94 100644
--- a/spec/forms/schools/on_boarding/dbs_requirement_spec.rb
+++ b/spec/forms/schools/on_boarding/dbs_requirement_spec.rb
@@ -20,7 +20,7 @@
end
it 'removes no dbs_policy_details' do
- expect(subject.no_dbs_policy_details).to be nil
+ expect(subject.no_dbs_policy_details).to be_nil
end
end
@@ -32,7 +32,7 @@
end
it 'removes no dbs_policy_details' do
- expect(subject.no_dbs_policy_details).to be nil
+ expect(subject.no_dbs_policy_details).to be_nil
end
end
@@ -44,7 +44,7 @@
end
it 'removes dbs_policy_details' do
- expect(subject.dbs_policy_details).to be nil
+ expect(subject.dbs_policy_details).to be_nil
end
end
end
@@ -56,8 +56,10 @@
it { is_expected.to validate_presence_of :dbs_policy_details }
context 'word counts' do
- before { subject.dbs_policy_details = too_long_text }
- before { subject.validate }
+ before do
+ subject.dbs_policy_details = too_long_text
+ subject.validate
+ end
it "valdiates word count is no more than 50 words" do
expect(subject.errors[:dbs_policy_details]).to \
@@ -72,8 +74,10 @@
it { is_expected.to validate_presence_of :dbs_policy_details_inschool }
context 'word counts' do
- before { subject.dbs_policy_details_inschool = too_long_text }
- before { subject.validate }
+ before do
+ subject.dbs_policy_details_inschool = too_long_text
+ subject.validate
+ end
it "valdiates word count is no more than 50 words" do
expect(subject.errors[:dbs_policy_details_inschool]).to \
@@ -86,8 +90,10 @@
before { subject.dbs_policy_conditions = 'notrequired' }
context 'word counts' do
- before { subject.no_dbs_policy_details = too_long_text }
- before { subject.validate }
+ before do
+ subject.no_dbs_policy_details = too_long_text
+ subject.validate
+ end
it "valdiates word count is no more than 50 words" do
expect(subject.errors[:no_dbs_policy_details]).to \
diff --git a/spec/forms/schools/on_boarding/experience_outline_spec.rb b/spec/forms/schools/on_boarding/experience_outline_spec.rb
index b1199a6ad2..0a9703b748 100644
--- a/spec/forms/schools/on_boarding/experience_outline_spec.rb
+++ b/spec/forms/schools/on_boarding/experience_outline_spec.rb
@@ -5,15 +5,15 @@
it { is_expected.to respond_to :candidate_experience }
end
- context '.new_from_bookings_school' do
+ describe '.new_from_bookings_school' do
+ subject { described_class.new_from_bookings_school school }
+
let :school do
FactoryBot.build \
:bookings_school,
:with_placement_info
end
- subject { described_class.new_from_bookings_school school }
-
it "sets candidate_experience to the school's placement_info" do
expect(subject.candidate_experience).to eq school.placement_info
end
diff --git a/spec/forms/schools/on_boarding/fees_spec.rb b/spec/forms/schools/on_boarding/fees_spec.rb
index 940f3b3c93..2a7271c476 100644
--- a/spec/forms/schools/on_boarding/fees_spec.rb
+++ b/spec/forms/schools/on_boarding/fees_spec.rb
@@ -1,7 +1,7 @@
require 'rails_helper'
describe Schools::OnBoarding::Fees, type: :model do
- context '#attributes' do
+ describe '#attributes' do
it { is_expected.to respond_to :selected_fees }
it { is_expected.to respond_to :dbs_fees_specified }
end
diff --git a/spec/forms/schools/on_boarding/from_bookings_school_spec.rb b/spec/forms/schools/on_boarding/from_bookings_school_spec.rb
index a9cf952b8b..e4c3db4718 100644
--- a/spec/forms/schools/on_boarding/from_bookings_school_spec.rb
+++ b/spec/forms/schools/on_boarding/from_bookings_school_spec.rb
@@ -3,7 +3,7 @@
describe Schools::OnBoarding::FromBookingsSchool do
subject { described_class.new school }
- context '#[]' do
+ describe '#[]' do
context 'availability_description' do
let :school do
FactoryBot.build :bookings_school
@@ -73,7 +73,7 @@
it 'returns the correct attributes' do
expect(
subject['teacher_training'][:provides_teacher_training]
- ).to eq true
+ ).to be true
end
end
@@ -85,7 +85,7 @@
it 'returns the correct attributes' do
expect(
subject['experience_outline'][:provides_teacher_training]
- ).to eq nil
+ ).to be_nil
end
end
end
diff --git a/spec/forms/schools/on_boarding/key_stage_list_spec.rb b/spec/forms/schools/on_boarding/key_stage_list_spec.rb
index 02a97c33c2..5e0197f8a8 100644
--- a/spec/forms/schools/on_boarding/key_stage_list_spec.rb
+++ b/spec/forms/schools/on_boarding/key_stage_list_spec.rb
@@ -1,26 +1,26 @@
require 'rails_helper'
describe Schools::OnBoarding::KeyStageList, type: :model do
- context '#attributes' do
+ describe '#attributes' do
it { is_expected.to respond_to :early_years }
it { is_expected.to respond_to :key_stage_1 }
it { is_expected.to respond_to :key_stage_2 }
end
- context '#validations' do
+ describe '#validations' do
it 'validates at_least_one_key_stage_offered' do
expect(described_class.new.tap(&:validate).errors[:base]).to \
eq ['Select at least one key stage']
end
end
- context '.new_from_bookings_school' do
+ describe '.new_from_bookings_school' do
+ subject { described_class.new_from_bookings_school school }
+
let :school do
FactoryBot.build :bookings_school, :with_primary_key_stage_info
end
- subject { described_class.new_from_bookings_school school }
-
it 'sets the attributes from the bookings_school' do
expect(subject.early_years).to be true
expect(subject.key_stage_1).to be true
diff --git a/spec/forms/schools/on_boarding/phases_list_spec.rb b/spec/forms/schools/on_boarding/phases_list_spec.rb
index 8eff7c516f..404e57a4e9 100644
--- a/spec/forms/schools/on_boarding/phases_list_spec.rb
+++ b/spec/forms/schools/on_boarding/phases_list_spec.rb
@@ -1,21 +1,21 @@
require 'rails_helper'
describe Schools::OnBoarding::PhasesList, type: :model do
- context '#attributes' do
+ describe '#attributes' do
it { is_expected.to respond_to :primary }
it { is_expected.to respond_to :secondary }
it { is_expected.to respond_to :college }
it { is_expected.to respond_to :secondary_and_college }
end
- context '#validations' do
+ describe '#validations' do
it 'validates at_least_one_phase_offered' do
expect(described_class.new.tap(&:validate).errors[:base]).to \
eq ['Select at least one school phase']
end
end
- context '#primary?' do
+ describe '#primary?' do
context 'primary selected' do
subject { described_class.new primary: true }
@@ -33,7 +33,7 @@
end
end
- context '#secondary?' do
+ describe '#secondary?' do
context 'secondary selected' do
subject { described_class.new secondary: true }
@@ -65,7 +65,7 @@
end
end
- context '#college?' do
+ describe '#college?' do
context 'college selected' do
subject { described_class.new college: true }
@@ -97,13 +97,13 @@
end
end
- context '.new_from_bookings_school' do
+ describe '.new_from_bookings_school' do
+ subject { described_class.new_from_bookings_school school }
+
let :school do
FactoryBot.create :bookings_school, :with_primary_key_stage_info
end
- subject { described_class.new_from_bookings_school school }
-
it 'sets the attributes from the bookings_school' do
expect(subject.primary?).to be true
expect(subject.secondary?).to be false
diff --git a/spec/forms/schools/on_boarding/subject_list_spec.rb b/spec/forms/schools/on_boarding/subject_list_spec.rb
index ac465b3c06..8c32374f24 100644
--- a/spec/forms/schools/on_boarding/subject_list_spec.rb
+++ b/spec/forms/schools/on_boarding/subject_list_spec.rb
@@ -1,11 +1,11 @@
require 'rails_helper'
describe Schools::OnBoarding::SubjectList, type: :model do
- context '#attibutes' do
+ describe '#attibutes' do
it { is_expected.to respond_to :subject_ids }
end
- context '#subject_ids' do
+ describe '#subject_ids' do
it 'removes blank values' do
expect(described_class.new(subject_ids: [""]).subject_ids).to eq []
end
@@ -26,12 +26,12 @@
end
context 'when non existent subject ids selected' do
+ subject { described_class.new subject_ids: [bookings_subject.id + 1] }
+
let :bookings_subject do
FactoryBot.create :bookings_subject
end
- subject { described_class.new subject_ids: [bookings_subject.id + 1] }
-
it 'is invalid' do
expect(subject).not_to be_valid
expect(subject.errors.full_messages).to eq ['Subject not available']
@@ -39,13 +39,13 @@
end
end
- context '.new_from_bookings_school' do
+ describe '.new_from_bookings_school' do
+ subject { described_class.new_from_bookings_school bookings_school }
+
let :bookings_school do
FactoryBot.create :bookings_school, :with_subjects
end
- subject { described_class.new_from_bookings_school bookings_school }
-
it 'sets the subjects from the bookings school' do
expect(subject.subject_ids).to eq bookings_school.subject_ids
end
diff --git a/spec/forms/schools/on_boarding/teacher_training_spec.rb b/spec/forms/schools/on_boarding/teacher_training_spec.rb
index 4a0c9a6221..61c9b6e3cb 100644
--- a/spec/forms/schools/on_boarding/teacher_training_spec.rb
+++ b/spec/forms/schools/on_boarding/teacher_training_spec.rb
@@ -12,6 +12,7 @@
context 'when provides_teacher_training' do
subject { described_class.new provides_teacher_training: true }
+
it { is_expected.to validate_presence_of :teacher_training_details }
context 'when teacher_training_url is present' do
@@ -30,12 +31,15 @@
context 'when not provides_teacher_training' do
subject { described_class.new provides_teacher_training: false }
+
it { is_expected.not_to validate_presence_of :teacher_training_details }
it { is_expected.not_to validate_presence_of :teacher_training_url }
end
end
- context '.new_from_bookings_school' do
+ describe '.new_from_bookings_school' do
+ subject { described_class.new_from_bookings_school school }
+
let :school do
FactoryBot.build \
:bookings_school,
@@ -44,8 +48,6 @@
teacher_training_provider: true
end
- subject { described_class.new_from_bookings_school school }
-
it "sets provides_teacher_training" do
expect(subject.provides_teacher_training).to be true
end
diff --git a/spec/forms/schools/on_boarding/wizard_spec.rb b/spec/forms/schools/on_boarding/wizard_spec.rb
index 7e38a770e2..106bf06852 100644
--- a/spec/forms/schools/on_boarding/wizard_spec.rb
+++ b/spec/forms/schools/on_boarding/wizard_spec.rb
@@ -11,7 +11,7 @@
let(:previous_step) { nil }
it "returns the first required step (from all steps/sections)" do
- is_expected.to be(:phases_list)
+ expect(subject).to be(:phases_list)
end
end
@@ -19,7 +19,7 @@
let(:previous_step) { :unknown }
it "returns the first required step (from all steps/sections)" do
- is_expected.to be(:phases_list)
+ expect(subject).to be(:phases_list)
end
end
@@ -33,7 +33,7 @@
let(:previous_step) { :dbs_requirement }
it "returns the next step" do
- is_expected.to be(:fees)
+ expect(subject).to be(:fees)
end
end
@@ -42,7 +42,7 @@
let(:previous_step) { :dbs_requirement }
it "skips the complted step, returning the next incomplete step" do
- is_expected.to be(:administration_fee)
+ expect(subject).to be(:administration_fee)
end
end
@@ -300,10 +300,10 @@
end
describe "#step_state" do
- let(:step) { :dbs_requirement }
-
subject { instance.step_state(step) }
+ let(:step) { :dbs_requirement }
+
it { is_expected.to be(:not_started) }
context "when the step has been completed" do
diff --git a/spec/forms/schools/placement_dates/configuration_form_spec.rb b/spec/forms/schools/placement_dates/configuration_form_spec.rb
index e85ce2f05a..a3224e4678 100644
--- a/spec/forms/schools/placement_dates/configuration_form_spec.rb
+++ b/spec/forms/schools/placement_dates/configuration_form_spec.rb
@@ -5,7 +5,7 @@
create :bookings_school, :with_subjects, subject_count: 3
end
- context '.new_from_date' do
+ describe '.new_from_date' do
subject { described_class.new_from_date placement_date }
context 'when the placement_date has already been published' do
@@ -49,14 +49,14 @@
end
it 'returns a new subject selection without attributes set' do
- expect(subject.available_for_all_subjects).to be nil
- expect(subject.max_bookings_count).to be nil
- expect(subject.has_limited_availability).to be nil
+ expect(subject.available_for_all_subjects).to be_nil
+ expect(subject.max_bookings_count).to be_nil
+ expect(subject.has_limited_availability).to be_nil
end
end
end
- context '#save' do
+ describe '#save' do
before { described_class.new(attributes).save(placement_date) }
context 'for a unpublished placement_date' do
@@ -140,7 +140,7 @@
end
it 'sets published_at to nil' do
- expect(placement_date.published_at).to eq nil
+ expect(placement_date.published_at).to be_nil
end
end
end
@@ -214,20 +214,23 @@
end
end
- context '#subject_specific?' do
+ describe '#subject_specific?' do
context 'when the date doesnt support subjects' do
subject { described_class.new supports_subjects: false }
+
it { is_expected.not_to be_subject_specific }
end
context 'when the date supports subject' do
context 'when the date is available_for_all_subjects' do
subject { described_class.new supports_subjects: true, available_for_all_subjects: true }
+
it { is_expected.not_to be_subject_specific }
end
context 'when the date is not available_for_all_subjects' do
subject { described_class.new supports_subjects: true, available_for_all_subjects: false }
+
it { is_expected.to be_subject_specific }
end
end
diff --git a/spec/forms/schools/placement_dates/placement_detail_spec.rb b/spec/forms/schools/placement_dates/placement_detail_spec.rb
index c7c2259452..4cbb16eeef 100644
--- a/spec/forms/schools/placement_dates/placement_detail_spec.rb
+++ b/spec/forms/schools/placement_dates/placement_detail_spec.rb
@@ -2,7 +2,7 @@
describe Schools::PlacementDates::PlacementDetail, type: :model do
context 'validations' do
- context '#start_availability_offset' do
+ describe '#start_availability_offset' do
it do
expect(subject).to(
validate_numericality_of(:start_availability_offset)
@@ -10,16 +10,17 @@
.is_less_than_or_equal_to(180)
)
end
+
it { expect(subject).to validate_presence_of(:start_availability_offset) }
it "is greater than #end_availability_offset" do
subject.end_availability_offset = 1
- is_expected.to allow_value(2).for :start_availability_offset
- is_expected.to_not allow_values(0, 1).for :start_availability_offset
+ expect(subject).to allow_value(2).for :start_availability_offset
+ expect(subject).not_to allow_values(0, 1).for :start_availability_offset
end
end
- context '#end_availability_offset' do
+ describe '#end_availability_offset' do
it do
expect(subject).to(
validate_numericality_of(:end_availability_offset)
@@ -27,10 +28,11 @@
.is_less_than_or_equal_to(100)
)
end
+
it { expect(subject).to validate_presence_of(:end_availability_offset) }
end
- context '#duration' do
+ describe '#duration' do
it do
expect(subject).to(
validate_numericality_of(:duration)
@@ -38,30 +40,31 @@
.is_less_than(100)
)
end
+
it { expect(subject).to validate_presence_of(:duration) }
end
- context '#virtual' do
+ describe '#virtual' do
it { is_expected.to allow_values(true, false).for :virtual }
it { is_expected.not_to allow_value(nil).for :virtual }
end
- context '#supports_subjects' do
+ describe '#supports_subjects' do
context "when placement dates school has primary and secondary phases" do
+ subject { described_class.new_from_date placement_date }
+
include_context 'with phases'
let(:school) { create(:bookings_school, :primary, :secondary) }
let(:placement_date) { create :bookings_placement_date, bookings_school: school }
- subject { described_class.new_from_date placement_date }
-
it { is_expected.to allow_values(true, false).for :supports_subjects }
it { is_expected.not_to allow_value(nil).for :supports_subjects }
end
end
end
- context '.new_from_date' do
+ describe '.new_from_date' do
subject { described_class.new_from_date placement_date }
let(:placement_date) { create :bookings_placement_date, published_at: DateTime.now }
@@ -71,10 +74,11 @@
end
end
- context '#save' do
- let(:placement_date) { create :bookings_placement_date }
+ describe '#save' do
subject { described_class.new }
+ let(:placement_date) { create :bookings_placement_date }
+
context 'invalid' do
before { allow(subject).to receive(:valid?).and_return(false) }
@@ -84,6 +88,8 @@
end
context 'valid' do
+ subject { described_class.new(attributes) }
+
let(:placement_date) { create :bookings_placement_date }
let(:attributes) do
{
@@ -103,14 +109,12 @@
supports_subjects: false
end
- subject { described_class.new(attributes) }
-
it 'updates the placement_date subjects to the selected_subjects' do
expect(placement_date.start_availability_offset).to eq 100
expect(placement_date.end_availability_offset).to eq 100
expect(placement_date.duration).to eq 100
- expect(placement_date.virtual).to eq false
- expect(placement_date.supports_subjects).to eq false
+ expect(placement_date.virtual).to be false
+ expect(placement_date.supports_subjects).to be false
end
end
end
diff --git a/spec/forms/schools/placement_dates/recurrences_selection_spec.rb b/spec/forms/schools/placement_dates/recurrences_selection_spec.rb
index 4dce54ea97..d5b356e0ca 100644
--- a/spec/forms/schools/placement_dates/recurrences_selection_spec.rb
+++ b/spec/forms/schools/placement_dates/recurrences_selection_spec.rb
@@ -4,45 +4,45 @@
let(:now) { Time.zone.now }
context 'validations' do
- context '#start_at' do
+ describe '#start_at' do
it { expect(subject).to validate_presence_of(:start_at) }
end
- context '#end_at' do
+ describe '#end_at' do
it { expect(subject).to validate_presence_of(:end_at) }
it "cannot be the same day as start_at" do
subject.start_at = now
- is_expected.not_to allow_value(now).for :end_at
+ expect(subject).not_to allow_value(now).for :end_at
end
it "cannot be earlier than start_at" do
subject.start_at = now
- is_expected.not_to allow_value(now - 1.day).for :end_at
+ expect(subject).not_to allow_value(now - 1.day).for :end_at
end
it "can be later than start_at" do
subject.start_at = now
- is_expected.to allow_value(now + 1.day).for :end_at
+ expect(subject).to allow_value(now + 1.day).for :end_at
end
it "cannot be later than 4 months after start_at" do
subject.start_at = now
- is_expected.not_to allow_value(now + 4.months + 1.day).for :end_at
+ expect(subject).not_to allow_value(now + 4.months + 1.day).for :end_at
end
it "cannot result in no recurrences" do
subject.recurrence_period = described_class::RECURRENCE_PERIODS[:daily]
subject.start_at = Date.today.next_occurring(:saturday)
- is_expected.not_to allow_value(Date.today.next_occurring(:sunday)).for :end_at
+ expect(subject).not_to allow_value(Date.today.next_occurring(:sunday)).for :end_at
end
end
- context '#recurrence_period' do
+ describe '#recurrence_period' do
it { expect(subject).to validate_presence_of(:recurrence_period) }
end
- context '#custom_recurrence_days' do
+ describe '#custom_recurrence_days' do
context "when recurrence_period is custom" do
before do
subject.recurrence_period = described_class::RECURRENCE_PERIODS[:custom]
@@ -54,7 +54,7 @@
end
end
- context '.new_from_date' do
+ describe '.new_from_date' do
subject { described_class.new_from_date placement_date }
let(:placement_date) { create :bookings_placement_date, published_at: DateTime.now }
@@ -64,8 +64,10 @@
end
end
- context '#recurring_dates' do
+ describe '#recurring_dates' do
context "when daily" do
+ subject { described_class.new(attributes).recurring_dates }
+
let(:next_monday) { Date.today.next_occurring(:monday) }
let(:monday_after_next) { next_monday.next_occurring(:monday) }
let(:attributes) do
@@ -76,8 +78,6 @@
}
end
- subject { described_class.new(attributes).recurring_dates }
-
it 'returns a correct array of dates (skipping weekends)' do
expect(subject).to eq [
next_monday,
@@ -92,6 +92,8 @@
end
context "when weekly" do
+ subject { described_class.new(attributes).recurring_dates }
+
let(:next_monday) { Date.today.next_occurring(:monday) }
let(:attributes) do
{
@@ -101,8 +103,6 @@
}
end
- subject { described_class.new(attributes).recurring_dates }
-
it 'returns a correct array of dates' do
expect(subject).to eq [
next_monday,
@@ -114,6 +114,8 @@
end
context "when fortnightly" do
+ subject { described_class.new(attributes).recurring_dates }
+
let(:next_monday) { Date.today.next_occurring(:monday) }
let(:attributes) do
{
@@ -123,8 +125,6 @@
}
end
- subject { described_class.new(attributes).recurring_dates }
-
it 'returns a correct array of dates' do
expect(subject).to eq [
next_monday,
@@ -134,6 +134,8 @@
end
context "when custom" do
+ subject { described_class.new(attributes).recurring_dates }
+
let(:next_monday) { Date.today.next_occurring(:monday) }
let(:attributes) do
{
@@ -144,8 +146,6 @@
}
end
- subject { described_class.new(attributes).recurring_dates }
-
it 'returns a correct array of dates' do
expect(subject).to eq [
next_monday,
diff --git a/spec/forms/schools/placement_dates/subject_selection_spec.rb b/spec/forms/schools/placement_dates/subject_selection_spec.rb
index d9bad99990..bb2af9e1d0 100644
--- a/spec/forms/schools/placement_dates/subject_selection_spec.rb
+++ b/spec/forms/schools/placement_dates/subject_selection_spec.rb
@@ -9,7 +9,7 @@
it { is_expected.to validate_presence_of :subject_ids }
end
- context '.new_from_date' do
+ describe '.new_from_date' do
subject { described_class.new_from_date placement_date }
context 'published' do
@@ -39,14 +39,14 @@
end
end
- context '#subject_ids=' do
+ describe '#subject_ids=' do
it 'removes any blank values' do
subject.subject_ids = ["", "1", "2", "3"]
expect(subject.subject_ids).to eq %w[1 2 3]
end
end
- context '#save' do
+ describe '#save' do
let :placement_date do
create \
:bookings_placement_date,
@@ -65,7 +65,7 @@
it { is_expected.to(be_invalid) }
it 'doesnt update the placement_date' do
- expect(placement_date.published_at).to be nil
+ expect(placement_date.published_at).to be_nil
end
end
diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb
index 58b1fcfdf0..61cf54c66e 100644
--- a/spec/helpers/application_helper_spec.rb
+++ b/spec/helpers/application_helper_spec.rb
@@ -17,6 +17,8 @@ class StubModel
let(:user) { User.exchange(dfe_sign_in_user) }
context 'Breadcrumbs' do
+ subject { Nokogiri.parse(helper.breadcrumbs) }
+
let(:args) do
{
'page one' => '/page/one',
@@ -31,7 +33,6 @@ class StubModel
let(:hyperlink_breadcrumb_count) { hyperlink_breadcrumbs.count }
before { helper.breadcrumbs = args }
- subject { Nokogiri.parse(helper.breadcrumbs) }
specify 'the generated list should contain GOV.UK breadcrumb-compliant markup' do
selector = [
@@ -66,8 +67,9 @@ class StubModel
end
end
- context '#current_user_info_and_logout_link' do
+ describe '#current_user_info_and_logout_link' do
subject { helper.current_user_info_and_logout_link user }
+
context 'when a user is logged in' do
specify "should contain the person's name" do
expect(subject).to include("#{given_name} #{family_name}")
@@ -79,13 +81,13 @@ class StubModel
end
end
- context '#current_candidate_info_and_logout_link' do
+ describe '#current_candidate_info_and_logout_link' do
+ subject { helper.current_candidate_info_and_logout_link current_candidate }
+
let(:current_candidate) do
create(:candidate, :with_api_contact)
end
- subject { helper.current_candidate_info_and_logout_link current_candidate }
-
specify "should contain the person's name" do
expect(subject).to include(current_candidate.full_name)
end
@@ -106,6 +108,7 @@ class StubModel
context 'when current_user absent' do
let(:user) { nil }
+
specify "should return 'Unknown'" do
expect(subject).to eql("Unknown")
end
@@ -115,18 +118,21 @@ class StubModel
describe '#page_heading' do
context 'with parameter' do
subject! { page_heading('My Page Title') }
+
it { is_expected.to eql('My Page Title
') }
it { expect(page_title).to eql('My Page Title - Get school experience - GOV.UK') }
end
context 'with block' do
subject! { page_heading { 'My Page Title' } }
+
it { is_expected.to eql('My Page Title
') }
it { expect(page_title).to eql('My Page Title - Get school experience - GOV.UK') }
end
context 'with custom options' do
subject! { page_heading('Page Title', class: 'govuk-heading-xl') }
+
it { is_expected.to eql('Page Title
') }
it { expect(page_title).to eql('Page Title - Get school experience - GOV.UK') }
end
diff --git a/spec/helpers/candidates/maps_helper_spec.rb b/spec/helpers/candidates/maps_helper_spec.rb
index 7e117c00ff..17a4cae082 100644
--- a/spec/helpers/candidates/maps_helper_spec.rb
+++ b/spec/helpers/candidates/maps_helper_spec.rb
@@ -2,47 +2,47 @@
RSpec.describe Candidates::MapsHelper, type: :helper do
before do
- allow(Rails.application.config.x).to receive(:google_maps_key) { '12345' }
+ allow(Rails.application.config.x).to receive(:google_maps_key).and_return('12345')
@latitude = "53.4782"
@longitude = "-2.2299"
@zoom = 8
end
- context '.static_map_url' do
+ describe '.static_map_url' do
subject do
static_map_url(@latitude, @longitude, mapsize: [300, 200], zoom: @zoom)
end
- it('should return a correct Google Maps url') do
+ it('returns a correct Google Maps url') do
url = "https://maps.googleapis.com/maps/api/staticmap"
params = "center=#{@latitude}%2C#{@longitude}&key=12345&markers=#{@latitude}%2C#{@longitude}&scale=2&size=300x200&zoom=#{@zoom}"
expect(subject).to eq("#{url}?#{params}")
end
end
- context '.ajax_map' do
+ describe '.ajax_map' do
include ActionController::Base::HelperMethods
subject { ajax_map(@latitude, @longitude, mapsize: [300, 200], zoom: @zoom) }
- it "should include wrapping div" do
+ it "includes wrapping div" do
expect(subject).to match('class="embedded-map"')
end
- it "should include map container div" do
+ it "includes map container div" do
expect(subject).to match('class="embedded-map__inner-container"')
end
- it "should include nested non-js fallback img" do
+ it "includes nested non-js fallback img" do
expect(subject).to match(/ li').map(&:text)).to eql(@school.phases.map(&:name))
end
end
describe ".format_school_phases_compact" do
+ subject { format_school_phases_compact(@school) }
+
before do
@school = OpenStruct.new(
phases: [
@@ -144,16 +147,14 @@
)
end
- subject { format_school_phases_compact(@school) }
-
it { is_expected.to eq("First, Second, Third") }
end
- context '.describe_current_search' do
- let(:opts) { {} }
-
+ describe '.describe_current_search' do
subject { describe_current_search(search, **opts) }
+ let(:opts) { {} }
+
context 'with location search' do
context 'and name supplied by search' do
let(:search) do
@@ -217,12 +218,14 @@
end
end
- context '.school_location_map' do
+ describe '.school_location_map' do
include Candidates::MapsHelper
include ActionController::Base::HelperMethods
+ subject { school_location_map @school }
+
before do
- allow(Rails.application.config.x).to receive(:google_maps_key) { '12345' }
+ allow(Rails.application.config.x).to receive(:google_maps_key).and_return('12345')
@latitude = "53.4782"
@longitude = "-2.2299"
@school = OpenStruct.new(
@@ -231,9 +234,7 @@
)
end
- subject { school_location_map @school }
-
- it('should return a correct Google Maps for schools location') do
+ it('returns a correct Google Maps for schools location') do
expect(subject).to match(/foobar
', 'no content') }
+
it { is_expected.to have_css('p', text: 'foobar') }
end
context 'without content but text msg' do
subject { content_or_msg('', 'no content') }
+
it { is_expected.to have_css('em', text: 'no content') }
end
context 'without content but block msg' do
subject { content_or_msg('') { 'no content' } }
+
it { is_expected.to have_css('b', text: 'no content') }
end
end
@@ -303,6 +312,8 @@
end
context 'splitting up items into a HTML list' do
+ subject { split_to_list content }
+
let(:content) do
<<~CONTENT
The good,
@@ -311,14 +322,14 @@
CONTENT
end
- subject { split_to_list content }
-
specify 'should create a list with the correct number of entries' do
- is_expected.to have_css('ul.govuk-list--bullet > li', count: 3)
+ expect(subject).to have_css('ul.govuk-list--bullet > li', count: 3)
end
end
context 'dealing with blank lines' do
+ subject { split_to_list content }
+
let(:content) do
<<~CONTENT
The good,
@@ -327,10 +338,8 @@
CONTENT
end
- subject { split_to_list content }
-
specify 'should create a list with the correct number of entries' do
- is_expected.to have_css('ul.govuk-list--bullet > li', count: 2)
+ expect(subject).to have_css('ul.govuk-list--bullet > li', count: 2)
end
end
end
diff --git a/spec/helpers/link_and_button_helper_spec.rb b/spec/helpers/link_and_button_helper_spec.rb
index 15121692c5..47afc15272 100644
--- a/spec/helpers/link_and_button_helper_spec.rb
+++ b/spec/helpers/link_and_button_helper_spec.rb
@@ -2,20 +2,22 @@
describe LinkAndButtonHelper do
shared_examples 'govuk-styled links and buttons' do |method, tag|
+ subject { helper.send(method, link_text, path) }
+
let(:method) { method }
let(:tag) { tag }
let(:path) { candidates_root_path }
let(:link_text) { 'Continue' }
- subject { helper.send(method, link_text, path) }
specify 'should create a button link with the appropriate data module' do
expect(subject).to have_css("#{tag}.govuk-button[data-module='govuk-button']")
end
context 'overriding text' do
- let(:custom_text) { 'Proceed' }
subject { helper.send(method, custom_text, path) }
+ let(:custom_text) { 'Proceed' }
+
specify 'button should contain the provided text' do
expect(subject).to have_css("#{tag}.govuk-button", text: custom_text)
rescue RSpec::Expectations::ExpectationNotMetError
@@ -34,9 +36,10 @@
end
context 'extra classes' do
- let(:extra_classes) { %w[pink stripy] }
subject { helper.send(method, link_text, path, class: extra_classes) }
+ let(:extra_classes) { %w[pink stripy] }
+
specify 'should create a button link with extra provided classes' do
expect(subject).to have_css("#{tag}.#{extra_classes.join('.')}")
end
@@ -59,10 +62,10 @@
end
context 'blocks' do
- let(:custom_text) { 'Advance' }
-
subject { helper.send(method, path) { custom_text } }
+ let(:custom_text) { 'Advance' }
+
specify 'button should contain the text provided by the block' do
expect(subject).to have_css("#{tag}.govuk-button", text: custom_text)
rescue RSpec::Expectations::ExpectationNotMetError
@@ -82,6 +85,7 @@
describe '#govuk_back_link' do
context 'without params' do
subject { govuk_back_link }
+
it { is_expected.to have_content 'Back' }
it { is_expected.to have_css 'a.govuk-back-link' }
it { is_expected.not_to have_css 'a[data-controller]' }
@@ -89,6 +93,7 @@
context 'with title' do
subject { govuk_back_link text: 'Dashboard' }
+
it { is_expected.to have_content 'Dashboard' }
it { is_expected.to have_css 'a.govuk-back-link' }
it { is_expected.not_to have_css 'a[data-controller]' }
@@ -96,6 +101,7 @@
context 'with title and js enabled' do
subject { govuk_back_link text: 'Dashboard', javascript: true }
+
it { is_expected.to have_content 'Dashboard' }
it { is_expected.to have_css 'a.govuk-back-link' }
it { is_expected.to have_css 'a[data-controller="back-link"]' }
@@ -103,6 +109,7 @@
context 'with custom class' do
subject { govuk_back_link class: 'some-other' }
+
it { is_expected.to have_content 'Back' }
it { is_expected.to have_css 'a.govuk-back-link.some-other' }
it { is_expected.not_to have_css 'a[data-controller]' }
@@ -110,6 +117,7 @@
context 'with javascript and custom data controller' do
subject { govuk_back_link javascript: true, data: { controller: 'test' } }
+
it { is_expected.to have_content 'Back' }
it { is_expected.to have_css 'a.govuk-back-link' }
it { is_expected.to have_css 'a[data-controller="back-link test"]' }
@@ -117,6 +125,7 @@
context 'with back path' do
subject { govuk_back_link '/test' }
+
it { is_expected.to have_content 'Back' }
it { is_expected.to have_css 'a.govuk-back-link' }
it { is_expected.to have_css 'a[href="/test"]' }
diff --git a/spec/helpers/schools/bookings_helper_spec.rb b/spec/helpers/schools/bookings_helper_spec.rb
index b71640a732..31db02dd5c 100644
--- a/spec/helpers/schools/bookings_helper_spec.rb
+++ b/spec/helpers/schools/bookings_helper_spec.rb
@@ -8,7 +8,7 @@
let(:booking) { create(:bookings_booking, :attended) }
it do
- is_expected.to \
+ expect(subject).to \
have_css('strong.govuk-tag', text: 'Yes')
end
end
@@ -17,7 +17,7 @@
let(:booking) { create(:bookings_booking, :unattended) }
it do
- is_expected.to \
+ expect(subject).to \
have_css('strong.govuk-tag.govuk-tag--grey', text: 'No')
end
end
@@ -26,15 +26,16 @@
let(:booking) { create(:bookings_booking, :cancelled_by_school) }
it do
- is_expected.to \
+ expect(subject).to \
have_css('strong.govuk-tag.govuk-tag--red', text: 'Cancelled')
end
end
context 'for unknown' do
let(:booking) { create(:bookings_booking, :accepted) }
+
it do
- is_expected.to \
+ expect(subject).to \
have_css('strong.govuk-tag.govuk-tag--light-blue', text: 'Not set')
end
end
diff --git a/spec/helpers/schools/dashboards_helper_spec.rb b/spec/helpers/schools/dashboards_helper_spec.rb
index 2922dcc52d..ecc653b2bf 100644
--- a/spec/helpers/schools/dashboards_helper_spec.rb
+++ b/spec/helpers/schools/dashboards_helper_spec.rb
@@ -2,10 +2,11 @@
describe Schools::DashboardsHelper, type: 'helper' do
describe '#numbered_circle' do
+ subject { Nokogiri.parse(circle) }
+
let(:text) { '15' }
let(:aria_label) { 'upcoming bookings' }
let(:circle) { numbered_circle(text, aria_label: aria_label) }
- subject { Nokogiri.parse(circle) }
context 'id' do
context 'when not set' do
@@ -17,6 +18,7 @@
context 'when set' do
let(:id) { 'what-a-nice-circle' }
let(:circle) { numbered_circle(text, id: id, aria_label: aria_label) }
+
specify 'should be set to the overridden value' do
expect(subject.at_css('div.numbered-circle')['id']).to eql(id)
end
@@ -35,17 +37,21 @@
context 'with 0' do
subject { numbered_circle 0, aria_label: 'test' }
+
it { is_expected.to be_nil }
context 'and show_if_zero set' do
- let(:circle) { numbered_circle 0, aria_label: 'x', show_if_zero: true }
subject { Nokogiri.parse circle }
+
+ let(:circle) { numbered_circle 0, aria_label: 'x', show_if_zero: true }
+
it { is_expected.to have_css 'div', text: '0' }
end
end
context 'with nil' do
subject { numbered_circle nil, aria_label: 'test' }
+
it { is_expected.to be_nil }
end
end
@@ -55,6 +61,7 @@
context 'when on' do
let(:school) { build(:bookings_school) }
+
specify "should be 'on' when on is true" do
expect(subject).to eql('on')
end
@@ -62,43 +69,48 @@
context 'when off' do
let(:school) { build(:bookings_school, :disabled) }
+
specify "should be 'off' when on is false" do
expect(subject).to eql('off')
end
end
end
- context '#show_no_placement_dates_warning?' do
+ describe '#show_no_placement_dates_warning?' do
context 'when availability preference is fixed and dates are available' do
- let(:school) { create(:bookings_school, :with_fixed_availability_preference, :with_placement_dates) }
subject { show_no_placement_dates_warning?(school) }
+ let(:school) { create(:bookings_school, :with_fixed_availability_preference, :with_placement_dates) }
+
specify 'should be false' do
expect(subject).to be false
end
end
context 'when availability preference is flexible and dates are available' do
- let(:school) { create(:bookings_school, :with_placement_dates) }
subject { show_no_placement_dates_warning?(school) }
+ let(:school) { create(:bookings_school, :with_placement_dates) }
+
specify 'should be false' do
expect(subject).to be false
end
end
context 'when availability preference is fixed and dates are not available' do
- let(:school) { create(:bookings_school, :with_fixed_availability_preference) }
subject { show_no_placement_dates_warning?(school) }
+ let(:school) { create(:bookings_school, :with_fixed_availability_preference) }
+
specify 'should be true' do
expect(subject).to be true
end
end
end
- context '#not_onboarded_warning' do
+ describe '#not_onboarded_warning' do
let(:school) { create(:bookings_school) }
+
context 'when the school has placement requests' do
let!(:pr) { create(:bookings_placement_request, school: school) }
@@ -127,10 +139,10 @@
end
describe "#in_school_group?" do
- let(:sample) { SchoolGroup::SCHOOL_URNS_IN_GROUP.sample }
-
subject { helper }
+ let(:sample) { SchoolGroup::SCHOOL_URNS_IN_GROUP.sample }
+
it { is_expected.to be_in_school_group(sample) }
it { is_expected.to be_in_school_group(sample.to_s) }
it { is_expected.not_to be_in_school_group(123_456) }
diff --git a/spec/helpers/schools/placement_requests_helper_spec.rb b/spec/helpers/schools/placement_requests_helper_spec.rb
index 95c32ca61f..ed89f2eab1 100644
--- a/spec/helpers/schools/placement_requests_helper_spec.rb
+++ b/spec/helpers/schools/placement_requests_helper_spec.rb
@@ -2,6 +2,8 @@
describe Schools::PlacementRequestsHelper, type: :helper do
describe "#cancellation_reasons" do
+ subject { cancellation_reasons(cancellation) }
+
let(:cancellation) do
build(:cancellation,
fully_booked: true,
@@ -9,8 +11,6 @@
reason: "Sorry!")
end
- subject { cancellation_reasons(cancellation) }
-
it { is_expected.to have_css("ul li", count: 2) }
it { is_expected.to have_css("li", text: "The date you requested is fully booked.") }
it { is_expected.to have_css("li", text: "Sorry!") }
diff --git a/spec/helpers/text_formatting_helper_spec.rb b/spec/helpers/text_formatting_helper_spec.rb
index 08612eef3e..8520bee94d 100644
--- a/spec/helpers/text_formatting_helper_spec.rb
+++ b/spec/helpers/text_formatting_helper_spec.rb
@@ -6,19 +6,21 @@
context 'with new lines' do
let(:content) { "hello\r\n\r\nworld" }
+
it { is_expected.to eql "hello
\n\nworld
" }
end
context 'with html content' do
let(:content) { "hello world" }
+
it { is_expected.to eql "hello world
" }
end
context "with options" do
- let(:content) { "hello world" }
-
subject { safe_format(content, wrapper_tag: "span") }
+ let(:content) { "hello world" }
+
it { is_expected.to eq("hello world") }
end
end
@@ -28,11 +30,13 @@
context "with new lines" do
let(:content) { "foo\nbar" }
+
it { is_expected.to eql "foo\n
bar
" }
end
context "without new lines" do
let(:content) { "foobar" }
+
it { is_expected.to eql "foobar" }
end
end
diff --git a/spec/jobs/bookings/reminder_job_spec.rb b/spec/jobs/bookings/reminder_job_spec.rb
index 518acc9263..15ddfcb3e5 100644
--- a/spec/jobs/bookings/reminder_job_spec.rb
+++ b/spec/jobs/bookings/reminder_job_spec.rb
@@ -1,17 +1,18 @@
require 'rails_helper'
describe Bookings::ReminderJob, type: :job do
+ subject { described_class.perform_now(booking, time_until_booking, time_until_booking_descriptive) }
+
let(:time_until_booking) { 'one week' }
let(:time_until_booking_descriptive) { 'in one week' }
let(:reminder) { double(Bookings::Reminder, deliver: true) }
let(:booking) { create(:bookings_booking) }
+
before do
allow(Bookings::Reminder).to receive(:new).with(booking, time_until_booking, time_until_booking_descriptive).and_return(reminder)
end
- subject { described_class.perform_now(booking, time_until_booking, time_until_booking_descriptive) }
-
- context '#perform' do
+ describe '#perform' do
before { subject }
specify 'should build a new reminder with the correct params' do
diff --git a/spec/jobs/candidates/registrations/placement_request_job_spec.rb b/spec/jobs/candidates/registrations/placement_request_job_spec.rb
index f4a1e138a2..9b3c63e837 100644
--- a/spec/jobs/candidates/registrations/placement_request_job_spec.rb
+++ b/spec/jobs/candidates/registrations/placement_request_job_spec.rb
@@ -48,7 +48,7 @@
registration_store.store! registration_session
end
- context '#perform' do
+ describe '#perform' do
context 'no errors' do
before do
perform_enqueued_jobs do
diff --git a/spec/jobs/candidates/registrations/send_email_confirmation_job_spec.rb b/spec/jobs/candidates/registrations/send_email_confirmation_job_spec.rb
index 99cb673d25..8ce9372c8a 100644
--- a/spec/jobs/candidates/registrations/send_email_confirmation_job_spec.rb
+++ b/spec/jobs/candidates/registrations/send_email_confirmation_job_spec.rb
@@ -21,7 +21,7 @@
Candidates::Registrations::RegistrationStore.instance.delete! uuid
end
- context '#perform' do
+ describe '#perform' do
before do
perform_enqueued_jobs do
described_class.perform_later uuid, host
diff --git a/spec/jobs/cron/heart_beat_job_spec.rb b/spec/jobs/cron/heart_beat_job_spec.rb
index 82a3a0783a..a40a52fd91 100644
--- a/spec/jobs/cron/heart_beat_job_spec.rb
+++ b/spec/jobs/cron/heart_beat_job_spec.rb
@@ -2,10 +2,10 @@
describe Cron::HeartBeatJob, type: :job do
describe "#perform" do
- let(:school_sync_instance) { double Object, sync: true }
-
subject(:perform) { described_class.new.perform }
+ let(:school_sync_instance) { double Object, sync: true }
+
it "increments the sidekiq_heart_beat metric" do
expect { perform }.to increment_yabeda_counter(Yabeda.gse.sidekiq_heart_beat).by(1)
end
diff --git a/spec/jobs/cron/identify_closed_schools_job_spec.rb b/spec/jobs/cron/identify_closed_schools_job_spec.rb
index e19eed8581..6731192fad 100644
--- a/spec/jobs/cron/identify_closed_schools_job_spec.rb
+++ b/spec/jobs/cron/identify_closed_schools_job_spec.rb
@@ -2,6 +2,8 @@
describe Cron::IdentifyClosedSchoolsJob, type: :job do
describe "#perform" do
+ subject(:perform) { described_class.new.perform }
+
let(:email_double) { instance_double(NotifyEmail::ClosedOnboardedSchoolsSummary, despatch_later!: nil) }
let(:closed_school_1) { create(:bookings_school, :onboarded) }
let(:closed_school_2) { create(:bookings_school, :onboarded) }
@@ -25,8 +27,6 @@
CSV
end
- subject(:perform) { described_class.new.perform }
-
before do
temp_csv = Tempfile.new
temp_csv.write(csv)
diff --git a/spec/jobs/cron/reminders/add_availability_job_spec.rb b/spec/jobs/cron/reminders/add_availability_job_spec.rb
index f4d90eac44..87ffe20a4f 100644
--- a/spec/jobs/cron/reminders/add_availability_job_spec.rb
+++ b/spec/jobs/cron/reminders/add_availability_job_spec.rb
@@ -2,6 +2,8 @@
describe Cron::Reminders::AddAvailabilityJob, type: :job do
describe '#perform' do
+ subject! { described_class.new.perform }
+
let(:reminder_email_double) { instance_double(NotifyEmail::SchoolAddAvailabilityReminder, despatch_later!: true) }
let(:admin_contact_email) { "admin@email.com" }
@@ -16,8 +18,6 @@
end
end
- subject! { described_class.new.perform }
-
it 'sends a reminder email to all schools who created their profile yesterday and have no availability' do
expect(reminder_email_double).to have_received(:despatch_later!).once
end
diff --git a/spec/jobs/cron/reminders/next_week_job_spec.rb b/spec/jobs/cron/reminders/next_week_job_spec.rb
index 71b95b5b26..703d533dc1 100644
--- a/spec/jobs/cron/reminders/next_week_job_spec.rb
+++ b/spec/jobs/cron/reminders/next_week_job_spec.rb
@@ -6,6 +6,8 @@
end
describe '#perform' do
+ subject! { described_class.new.perform }
+
before do
FactoryBot.create(:bookings_booking, :accepted, date: 7.days.from_now.to_date)
FactoryBot.create(:bookings_booking, :accepted, date: 7.days.from_now.to_date)
@@ -16,8 +18,6 @@
allow(Bookings::ReminderJob).to receive(:perform_later).and_return(true)
end
- subject! { described_class.new.perform }
-
specify 'should schedule Bookings::ReminderJob for accepted bookings' do
expect(Bookings::ReminderJob).to have_received(:perform_later).exactly(2).times
end
diff --git a/spec/jobs/cron/reminders/tomorrow_job_spec.rb b/spec/jobs/cron/reminders/tomorrow_job_spec.rb
index 8982c13b9e..a55eafc5e7 100644
--- a/spec/jobs/cron/reminders/tomorrow_job_spec.rb
+++ b/spec/jobs/cron/reminders/tomorrow_job_spec.rb
@@ -6,6 +6,8 @@
end
describe '#perform' do
+ subject! { described_class.new.perform }
+
before do
FactoryBot.create(:bookings_booking, :accepted, date: Time.zone.tomorrow)
FactoryBot.create(:bookings_booking, :accepted, date: Time.zone.tomorrow)
@@ -16,8 +18,6 @@
allow(Bookings::ReminderJob).to receive(:perform_later).and_return(true)
end
- subject! { described_class.new.perform }
-
specify 'should schedule Bookings::ReminderJob for accepted bookings' do
expect(Bookings::ReminderJob).to have_received(:perform_later).exactly(2).times
end
diff --git a/spec/jobs/cron/send_entity_table_checks_to_bigquery_spec.rb b/spec/jobs/cron/send_entity_table_checks_to_bigquery_spec.rb
index cf77932bbe..b705fb535b 100644
--- a/spec/jobs/cron/send_entity_table_checks_to_bigquery_spec.rb
+++ b/spec/jobs/cron/send_entity_table_checks_to_bigquery_spec.rb
@@ -2,10 +2,10 @@
describe DfE::Analytics::EntityTableCheckJob, type: :job do
describe "#perform" do
- let(:school_sync_instance) { double Object, sync: true }
-
subject(:perform) { described_class.new.perform }
+ let(:school_sync_instance) { double Object, sync: true }
+
it 'executes the job successfully' do
expect { perform }.not_to raise_error
end
diff --git a/spec/jobs/cron/sync_schools_job_spec.rb b/spec/jobs/cron/sync_schools_job_spec.rb
index 5819686041..eba3e5b68e 100644
--- a/spec/jobs/cron/sync_schools_job_spec.rb
+++ b/spec/jobs/cron/sync_schools_job_spec.rb
@@ -2,14 +2,14 @@
describe Cron::SyncSchoolsJob, type: :job do
describe '#perform' do
+ subject! { described_class.new.perform }
+
let(:school_sync_instance) { double Object, sync: true }
before do
allow(Bookings::SchoolSync).to receive(:new).and_return(school_sync_instance)
end
- subject! { described_class.new.perform }
-
specify 'calling perform should call Bookings::SchoolSync.new.sync' do
expect(school_sync_instance).to have_received(:sync)
end
diff --git a/spec/jobs/notify_job_spec.rb b/spec/jobs/notify_job_spec.rb
index 46e4562fde..5483bccf0d 100644
--- a/spec/jobs/notify_job_spec.rb
+++ b/spec/jobs/notify_job_spec.rb
@@ -42,7 +42,7 @@
executions.times { job.perform_now }
end
- context '#perform' do
+ describe '#perform' do
context 'on error' do
context 'retryable error' do
let(:notify_class) { NotifyRetryableErroringClient }
@@ -87,8 +87,8 @@
end
describe Notify::BaseJob, type: :job do
- context "#perform" do
- it "should fail with NotImplementedError'" do
+ describe "#perform" do
+ it "fails with NotImplementedError'" do
expect { subject.perform }.to raise_error(NotImplementedError, 'You must implement the perform method')
end
end
diff --git a/spec/lib/academic_year_spec.rb b/spec/lib/academic_year_spec.rb
index 5a68ef02da..7decb915f0 100644
--- a/spec/lib/academic_year_spec.rb
+++ b/spec/lib/academic_year_spec.rb
@@ -8,11 +8,13 @@
context "with date after the new academic year has started" do
let(:date) { Date.parse("2021-10-12") }
+
it { is_expected.to eql Date.parse("2021-09-01").at_beginning_of_day }
end
context "with date before the new academic year has started" do
let(:date) { Date.parse("2021-08-12") }
+
it { is_expected.to eql Date.parse("2020-09-01").at_beginning_of_day }
end
end
@@ -22,11 +24,13 @@
context "with date after the new academic year has started" do
let(:time) { Time.zone.parse("2021-10-12") }
+
it { is_expected.to eql Date.parse("2021-09-01").at_beginning_of_day }
end
context "with date before the new academic year has started" do
let(:time) { Time.zone.parse("2021-08-12") }
+
it { is_expected.to eql Date.parse("2020-09-01").at_beginning_of_day }
end
end
diff --git a/spec/lib/cloud_front_ip_filter_spec.rb b/spec/lib/cloud_front_ip_filter_spec.rb
index f5e9f16d48..378ec44377 100644
--- a/spec/lib/cloud_front_ip_filter_spec.rb
+++ b/spec/lib/cloud_front_ip_filter_spec.rb
@@ -2,13 +2,13 @@
require "cloud_front_ip_filter"
RSpec.describe CloudFrontIpFilter do
+ subject { described_class.new original }
+
before do
stub_request(:get, "https://ip-ranges.amazonaws.com/ip-ranges.json")
.to_return(status: 401) # will fallback to copy in Gem
end
- subject { described_class.new original }
-
let(:original) { ->(ip) { /192\.168\.1\./.match?(ip) } }
describe "#call" do
diff --git a/spec/lib/conversions_spec.rb b/spec/lib/conversions_spec.rb
index ffae2da086..019d3f3a38 100644
--- a/spec/lib/conversions_spec.rb
+++ b/spec/lib/conversions_spec.rb
@@ -1,6 +1,6 @@
describe 'Conversions' do
describe 'Distance::Miles::ToMetres' do
- context '.convert' do
+ describe '.convert' do
subject { Conversions::Distance::Miles::ToMetres }
specify "should multiply by 1609.344" do
@@ -16,7 +16,7 @@
end
describe 'Distance::Miles::ToMetres' do
- context '.convert' do
+ describe '.convert' do
context 'with precision of 0' do
subject { Conversions::Distance::Metres::ToMiles }
diff --git a/spec/lib/encryptor_spec.rb b/spec/lib/encryptor_spec.rb
index c9e5ad9b50..cd2a6d0ade 100644
--- a/spec/lib/encryptor_spec.rb
+++ b/spec/lib/encryptor_spec.rb
@@ -17,10 +17,10 @@
end
describe ".decrypt_hash" do
- let(:encrypted_value) { described_class.encrypt(value) }
-
subject { described_class.decrypt(encrypted_value) }
+ let(:encrypted_value) { described_class.encrypt(value) }
+
it { is_expected.to eq(value) }
context "when nil" do
diff --git a/spec/lib/geocoder_autoexpire_cache_spec.rb b/spec/lib/geocoder_autoexpire_cache_spec.rb
index b2b5952c74..d8cb06f6c8 100644
--- a/spec/lib/geocoder_autoexpire_cache_spec.rb
+++ b/spec/lib/geocoder_autoexpire_cache_spec.rb
@@ -2,13 +2,13 @@
require Rails.root.join('lib', 'geocoder_autoexpire_cache')
describe GeocoderAutoexpireCache do
- let(:store) { ActiveSupport::Cache.lookup_store(:memory_store) }
subject { described_class.new(store) }
+ let(:store) { ActiveSupport::Cache.lookup_store(:memory_store) }
let(:key) { "some_key" }
let(:value) { "some_value" }
- it 'should correctly set the value' do
+ it 'correctlies set the value' do
subject[key] = value
expect(subject[key]).to eql(value)
end
@@ -16,11 +16,10 @@
context 'expiry defaults to 1 month' do
before do
allow(subject.store).to receive(:write).and_return(true)
+ subject[key] = value
end
- before { subject[key] = value }
-
- it 'should set the ttl of new records to a month in the future' do
+ it 'sets the ttl of new records to a month in the future' do
expect(subject.store).to have_received(:write).with(key, value, expires_in: 1.month)
end
end
@@ -28,7 +27,7 @@
context 'overriding the expiry' do
subject { described_class.new(store, 2.months) }
- it 'should set the ttl of new records to be the newly-specified value' do
+ it 'sets the ttl of new records to be the newly-specified value' do
expect(subject.ttl).to be_within(1).of(2.months)
end
end
diff --git a/spec/lib/geocoding_response_country_spec.rb b/spec/lib/geocoding_response_country_spec.rb
index 5070e9f725..a35ffb73ed 100644
--- a/spec/lib/geocoding_response_country_spec.rb
+++ b/spec/lib/geocoding_response_country_spec.rb
@@ -4,12 +4,12 @@
RSpec.describe GeocodingResponseCountry do
describe "#name" do
shared_examples "a known country" do |country|
- let(:response) { Geocoder::Result::Test.new(address_components: [long_name: country]) }
-
subject do
described_class.new(response).name
end
+ let(:response) { Geocoder::Result::Test.new(address_components: [long_name: country]) }
+
it "returns '#{country}'" do
expect(subject).to eq country
end
@@ -32,26 +32,26 @@
end
context "when unknown country" do
- let(:canada_response) { Geocoder::Result::Test.new(address_components: [long_name: "Canada"]) }
-
subject do
described_class.new(canada_response).name
end
+ let(:canada_response) { Geocoder::Result::Test.new(address_components: [long_name: "Canada"]) }
+
it "returns nil" do
- expect(subject).to be nil
+ expect(subject).to be_nil
end
end
end
describe "#not_serviced?" do
shared_examples "a country that is not serviced" do |country|
- let(:response) { Geocoder::Result::Test.new(address_components: [long_name: country]) }
-
subject do
described_class.new(response).not_serviced?
end
+ let(:response) { Geocoder::Result::Test.new(address_components: [long_name: country]) }
+
it "returns true" do
expect(subject).to be true
end
@@ -74,12 +74,12 @@
end
context "when England" do
- let(:response) { Geocoder::Result::Test.new(address_components: [long_name: "England"]) }
-
subject do
described_class.new(response).not_serviced?
end
+ let(:response) { Geocoder::Result::Test.new(address_components: [long_name: "England"]) }
+
it "returns false" do
expect(subject).to be false
end
diff --git a/spec/lib/notify/notify_sync_spec.rb b/spec/lib/notify/notify_sync_spec.rb
index e70ff6299b..1c1b4365a7 100644
--- a/spec/lib/notify/notify_sync_spec.rb
+++ b/spec/lib/notify/notify_sync_spec.rb
@@ -2,21 +2,18 @@
require Rails.root.join("lib", "notify", "notify_sync")
describe NotifySync do
+ subject do
+ described_class.new
+ end
+
before do
stub_const(
'NotifySync::API_KEY',
["somekey", SecureRandom.uuid, SecureRandom.uuid].join("-")
)
- end
-
- before do
allow(subject).to receive(:client).and_return(NotifyFakeClient.new)
end
- subject do
- described_class.new
- end
-
specify "template path should be app/notify/notify_email" do
expect(described_class::TEMPLATE_PATH).to eql(
[Rails.root, "app", "notify", "notify_email"]
@@ -29,24 +26,18 @@
let(:matching_template_name) { 'A story about a fox' }
before do
- allow(subject).to receive(:local_templates).and_return(
- matching_template_id => <<~TEMPLATE_ONE
- The quick brown fox jumped
- over the lazy dog
- TEMPLATE_ONE
- .chomp,
- )
-
- allow(subject).to receive(:remote_templates).and_return(
- matching_template_id => OpenStruct.new(
+ allow(subject).to receive_messages(local_templates: { matching_template_id => <<~TEMPLATE_ONE
+ The quick brown fox jumped
+ over the lazy dog
+ TEMPLATE_ONE
+ .chomp }, remote_templates: { matching_template_id => OpenStruct.new(
id: matching_template_id,
name: matching_template_name,
body: <<~TEMPLATE_ONE
The quick brown fox jumped
over the lazy dog
TEMPLATE_ONE
- )
- )
+ ) })
end
after { subject.compare }
@@ -66,14 +57,11 @@
let(:local_only_template_id) { 'aaaaaaaa-bbbb-cccc-dddd-222222222222' }
before do
- allow(subject).to receive(:local_templates).and_return(
- local_only_template_id => <<~TEMPLATE_TWO
- The quick brown fox jumped
- over the lazy dog
- TEMPLATE_TWO
- .chomp,
- )
- allow(subject).to receive(:remote_templates).and_return({})
+ allow(subject).to receive_messages(local_templates: { local_only_template_id => <<~TEMPLATE_TWO
+ The quick brown fox jumped
+ over the lazy dog
+ TEMPLATE_TWO
+ .chomp }, remote_templates: {})
end
after { subject.compare }
@@ -94,18 +82,14 @@
let(:remote_only_template_name) { 'A story about a fox' }
before do
- allow(subject).to receive(:local_templates).and_return({})
-
- allow(subject).to receive(:remote_templates).and_return(
- remote_only_template_id => OpenStruct.new(
- id: remote_only_template_id,
- name: remote_only_template_name,
- body: <<~TEMPLATE_THREE
- The quick brown fox jumped
- over the lazy dog
- TEMPLATE_THREE
- )
- )
+ allow(subject).to receive_messages(local_templates: {}, remote_templates: { remote_only_template_id => OpenStruct.new(
+ id: remote_only_template_id,
+ name: remote_only_template_name,
+ body: <<~TEMPLATE_THREE
+ The quick brown fox jumped
+ over the lazy dog
+ TEMPLATE_THREE
+ ) })
end
after { subject.compare }
@@ -132,21 +116,15 @@
end
before do
- allow(subject).to receive(:local_templates).and_return(
- template_id => <<~TEMPLATE_FOUR
- The quick brown fox jumped
- over the lazy dog
- TEMPLATE_FOUR
- .chomp,
- )
-
- allow(subject).to receive(:remote_templates).and_return(
- template_id => OpenStruct.new(
+ allow(subject).to receive_messages(local_templates: { template_id => <<~TEMPLATE_FOUR
+ The quick brown fox jumped
+ over the lazy dog
+ TEMPLATE_FOUR
+ .chomp }, remote_templates: { template_id => OpenStruct.new(
id: template_id,
name: "My - Magic - Template",
body: remote_body
- )
- )
+ ) })
end
after { subject.pull }
diff --git a/spec/lib/placement_request_transfer_spec.rb b/spec/lib/placement_request_transfer_spec.rb
index 097c89f323..a1313986d4 100644
--- a/spec/lib/placement_request_transfer_spec.rb
+++ b/spec/lib/placement_request_transfer_spec.rb
@@ -8,10 +8,10 @@
let(:school_id) { school.id }
describe "#transfer!" do
- let(:instance) { described_class.new(placement_request_id, school_id) }
-
subject(:transfer) { instance.transfer! }
+ let(:instance) { described_class.new(placement_request_id, school_id) }
+
it { expect { transfer }.to change { placement_request.reload.school }.to(school) }
context "when the placement request has been viewed" do
diff --git a/spec/models/bookings/booking_spec.rb b/spec/models/bookings/booking_spec.rb
index 4768243231..52c31623b1 100644
--- a/spec/models/bookings/booking_spec.rb
+++ b/spec/models/bookings/booking_spec.rb
@@ -11,37 +11,37 @@
describe 'Columns' do
it do
- is_expected.to have_db_column(:bookings_subject_id)
+ expect(subject).to have_db_column(:bookings_subject_id)
.of_type(:integer)
.with_options(null: false)
end
it do
- is_expected.to have_db_column(:bookings_placement_request_id)
+ expect(subject).to have_db_column(:bookings_placement_request_id)
.of_type(:integer)
.with_options(null: false)
end
it do
- is_expected.to have_db_column(:bookings_school_id)
+ expect(subject).to have_db_column(:bookings_school_id)
.of_type(:integer)
.with_options(null: false)
end
it do
- is_expected.to have_db_column(:date)
+ expect(subject).to have_db_column(:date)
.of_type(:date)
.with_options(null: false)
end
it do
- is_expected.to have_db_column(:duration)
+ expect(subject).to have_db_column(:duration)
.of_type(:integer)
.with_options(default: 1, null: false)
end
it do
- is_expected.to have_db_column(:experience_type)
+ expect(subject).to have_db_column(:experience_type)
.of_type(:string)
end
end
@@ -72,7 +72,7 @@
it { is_expected.to allow_value(false).for(:attended).on(:attendance) }
it { is_expected.not_to allow_value(nil).for(:attended).on(:attendance) }
- context '#date' do
+ describe '#date' do
it { is_expected.to validate_presence_of(:date) }
context 'new placement dates must not be in the past' do
@@ -95,27 +95,31 @@
end
context 'error messages' do
+ subject { invalid_pd.errors.full_messages }
+
let(:message) { 'Date must be in the future' }
let(:invalid_pd) { build(:bookings_placement_date, date: 3.weeks.ago).tap(&:valid?) }
- subject { invalid_pd.errors.full_messages }
specify 'should show a suitable error message' do
- is_expected.to include(message)
+ expect(subject).to include(message)
end
end
end
context 'updating placement date with same date' do
- let(:booking) { create(:bookings_booking) }
subject { booking.errors.to_hash }
+ let(:booking) { create(:bookings_booking) }
+
context 'defaults to being allowed' do
before { booking.valid? }
+
it { is_expected.to be_empty }
end
context 'is disallowed if updating_date is enabled' do
before { booking.valid?(:updating_date) }
+
it { is_expected.to be_any }
it { is_expected.to include(date: ["Date has not been changed"]) }
end
@@ -167,8 +171,9 @@
it { is_expected.to belong_to(:bookings_school) }
it { is_expected.to have_one(:candidate_cancellation).through(:bookings_placement_request) }
it { is_expected.to have_one(:school_cancellation).through(:bookings_placement_request) }
+
it do
- is_expected.to have_one(:candidate_feedback)
+ expect(subject).to have_one(:candidate_feedback)
.class_name("Candidates::BookingFeedback")
.with_foreign_key(:bookings_booking_id)
.inverse_of(:booking)
@@ -194,6 +199,8 @@
describe 'Scopes' do
describe '.cancelled' do
+ subject { described_class.cancelled }
+
let! :not_cancelled do
FactoryBot.create :bookings_booking
end
@@ -206,12 +213,12 @@
FactoryBot.create :bookings_booking, :cancelled_by_candidate
end
- subject { described_class.cancelled }
-
- it { is_expected.to match_array [booking_cancelled_by_school, booking_cancelled_by_candidate] }
+ it { is_expected.to contain_exactly(booking_cancelled_by_school, booking_cancelled_by_candidate) }
end
describe '.not_cancelled' do
+ subject { described_class.not_cancelled }
+
let! :not_cancelled do
FactoryBot.create :bookings_booking
end
@@ -224,12 +231,12 @@
FactoryBot.create :bookings_booking, :cancelled_by_candidate
end
- subject { described_class.not_cancelled }
-
- it { is_expected.to match_array [not_cancelled] }
+ it { is_expected.to contain_exactly(not_cancelled) }
end
describe '.previous' do
+ subject { described_class.previous.to_a }
+
let!(:previous_bookings) do
[
FactoryBot.build(:bookings_booking, date: 1.week.ago),
@@ -247,8 +254,6 @@
]
end
- subject { described_class.previous.to_a }
-
specify 'should include dates today or before' do
expect(subject).to match_array(previous_bookings)
end
@@ -259,6 +264,8 @@
end
describe '.future' do
+ subject { described_class.future }
+
let!(:previous_bookings) do
[
FactoryBot.build(:bookings_booking, date: 1.week.ago),
@@ -278,8 +285,6 @@
end
end
- subject { described_class.future }
-
specify 'should not include dates before today' do
expect(subject).not_to include(*previous_bookings)
end
@@ -312,14 +317,14 @@
end
describe '.with_unviewed_candidate_cancellation' do
+ subject { described_class.with_unviewed_candidate_cancellation }
+
let!(:new_booking) { create :bookings_booking }
let!(:with_viewed_candidate_cancellation) { create :bookings_booking, :with_viewed_candidate_cancellation }
let!(:with_unviewed_candidate_cancellation) { create :bookings_booking, :cancelled_by_candidate }
let!(:with_unviewed_school_cancellation) { create :bookings_booking, :cancelled_by_school }
- subject { described_class.with_unviewed_candidate_cancellation }
-
- it { is_expected.to match_array [with_unviewed_candidate_cancellation] }
+ it { is_expected.to contain_exactly(with_unviewed_candidate_cancellation) }
end
describe '.historical' do
@@ -332,11 +337,13 @@
let!(:previous_accepted) do
create(:bookings_booking, :previous, :accepted)
end
+
it { is_expected.to include(previous_accepted) }
end
context 'which have not been accepted' do
let!(:previous_unaccepted) { create(:bookings_booking, :previous) }
+
it { is_expected.not_to include(previous_unaccepted) }
end
@@ -368,11 +375,13 @@
context 'for future bookings' do
context 'which have been accepted' do
let!(:future_accepted) { create(:bookings_booking, :accepted) }
+
it { is_expected.not_to include(future_accepted) }
end
context 'which have not been accepted' do
let!(:future_unaccepted) { create(:bookings_booking) }
+
it { is_expected.not_to include(future_unaccepted) }
end
@@ -404,6 +413,7 @@
describe '.tomorrow' do
after { described_class.for_tomorrow }
+
specify 'should call .days_in_the_future with 1 days' do
expect(described_class).to receive(:for_days_in_the_future).with(1.day)
end
@@ -411,6 +421,7 @@
describe '.one_week_from_now' do
after { described_class.for_one_week_from_now }
+
specify 'should call .days_in_the_future with 7 days' do
expect(described_class).to receive(:for_days_in_the_future).with(7.days)
end
@@ -420,12 +431,12 @@
describe '#placement_start_date_with_duration' do
context 'when the placement request has a flexible date' do
+ subject { described_class.new date: date }
+
let! :date do
Time.zone.today
end
- subject { described_class.new date: date }
-
specify 'should return the date formatted to GOV.UK style' do
expect(subject.placement_start_date_with_duration).to eq \
date.to_formatted_s(:govuk)
@@ -433,6 +444,8 @@
end
context 'when the placement request has a fixed date' do
+ subject { described_class.new(date: date, duration: 2, bookings_placement_request: placement_request) }
+
let! :date do
Time.zone.today
end
@@ -440,8 +453,6 @@
let(:placement_date) { create(:bookings_placement_date) }
let(:placement_request) { create(:placement_request, placement_date: placement_date) }
- subject { described_class.new(date: date, duration: 2, bookings_placement_request: placement_request) }
-
specify 'should return a the date formatted to GOV.UK style with duration' do
expect(subject.placement_start_date_with_duration).to eq \
"#{date.to_formatted_s(:govuk)} for 2 days"
@@ -460,54 +471,64 @@
describe '#in_future?' do
context 'for upcoming booking' do
subject { build :bookings_booking }
+
it { is_expected.to be_in_future }
end
context 'for previous booking' do
subject { build :bookings_booking, :previous }
+
it { is_expected.not_to be_in_future }
end
end
- context '#cancellable?' do
+ describe '#cancellable?' do
context 'for uncancelled future booking' do
subject { create(:bookings_booking, :accepted) }
+
it { is_expected.to be_cancellable }
end
context 'for cancelled booking' do
subject { create(:bookings_booking, :cancelled_by_school) }
+
it { is_expected.not_to be_cancellable }
end
context 'for past booking' do
subject { create(:bookings_booking, :previous) }
+
it { is_expected.not_to be_cancellable }
end
end
- context '#cancellable?' do
+ describe '#cancellable?' do
context 'for uncancelled future booking' do
subject { create(:bookings_booking, :accepted) }
+
it { is_expected.to be_editable_date }
end
context 'for cancelled booking' do
subject { create(:bookings_booking, :cancelled_by_school) }
+
it { is_expected.not_to be_editable_date }
end
context 'for past booking' do
subject { create(:bookings_booking, :previous) }
+
it { is_expected.not_to be_editable_date }
end
end
describe '.from_placement_request' do
- specify { expect(described_class).to respond_to(:from_placement_request) }
- let(:placement_request) { create(:bookings_placement_request, placement_date: placement_date) }
subject { described_class.from_placement_request(placement_request) }
+ let(:placement_request) { create(:bookings_placement_request, placement_date: placement_date) }
+
+ specify { expect(described_class).to respond_to(:from_placement_request) }
+
context 'when experience type is vaguely specified' do
let(:placement_request) { create(:placement_request, experience_type: 'both') }
diff --git a/spec/models/bookings/candidate_spec.rb b/spec/models/bookings/candidate_spec.rb
index ec0a354978..63f0390336 100644
--- a/spec/models/bookings/candidate_spec.rb
+++ b/spec/models/bookings/candidate_spec.rb
@@ -21,12 +21,13 @@
it { is_expected.not_to allow_value('foobar').for :gitis_uuid }
it do
- is_expected.not_to \
+ expect(subject).not_to \
allow_value(SecureRandom.uuid + SecureRandom.uuid).for :gitis_uuid
end
context 'with existing record' do
before { create(:candidate) }
+
it { is_expected.to validate_uniqueness_of(:gitis_uuid).case_insensitive }
end
end
@@ -46,16 +47,16 @@
describe '.confirmed' do
subject { described_class.confirmed.to_a }
- it "will only include confirmed" do
- is_expected.to eql([confirmed])
+ it "onlies include confirmed" do
+ expect(subject).to eql([confirmed])
end
end
describe '.unconfirmed' do
subject { described_class.unconfirmed.to_a }
- it "will only include unconfirmed" do
- is_expected.to eql([unconfirmed])
+ it "onlies include unconfirmed" do
+ expect(subject).to eql([unconfirmed])
end
end
end
@@ -65,20 +66,22 @@
let(:gitis_contact) { build(:api_schools_experience_sign_up_with_name) }
context 'with existing Candidate' do
+ subject { described_class.find_by_gitis_contact gitis_contact }
+
let!(:candidate) { create(:candidate, gitis_uuid: gitis_contact.candidate_id) }
- subject { Bookings::Candidate.find_by_gitis_contact gitis_contact }
it "return existing candidate" do
- is_expected.to eql candidate
+ expect(subject).to eql candidate
end
- it "will assign gitis_contact" do
- is_expected.to have_attributes(gitis_contact: gitis_contact)
+ it "assigns gitis_contact" do
+ expect(subject).to have_attributes(gitis_contact: gitis_contact)
end
end
context 'without existing Candidate' do
- subject { Bookings::Candidate.find_by_gitis_contact gitis_contact }
+ subject { described_class.find_by_gitis_contact gitis_contact }
+
it { is_expected.to be_nil }
end
end
@@ -87,67 +90,68 @@
let(:gitis_contact) { build(:api_schools_experience_sign_up_with_name) }
context 'with existing Candidate' do
+ subject { described_class.find_by_gitis_contact! gitis_contact }
+
let!(:candidate) { create(:candidate, gitis_uuid: gitis_contact.candidate_id) }
- subject { Bookings::Candidate.find_by_gitis_contact! gitis_contact }
it "return existing candidate" do
- is_expected.to eql candidate
+ expect(subject).to eql candidate
end
- it "will assign gitis_contact" do
- is_expected.to have_attributes(gitis_contact: gitis_contact)
+ it "assigns gitis_contact" do
+ expect(subject).to have_attributes(gitis_contact: gitis_contact)
end
end
context 'without existing Candidate' do
it "raise record not found" do
expect {
- Bookings::Candidate.find_by_gitis_contact! gitis_contact
+ described_class.find_by_gitis_contact! gitis_contact
}.to raise_exception(ActiveRecord::RecordNotFound)
end
end
end
describe '.find_or_create_from_gitis_contact!' do
- let(:gitis_contact) { build(:api_schools_experience_sign_up_with_name) }
-
subject do
- Bookings::Candidate.find_or_create_from_gitis_contact! gitis_contact
+ described_class.find_or_create_from_gitis_contact! gitis_contact
end
+ let(:gitis_contact) { build(:api_schools_experience_sign_up_with_name) }
+
context 'with existing' do
let!(:candidate) { create(:candidate, gitis_uuid: gitis_contact.candidate_id) }
it "return existing candidate" do
- is_expected.to eql candidate
+ expect(subject).to eql candidate
end
- it "will assign gitis_contact" do
- is_expected.to have_attributes(gitis_contact: gitis_contact)
+ it "assigns gitis_contact" do
+ expect(subject).to have_attributes(gitis_contact: gitis_contact)
end
end
context 'without existing' do
- it "will create candidate" do
- is_expected.to be_kind_of Bookings::Candidate
- is_expected.to be_persisted
+ it "creates candidate" do
+ expect(subject).to be_a described_class
+ expect(subject).to be_persisted
end
- it "will assign gitis_contact" do
- is_expected.to have_attributes(gitis_contact: gitis_contact)
+ it "assigns gitis_contact" do
+ expect(subject).to have_attributes(gitis_contact: gitis_contact)
end
end
end
describe '.create_from_registration_session!' do
- include_context "api latest privacy policy"
-
- let(:registration) { build(:registration_session, :with_school) }
-
subject do
described_class.create_from_registration_session! registration
end
+ include_context "api latest privacy policy"
+
+ let(:registration) { build(:registration_session, :with_school) }
+
before do
allow_any_instance_of(GetIntoTeachingApiClient::SchoolsExperienceApi).to \
receive(:sign_up_schools_experience_candidate) do |_, sign_up|
@@ -156,12 +160,12 @@
end
end
- it { is_expected.to be_kind_of Bookings::Candidate }
+ it { is_expected.to be_a described_class }
it { is_expected.to be_persisted }
it { is_expected.to have_attributes(gitis_uuid: subject.gitis_contact.candidate_id) }
it { is_expected.to have_attributes(gitis_contact: instance_of(GetIntoTeachingApiClient::SchoolsExperienceSignUp)) }
- it "will assign contact attributes" do
+ it "assigns contact attributes" do
expect(subject.gitis_contact).to have_attributes \
first_name: registration.personal_information.first_name,
last_name: registration.personal_information.last_name
@@ -172,94 +176,94 @@
let(:registration_session) { build(:registration_session, :with_school) }
context 'with an existing contact and existing candidate' do
- let(:candidate) { create(:candidate, :with_api_contact) }
- let(:contact) { candidate.gitis_contact }
-
subject do
- Bookings::Candidate.create_or_update_from_registration_session! \
+ described_class.create_or_update_from_registration_session! \
registration_session, contact
end
- it "will return the existing candidate" do
- is_expected.to eql candidate
+ let(:candidate) { create(:candidate, :with_api_contact) }
+ let(:contact) { candidate.gitis_contact }
+
+ it "returns the existing candidate" do
+ expect(subject).to eql candidate
end
- it "will update the contacts details" do
+ it "updates the contacts details" do
expect(subject.gitis_contact).to have_attributes \
first_name: registration_session.personal_information.first_name,
last_name: registration_session.personal_information.last_name
end
- it "will mark as already existing in gitis" do
- is_expected.to have_attributes(created_in_gitis: false)
+ it "marks as already existing in gitis" do
+ expect(subject).to have_attributes(created_in_gitis: false)
end
end
context 'with an existing contact but not candidate' do
- let(:contact) { build(:api_schools_experience_sign_up_with_name) }
-
subject do
- Bookings::Candidate.create_or_update_from_registration_session! \
+ described_class.create_or_update_from_registration_session! \
registration_session, contact
end
- it "will create a Candidate" do
- is_expected.to be_kind_of Bookings::Candidate
- is_expected.to be_persisted
+ let(:contact) { build(:api_schools_experience_sign_up_with_name) }
+
+ it "creates a Candidate" do
+ expect(subject).to be_a described_class
+ expect(subject).to be_persisted
end
- it "will update the contacts details" do
+ it "updates the contacts details" do
expect(subject.gitis_contact).to have_attributes \
first_name: registration_session.personal_information.first_name,
last_name: registration_session.personal_information.last_name
end
- it "will mark as already existing in gitis" do
- is_expected.to have_attributes(created_in_gitis: false)
+ it "marks as already existing in gitis" do
+ expect(subject).to have_attributes(created_in_gitis: false)
end
end
context 'with no contact or candidate' do
- let(:contact_id) { SecureRandom.uuid }
-
subject do
- Bookings::Candidate.create_or_update_from_registration_session! \
+ described_class.create_or_update_from_registration_session! \
registration_session, nil
end
- it "will create a Candidate" do
- is_expected.to be_kind_of Bookings::Candidate
- is_expected.to be_persisted
+ let(:contact_id) { SecureRandom.uuid }
+
+ it "creates a Candidate" do
+ expect(subject).to be_a described_class
+ expect(subject).to be_persisted
end
- it "will create the Contacts with registration details" do
+ it "creates the Contacts with registration details" do
expect(subject.gitis_contact).to have_attributes \
first_name: registration_session.personal_information.first_name,
last_name: registration_session.personal_information.last_name
end
- it "will mark as newly created in gitis" do
- is_expected.to have_attributes(created_in_gitis: true)
+ it "marks as newly created in gitis" do
+ expect(subject).to have_attributes(created_in_gitis: true)
end
end
end
describe '#update_from_registration_session!' do
+ subject do
+ candidate.update_from_registration_session! registration
+ end
+
include_context "api latest privacy policy"
include_context "api sign up"
let(:registration) { build(:registration_session, :with_school) }
let(:candidate) { build(:candidate, :with_api_contact) }
- subject do
- candidate.update_from_registration_session! registration
- end
-
- it { is_expected.to be_kind_of Bookings::Candidate }
+ it { is_expected.to be_a described_class }
it { is_expected.to have_attributes(gitis_uuid: subject.gitis_contact.candidate_id) }
it { is_expected.to have_attributes(gitis_contact: instance_of(GetIntoTeachingApiClient::SchoolsExperienceSignUp)) }
- it "will assign contact attributes" do
+ it "assigns contact attributes" do
expect(subject.gitis_contact).to have_attributes \
first_name: registration.personal_information.first_name,
last_name: registration.personal_information.last_name
@@ -267,16 +271,19 @@
end
describe '#assign_gitis_contact' do
+ subject { candidate.reload }
+
let(:contact) { build(:api_schools_experience_sign_up_with_name) }
let(:candidate) { create(:candidate) }
let(:candidate_uuid) { candidate.gitis_uuid }
+
before { candidate.assign_gitis_contact contact }
- subject { candidate.reload }
- it 'should update the gitis contact' do
+ it 'updates the gitis contact' do
expect(candidate).to have_attributes gitis_contact: contact
end
- it 'should not update the gitis UUID' do
+
+ it 'does not update the gitis UUID' do
expect(candidate).to have_attributes gitis_uuid: candidate_uuid
end
end
@@ -284,9 +291,9 @@
describe '#generate_session_token!' do
let(:candidate) { create(:candidate) }
- it "should create a new token" do
- expect(candidate.generate_session_token!).to be_kind_of(Candidates::SessionToken)
- expect(candidate.session_tokens.count).to eql(1)
+ it "creates a new token" do
+ expect(candidate.generate_session_token!).to be_a(Candidates::SessionToken)
+ expect(candidate.session_tokens.count).to be(1)
end
end
@@ -298,15 +305,15 @@
before { first.candidate.expire_session_tokens! }
- it 'will invalidate other login tokens from same candidate' do
+ it 'invalidates other login tokens from same candidate' do
expect(second.reload.expired?).to be true
end
- it 'will not expire already expired tokens' do
+ it 'does not expire already expired tokens' do
expect(third.reload.expired_at).to be < 3.minutes.ago
end
- it "will not expire other candidates tokens" do
+ it "does not expire other candidates tokens" do
expect(another.reload.expired?).to be false
end
end
@@ -319,7 +326,7 @@
end
context 'for confirmed candidate' do
- it "will return last confirmed token timestamp" do
+ it "returns last confirmed token timestamp" do
expect(first.candidate.last_signed_in_at.to_i).to eql(second.confirmed_at.to_i)
end
end
@@ -327,7 +334,7 @@
context 'for subsequently deconfirmed candidate' do
before { first.candidate.update!(confirmed_at: nil) }
- it "will return last confirmed token timestamp" do
+ it "returns last confirmed token timestamp" do
expect(first.candidate.last_signed_in_at.to_i).to eql(second.confirmed_at.to_i)
end
end
@@ -335,10 +342,11 @@
describe "contact accessor attributes" do
subject { build :candidate, :with_api_contact }
- it "will be delegated to gitis contact" do
+
+ it "is delegated to gitis contact" do
full_name = "#{subject.gitis_contact.first_name} #{subject.gitis_contact.last_name}"
- is_expected.to have_attributes \
+ expect(subject).to have_attributes \
full_name: full_name,
email: subject.gitis_contact.email
end
diff --git a/spec/models/bookings/data/gias_data_file_spec.rb b/spec/models/bookings/data/gias_data_file_spec.rb
index b4b93c90fb..d6e487dff2 100644
--- a/spec/models/bookings/data/gias_data_file_spec.rb
+++ b/spec/models/bookings/data/gias_data_file_spec.rb
@@ -4,67 +4,66 @@
let(:today) { Time.zone.today.strftime('%Y%m%d') }
describe '#path' do
- before { allow(subject).to receive(:valid_file?).and_return true }
- before { allow(subject).to receive(:already_downloaded?).and_return false }
- before { allow(subject).to receive(:remove_old_files!).and_return true }
- before { allow(subject).to receive(:remove_todays_file!).and_return true }
- before { allow(subject).to receive(:download_and_save) { subject.todays_file } }
- before { allow(subject).to receive(:create_temp_dir).and_return true }
+ before do
+ allow(subject).to receive(:download_and_save) { subject.todays_file }
+ allow(subject).to receive_messages(valid_file?: true, already_downloaded?: false, remove_old_files!: true, remove_todays_file!: true, create_temp_dir: true)
+ end
context 'with existing file' do
before { allow(subject).to receive(:already_downloaded?).and_return true }
+
let!(:path) { subject.path }
- it "will return path of todays file" do
+ it "returns path of todays file" do
expect(path).to eql \
Rails.root.join('tmp', 'gias', "edubase-#{today}.csv")
end
- it "will return existing file" do
- is_expected.not_to have_received(:download_and_save)
+ it "returns existing file" do
+ expect(subject).not_to have_received(:download_and_save)
end
- it "will clean up old csv files" do
- is_expected.to have_received(:remove_old_files!)
+ it "cleans up old csv files" do
+ expect(subject).to have_received(:remove_old_files!)
end
- it "will create temp dir" do
- is_expected.not_to have_received(:create_temp_dir)
+ it "creates temp dir" do
+ expect(subject).not_to have_received(:create_temp_dir)
end
end
context 'without existing file' do
let!(:path) { subject.path }
- it "will return path of todays file" do
+ it "returns path of todays file" do
expect(path).to eql \
Rails.root.join('tmp', 'gias', "edubase-#{today}.csv")
end
- it "will download a new file" do
- is_expected.to have_received(:download_and_save)
+ it "downloads a new file" do
+ expect(subject).to have_received(:download_and_save)
end
- it "will clean up old csv files" do
- is_expected.to have_received(:remove_old_files!)
+ it "cleans up old csv files" do
+ expect(subject).to have_received(:remove_old_files!)
end
- it "will create temp dir" do
- is_expected.to have_received(:create_temp_dir)
+ it "creates temp dir" do
+ expect(subject).to have_received(:create_temp_dir)
end
end
context 'with invalid source file' do
before { allow(subject).to receive(:valid_file?).and_return false }
- it "will raise an exception and remove file" do
+ it "raises an exception and remove file" do
expect { subject.path }.to raise_exception described_class::InvalidSourceUri
- is_expected.to have_received(:remove_todays_file!)
+ expect(subject).to have_received(:remove_todays_file!)
end
end
end
- context '#remove_old_files' do
+ describe '#remove_old_files' do
let(:yesterday) { Time.zone.yesterday.strftime('%Y%m%d') }
let(:today) { Time.zone.today.strftime('%Y%m%d') }
let(:tomorrow) { Time.zone.tomorrow.strftime('%Y%m%d') }
@@ -80,12 +79,12 @@
subject.remove_old_files!
end
- it "will remove yesterdays" do
+ it "removes yesterdays" do
expect(File).to have_received(:unlink).with \
described_class::TEMP_PATH.join("edubase-#{yesterday}.csv").to_s
end
- it "will remove tomorrows" do
+ it "removes tomorrows" do
expect(File).to have_received(:unlink).with \
described_class::TEMP_PATH.join("edubase-#{tomorrow}.csv").to_s
end
@@ -96,7 +95,7 @@
end
end
- context '#remove_todays_file!' do
+ describe '#remove_todays_file!' do
let(:yesterday) { Time.zone.yesterday.strftime('%Y%m%d') }
let(:today) { Time.zone.today.strftime('%Y%m%d') }
@@ -110,7 +109,7 @@
described_class::TEMP_PATH.join("edubase-#{yesterday}.csv")
end
- it "will remove todays" do
+ it "removes todays" do
expect(File).to have_received(:unlink).with \
described_class::TEMP_PATH.join("edubase-#{today}.csv")
end
@@ -118,6 +117,7 @@
context 'valid_file?' do
let(:tempfile) { Tempfile.new }
+
before { allow(subject).to receive(:todays_file).and_return tempfile.path }
context 'with empty file' do
@@ -125,14 +125,20 @@
end
context 'with header only' do
- before { tempfile.write "#{described_class::EXPECTED_HEADER}\n" }
- before { tempfile.flush }
+ before do
+ tempfile.write "#{described_class::EXPECTED_HEADER}\n"
+ tempfile.flush
+ end
+
it { is_expected.to have_attributes valid_file?: false }
end
context 'with header and body' do
- before { tempfile.write "#{described_class::EXPECTED_HEADER}\n10000,\n" }
- before { tempfile.flush }
+ before do
+ tempfile.write "#{described_class::EXPECTED_HEADER}\n10000,\n"
+ tempfile.flush
+ end
+
it { is_expected.to have_attributes valid_file?: true }
end
end
diff --git a/spec/models/bookings/data/gias_reconciler_spec.rb b/spec/models/bookings/data/gias_reconciler_spec.rb
index 7d9ccfdd49..aaa53eb651 100644
--- a/spec/models/bookings/data/gias_reconciler_spec.rb
+++ b/spec/models/bookings/data/gias_reconciler_spec.rb
@@ -11,6 +11,8 @@
end
describe "#identify_onboarded_closed" do
+ subject { instance.identify_onboarded_closed }
+
let(:onboarded_school) { create(:bookings_school, :onboarded) }
let(:onboarded_disabled_school) { create(:bookings_school, :onboarded, :disabled) }
let(:school_1) { create(:bookings_school) }
@@ -25,12 +27,12 @@
CSV
end
- subject { instance.identify_onboarded_closed }
-
it { is_expected.to contain_exactly(onboarded_school, onboarded_disabled_school) }
end
describe "#find_reopened_urns" do
+ subject { instance.find_reopened_urns([closed_school_1.urn]) }
+
let(:closed_school_1) { create(:bookings_school) }
let(:closed_school_2) { create(:bookings_school) }
let(:closed_school_3) { create(:bookings_school) }
@@ -47,8 +49,6 @@
CSV
end
- subject { instance.find_reopened_urns([closed_school_1.urn]) }
-
it { is_expected.to eq({ closed_school_1.urn => [reopened_school_1.urn, reopened_school_2.urn] }) }
end
end
diff --git a/spec/models/bookings/data/school_manager_spec.rb b/spec/models/bookings/data/school_manager_spec.rb
index 175064afbd..e94aef8593 100644
--- a/spec/models/bookings/data/school_manager_spec.rb
+++ b/spec/models/bookings/data/school_manager_spec.rb
@@ -2,6 +2,8 @@
require 'csv'
describe Bookings::Data::SchoolManager do
+ subject { described_class.new(parsed_csv) }
+
let(:urns) do
[100_111, 100_112, 100_113]
end
@@ -17,8 +19,6 @@
CSV.parse(raw_csv, headers: true)
end
- subject { described_class.new(parsed_csv) }
-
before do
allow(Rails.logger).to receive(:info).and_return(true)
end
diff --git a/spec/models/bookings/data/school_mass_importer_spec.rb b/spec/models/bookings/data/school_mass_importer_spec.rb
index a392886d1b..53b253f92a 100644
--- a/spec/models/bookings/data/school_mass_importer_spec.rb
+++ b/spec/models/bookings/data/school_mass_importer_spec.rb
@@ -16,7 +16,7 @@
end
context 'EduBase Data' do
- subject { Bookings::Data::SchoolMassImporter.new([], edubase_data).edubase_data }
+ subject { described_class.new([], edubase_data).edubase_data }
specify 'should convert to a hash' do
expect(subject).to be_a(Hash)
@@ -32,6 +32,8 @@
end
context 'Importing' do
+ subject { described_class.new(edubase_data) }
+
let!(:count_before) { Bookings::School.count }
let(:school_type_id) { 2 }
@@ -47,12 +49,9 @@
create(:bookings_phase, name: name, edubase_id: i)
end
create(:bookings_school_type, edubase_id: school_type_id)
+ subject.import
end
- subject { Bookings::Data::SchoolMassImporter.new(edubase_data) }
-
- before { subject.import }
-
specify 'it should import the correct number of rows' do
expect(Bookings::School.count).to eql(count_before + edubase_data.size)
end
@@ -113,17 +112,18 @@
specify 'the new records should have coordinates' do
# we're relying on Breasal to do the maths, so just check
# they're populated
- Bookings::School.all.each do |school|
+ Bookings::School.all.find_each do |school|
expect(school.coordinates).to be_present
end
end
context 'Overriding email addresses' do
+ subject { described_class.new(edubase_data, email_override) }
+
let(:email_override) { "someone@someschool.org" }
- subject { Bookings::Data::SchoolMassImporter.new(edubase_data, email_override) }
specify "all emails should be set to the override email address" do
- Bookings::School.all.each do |school|
+ Bookings::School.all.find_each do |school|
expect(school.contact_email).to eql(email_override)
end
end
diff --git a/spec/models/bookings/phase_spec.rb b/spec/models/bookings/phase_spec.rb
index 03f99e19c1..33b877b59a 100644
--- a/spec/models/bookings/phase_spec.rb
+++ b/spec/models/bookings/phase_spec.rb
@@ -8,8 +8,9 @@
describe "Validation" do
context "Name" do
it { is_expected.to validate_presence_of(:name) }
+
it do
- is_expected.to validate_length_of(:name)
+ expect(subject).to validate_length_of(:name)
.is_at_least(2)
.is_at_most(32)
end
@@ -22,7 +23,7 @@
describe "Relationsips" do
specify do
- is_expected.to(
+ expect(subject).to(
have_many(:bookings_schools_phases)
.class_name("Bookings::SchoolsPhase")
.with_foreign_key(:bookings_phase_id)
@@ -31,7 +32,7 @@
end
specify do
- is_expected.to(
+ expect(subject).to(
have_many(:schools)
.through(:bookings_schools_phases)
.class_name("Bookings::School")
diff --git a/spec/models/bookings/placement_date_spec.rb b/spec/models/bookings/placement_date_spec.rb
index 5d6aacfaad..f06c5669cf 100644
--- a/spec/models/bookings/placement_date_spec.rb
+++ b/spec/models/bookings/placement_date_spec.rb
@@ -25,12 +25,12 @@
describe 'Validation' do
subject { described_class.new }
- context "#recurring" do
+ describe "#recurring" do
it { is_expected.to allow_values(true, false).for :recurring }
it { is_expected.not_to allow_value(nil).for :recurring }
end
- context '#date' do
+ describe '#date' do
it { expect(subject).to validate_presence_of(:date) }
context 'new placement dates must not be in the past' do
@@ -52,19 +52,21 @@
end
context 'error messages' do
+ subject { invalid_pd.errors.full_messages }
+
let(:message) { 'Date must be in the future' }
let(:invalid_pd) { build(:bookings_placement_date, date: 3.weeks.ago) }
before { invalid_pd.valid? }
- subject { invalid_pd.errors.full_messages }
specify 'should show a suitable error message' do
- is_expected.to include(message)
+ expect(subject).to include(message)
end
end
context 'updating expired placement dates' do
let(:expired_pd) { build(:bookings_placement_date, :active, :in_the_past) }
+
before do
expired_pd.bookings_school = school
expired_pd.save(validate: false)
@@ -72,7 +74,7 @@
specify 'should allow updates' do
expect(expired_pd.update(active: false)).to be(true)
- expect(expired_pd).to_not be_active
+ expect(expired_pd).not_to be_active
end
end
@@ -92,19 +94,20 @@
end
end
- context '#bookings_school' do
+ describe '#bookings_school' do
it { expect(subject).to validate_presence_of(:bookings_school) }
end
- context '#max_bookings_count' do
+ describe '#max_bookings_count' do
before { subject.published_at = Time.zone.today }
+
it do
- is_expected.to \
+ expect(subject).to \
validate_numericality_of(:max_bookings_count).is_greater_than(0).allow_nil
end
end
- context '#subjects' do
+ describe '#subjects' do
context 'published' do
before { subject.published_at = Time.zone.today }
@@ -149,23 +152,23 @@
let(:past_date) { create(:bookings_placement_date, :in_the_past) }
let(:today_date) { create(:bookings_placement_date, :in_the_past, date: Time.zone.today) }
- context '.bookable_date' do
+ describe '.bookable_date' do
subject { described_class.bookable_date }
- it 'should include future dates' do
- is_expected.to include(future_date)
+ it 'includes future dates' do
+ expect(subject).to include(future_date)
end
- it 'should not include past dates' do
- is_expected.not_to include(past_date)
+ it 'does not include past dates' do
+ expect(subject).not_to include(past_date)
end
- it 'should include dates on today' do
- is_expected.not_to include(today_date)
+ it 'includes dates on today' do
+ expect(subject).not_to include(today_date)
end
end
- context '.in_date_order' do
+ describe '.in_date_order' do
let!(:later) { create(:bookings_placement_date, date: 2.weeks.from_now) }
let!(:early) { create(:bookings_placement_date, date: 1.week.from_now) }
let!(:latest) { create(:bookings_placement_date, date: 3.weeks.from_now) }
@@ -178,7 +181,7 @@
end
end
- context '.active' do
+ describe '.active' do
subject { date.active }
context "when active is false" do
@@ -194,59 +197,60 @@
end
end
- context ".inside_availability_window" do
+ describe ".inside_availability_window" do
subject { described_class.inside_availability_window }
it 'includes placements that have not yet closed' do
travel_to Date.new(2022, 1, 8)
- is_expected.to include(create(:bookings_placement_date, date: Date.new(2022, 1, 10), end_availability_offset: 1))
+ expect(subject).to include(create(:bookings_placement_date, date: Date.new(2022, 1, 10), end_availability_offset: 1))
end
it 'does not include placements that closed today' do
travel_to Date.new(2022, 1, 9)
- is_expected.to_not include(create(:bookings_placement_date, date: Date.new(2022, 1, 10), end_availability_offset: 1))
+ expect(subject).not_to include(create(:bookings_placement_date, date: Date.new(2022, 1, 10), end_availability_offset: 1))
end
it 'does not include placements closed to candidates in the past' do
travel_to Date.new(2022, 1, 10)
- is_expected.to_not include(create(:bookings_placement_date, date: Date.new(2022, 1, 20), end_availability_offset: 15))
+ expect(subject).not_to include(create(:bookings_placement_date, date: Date.new(2022, 1, 20), end_availability_offset: 15))
end
it 'includes placements that opened today' do
travel_to Date.new(2022, 1, 8)
- is_expected.to include(create(:bookings_placement_date, date: Date.new(2022, 1, 9), start_availability_offset: 1))
+ expect(subject).to include(create(:bookings_placement_date, date: Date.new(2022, 1, 9), start_availability_offset: 1))
end
it 'does not include placements that open tomorrow' do
travel_to Date.new(2022, 1, 8)
- is_expected.to_not include(create(:bookings_placement_date, date: Date.new(2022, 1, 10), start_availability_offset: 1))
+ expect(subject).not_to include(create(:bookings_placement_date, date: Date.new(2022, 1, 10), start_availability_offset: 1))
end
it 'includes placements that opened in the past' do
travel_to Date.new(2022, 1, 10)
- is_expected.to include(create(:bookings_placement_date, date: Date.new(2022, 1, 20), start_availability_offset: 20))
+ expect(subject).to include(create(:bookings_placement_date, date: Date.new(2022, 1, 20), start_availability_offset: 20))
end
end
- context '.available' do
+ describe '.available' do
after { described_class.available }
+
specify 'should combine the future, active, published, open_to_candidates, and in_date_order scopes' do
expect(described_class).to receive_message_chain(:published, :active, :bookable_date, :inside_availability_window, :in_date_order)
end
end
- context '.published' do
+ describe '.published' do
let!(:published) { create :bookings_placement_date }
let!(:un_publised) { create :bookings_placement_date, published_at: nil }
specify 'should return only the published placement_dates' do
- expect(described_class.published).to match_array [published]
+ expect(described_class.published).to contain_exactly(published)
end
end
end
@@ -255,14 +259,11 @@
let(:placement_date) { create(:bookings_placement_date, publishable: false) }
it "marks the date as publishable" do
- expect { placement_date.mark_as_publishable! }.to change { placement_date.publishable }.from(false).to(true)
+ expect { placement_date.mark_as_publishable! }.to change(placement_date, :publishable).from(false).to(true)
end
end
describe "#publish" do
- let(:recurrences) { [] }
- let(:date) { 3.weeks.from_now.next_occurring(:monday) }
-
subject(:published_placement_date) do
freeze_time
@@ -271,6 +272,9 @@
end
end
+ let(:recurrences) { [] }
+ let(:date) { 3.weeks.from_now.next_occurring(:monday) }
+
it { is_expected.to be_active }
it { is_expected.to be_publishable }
it { expect(published_placement_date.published_at.to_date).to eq(Date.today) }
@@ -287,6 +291,8 @@
end
describe "#recur" do
+ subject { placement_date.recur(Date.new(2022, 1, 3)) }
+
let(:placement_date) { create(:bookings_placement_date, bookings_school: school) }
before do
@@ -295,13 +301,11 @@
placement_date.save!
end
- subject { placement_date.recur(Date.new(2022, 1, 3)) }
-
it { is_expected.to have_attributes(placement_date.attributes.except("created_at", "updated_at", "id", "date")) }
it { is_expected.to have_attributes(date: Date.new(2022, 1, 3)) }
end
- context '#has_limited_availability?' do
+ describe '#has_limited_availability?' do
context 'when max_bookings_count' do
before { subject.max_bookings_count = 7 }
@@ -319,7 +323,7 @@
end
end
- context '#published?' do
+ describe '#published?' do
context 'when published_at is set' do
before { subject.published_at = DateTime.now }
diff --git a/spec/models/bookings/placement_date_subject_spec.rb b/spec/models/bookings/placement_date_subject_spec.rb
index 4220e17a8c..f88c4b7d5d 100644
--- a/spec/models/bookings/placement_date_subject_spec.rb
+++ b/spec/models/bookings/placement_date_subject_spec.rb
@@ -22,7 +22,7 @@
before { subject.bookings_placement_date = placement_date }
it do
- is_expected.to \
+ expect(subject).to \
validate_inclusion_of(:bookings_subject_id).in_array(school.subject_ids)
end
end
@@ -30,15 +30,16 @@
describe 'methods' do
describe '#date_and_subject_id' do
- let(:placement_date) { create(:bookings_placement_date) }
- let(:chosen_subject) { create(:bookings_subject) }
subject do
- Bookings::PlacementDateSubject.create(
+ described_class.create(
bookings_placement_date: placement_date,
bookings_subject: chosen_subject
)
end
+ let(:placement_date) { create(:bookings_placement_date) }
+ let(:chosen_subject) { create(:bookings_subject) }
+
specify 'should be the bookings_placement_date id and own id delimited by an underscore' do
expect(subject.date_and_subject_id).to eql("#{placement_date.id}_#{chosen_subject.id}")
end
diff --git a/spec/models/bookings/placement_request/cancellation_spec.rb b/spec/models/bookings/placement_request/cancellation_spec.rb
index e7526f734a..4c75871ba7 100644
--- a/spec/models/bookings/placement_request/cancellation_spec.rb
+++ b/spec/models/bookings/placement_request/cancellation_spec.rb
@@ -30,12 +30,12 @@
end
describe "rejection" do
+ subject { cancellation.errors.messages }
+
let(:cancellation) { build(:cancellation) }
before { cancellation.save(context: :rejection) }
- subject { cancellation.errors.messages }
-
it { is_expected.to include(base: ["Choose a reason for rejecting this candidate"]) }
context "when there are rejection categories specified" do
@@ -68,25 +68,27 @@
describe 'scopes' do
describe '#sent' do
- let!(:cancellation) { create :cancellation }
subject { described_class.sent.to_a }
+ let!(:cancellation) { create :cancellation }
+
it { is_expected.not_to include cancellation }
context 'when sent' do
before { cancellation.sent! }
+
it { is_expected.to include cancellation }
end
end
end
context 'when placement_request is already closed' do
+ subject { described_class.new placement_request: placement_request }
+
let :placement_request do
FactoryBot.create :placement_request, :cancelled
end
- subject { described_class.new placement_request: placement_request }
-
before do
subject.validate
end
@@ -96,7 +98,7 @@
end
end
- context '#sent!' do
+ describe '#sent!' do
subject { FactoryBot.create :cancellation }
before do
@@ -123,9 +125,10 @@
end
describe '#dates_requested' do
- let(:placement_request) { create(:placement_request, :cancelled_by_school) }
subject { placement_request.school_cancellation }
+ let(:placement_request) { create(:placement_request, :cancelled_by_school) }
+
context 'when the placement has been accepted' do
let!(:booking) { create(:bookings_booking, bookings_placement_request: placement_request) }
@@ -194,7 +197,7 @@
let(:cancellation) { build(:cancellation, fully_booked: true, duplicate: true, reason: nil) }
it "returns the translated strings" do
- is_expected.to contain_exactly(
+ expect(subject).to contain_exactly(
"The date you requested is fully booked.",
"This is a duplicate request."
)
@@ -207,7 +210,7 @@
end
it "returns the translated strings" do
- is_expected.to contain_exactly(
+ expect(subject).to contain_exactly(
"The date you requested is fully booked.",
"This is a duplicate request.",
"Other reason."
diff --git a/spec/models/bookings/placement_request_spec.rb b/spec/models/bookings/placement_request_spec.rb
index f8ade4d642..02ad21b945 100644
--- a/spec/models/bookings/placement_request_spec.rb
+++ b/spec/models/bookings/placement_request_spec.rb
@@ -3,9 +3,14 @@
describe Bookings::PlacementRequest, type: :model do
include ActiveSupport::Testing::TimeHelpers
- include_context 'Stubbed candidates school'
subject { described_class.new bookings_school_id: school.id }
+ include_context 'Stubbed candidates school'
+
+ let! :today do
+ Time.zone.today
+ end
+
it { is_expected.to have_db_column(:objectives).of_type(:text).with_options null: false }
it { is_expected.to have_db_column(:urn).of_type(:integer).with_options null: false }
it { is_expected.to have_db_column(:degree_stage).of_type(:string).with_options null: false }
@@ -35,22 +40,26 @@
context 'with legacy record' do
subject { create(:placement_request) }
- before { subject.update_columns(candidate_id: nil) }
- before { subject.reload }
+
+ before do
+ subject.update_columns(candidate_id: nil)
+ subject.reload
+ end
+
it { is_expected.to be_valid }
end
end
context 'relationships' do
it do
- is_expected.to \
+ expect(subject).to \
have_one(:candidate_cancellation)
.dependent(:destroy)
.class_name('Bookings::PlacementRequest::Cancellation')
end
it do
- is_expected.to \
+ expect(subject).to \
have_one(:school_cancellation)
.dependent(:destroy)
.class_name('Bookings::PlacementRequest::Cancellation')
@@ -61,7 +70,7 @@
it { is_expected.to belong_to(:placement_date).class_name('Bookings::PlacementDate').with_foreign_key(:bookings_placement_date_id).optional }
it do
- is_expected.to belong_to(:candidate).class_name('Bookings::Candidate')\
+ expect(subject).to belong_to(:candidate).class_name('Bookings::Candidate')\
.with_foreign_key(:candidate_id).without_validating_presence
end
end
@@ -105,82 +114,71 @@
.bookings_placement_request
end
- context '.unprocessed' do
+ describe '.unprocessed' do
subject { described_class.unprocessed }
+
it do
- is_expected.to match_array [
- placement_request_open,
- placement_request_cancelled_by_school_but_not_sent,
- booked_but_not_accepted_placement_request
- ]
+ expect(subject).to contain_exactly(placement_request_open, placement_request_cancelled_by_school_but_not_sent, booked_but_not_accepted_placement_request)
end
end
- context '.unbooked' do
+ describe '.unbooked' do
subject { described_class.unbooked }
+
it do
- is_expected.to match_array [
- placement_request_open,
- placement_request_cancelled_by_school_but_not_sent,
- placement_request_closed_by_candidate,
- placement_request_closed_by_school,
- booked_but_not_accepted_placement_request
- ]
+ expect(subject).to contain_exactly(placement_request_open, placement_request_cancelled_by_school_but_not_sent, placement_request_closed_by_candidate, placement_request_closed_by_school, booked_but_not_accepted_placement_request)
end
end
- context '.cancelled' do
+ describe '.cancelled' do
subject { described_class.cancelled }
+
it do
- is_expected.to match_array [
- placement_request_closed_by_candidate,
- placement_request_closed_by_school,
- booked_then_cancelled_by_candidate
- ]
+ expect(subject).to contain_exactly(placement_request_closed_by_candidate, placement_request_closed_by_school, booked_then_cancelled_by_candidate)
end
end
- context '.not_cancelled' do
+ describe '.not_cancelled' do
subject { described_class.not_cancelled }
+
it do
- is_expected.to match_array [
- placement_request_open,
- placement_request_cancelled_by_school_but_not_sent,
- booked_placement_request,
- booked_but_not_accepted_placement_request
- ]
+ expect(subject).to contain_exactly(placement_request_open, placement_request_cancelled_by_school_but_not_sent, booked_placement_request, booked_but_not_accepted_placement_request)
end
end
- context '.withdrawn' do
+ describe '.withdrawn' do
+ subject { described_class.withdrawn }
+
let!(:unviewed) do
travel_to 2.minutes.from_now do
create :placement_request, :cancelled, school: school
end
end
- subject { described_class.withdrawn }
+
it { is_expected.to eq [unviewed, placement_request_closed_by_candidate] }
end
- context '.withdrawn_but_unviewed' do
+ describe '.withdrawn_but_unviewed' do
+ subject { described_class.withdrawn_but_unviewed }
+
let!(:withdrawn_and_viewed) do
create(:placement_request, :cancelled, school: school).tap do |pr|
pr.candidate_cancellation.viewed!
end
end
- subject { described_class.withdrawn_but_unviewed }
-
- it { is_expected.to match_array [placement_request_closed_by_candidate] }
+ it { is_expected.to contain_exactly(placement_request_closed_by_candidate) }
end
- context '.rejected' do
+ describe '.rejected' do
+ subject { described_class.rejected }
+
let!(:unviewed) do
travel_to 2.minutes.from_now do
create :placement_request, :cancelled_by_school, school: school
end
end
- subject { described_class.rejected }
+
it { is_expected.to eq [unviewed, placement_request_closed_by_school] }
end
end
@@ -215,7 +213,7 @@
create :placement_request, school: create(:bookings_school, :with_subjects)
end
- context '.requiring_attention' do
+ describe '.requiring_attention' do
subject { school.placement_requests.requiring_attention }
it { is_expected.to include request_pending_decision }
@@ -227,7 +225,7 @@
end
end
- context '.create_from_registration_session' do
+ describe '.create_from_registration_session' do
let(:candidate) { create(:candidate) }
context 'invalid session' do
@@ -251,19 +249,19 @@
end
context 'valid session' do
+ subject do
+ candidate.placement_requests.create_from_registration_session! \
+ registration_session
+ end
+
include_context 'Stubbed candidates school'
let :registration_session do
FactoryBot.build :registration_session
end
- subject do
- candidate.placement_requests.create_from_registration_session! \
- registration_session
- end
-
it 'creates the placement request' do
- expect { subject }.to change { described_class.count }.by 1
+ expect { subject }.to change(described_class, :count).by 1
end
it 'saves the experience type' do
@@ -442,13 +440,13 @@
it { is_expected.to validate_presence_of :degree_stage }
it do
- is_expected.to validate_inclusion_of(:degree_stage).in_array \
+ expect(subject).to validate_inclusion_of(:degree_stage).in_array \
described_class::OPTIONS_CONFIG.fetch 'DEGREE_STAGES'
end
context 'when degree stage is "Other"' do
before do
- allow(subject).to receive(:degree_stage) { "Other" }
+ allow(subject).to receive(:degree_stage).and_return("Other")
end
it { is_expected.to validate_presence_of :degree_stage_explaination }
@@ -462,47 +460,47 @@
context 'when degree stage is "I don\'t have a degree and am not studying for one"' do
before do
- allow(subject).to receive(:degree_stage) { "I don't have a degree and am not studying for one" }
+ allow(subject).to receive(:degree_stage).and_return("I don't have a degree and am not studying for one")
end
it do
- is_expected.to validate_absence_of(:degree_subject)
+ expect(subject).to validate_absence_of(:degree_subject)
end
end
context 'when degree stage is not "I don\'t have a degree and am not studying for one"' do
before do
- allow(subject).to receive(:degree_stage) { 'Final year' }
+ allow(subject).to receive(:degree_stage).and_return('Final year')
end
it do
- is_expected.to validate_presence_of(:degree_subject)
+ expect(subject).to validate_presence_of(:degree_subject)
end
end
it { is_expected.to validate_presence_of :teaching_stage }
it do
- is_expected.to validate_inclusion_of(:teaching_stage).in_array \
+ expect(subject).to validate_inclusion_of(:teaching_stage).in_array \
described_class::OPTIONS_CONFIG.fetch('TEACHING_STAGES')
end
it { is_expected.to validate_presence_of :subject_first_choice }
it do
- is_expected.to validate_inclusion_of(:subject_first_choice).in_array \
+ expect(subject).to validate_inclusion_of(:subject_first_choice).in_array \
allowed_subject_choices
end
it { is_expected.to validate_presence_of :subject_second_choice }
it do
- is_expected.to validate_inclusion_of(:subject_second_choice).in_array \
+ expect(subject).to validate_inclusion_of(:subject_second_choice).in_array \
second_subject_choices
end
end
- context '#available_subject_choices' do
+ describe '#available_subject_choices' do
context 'when the school has subjects' do
before do
school.subjects << FactoryBot.build_list(:bookings_subject, 8)
@@ -522,7 +520,7 @@
end
end
- context '#second_subject_choices' do
+ describe '#second_subject_choices' do
it "returns the list of subjects from it's school" do
choices = subject.second_subject_choices
no_choice = choices.shift
@@ -534,7 +532,7 @@
end
end
- context '#requires_subject_for_degree_stage?' do
+ describe '#requires_subject_for_degree_stage?' do
let :result do
described_class.new.requires_subject_for_degree_stage? stage
end
@@ -560,24 +558,19 @@
end
end
- let! :today do
- Time.zone.today
- end
-
context 'validations for placement preferences' do
- before :each do
+ before do
placement_request.validate
end
context 'when the school mandates fixed dates' do
before do
allow(placement_request).to receive(:school_offers_fixed_dates?).and_return(true)
+ placement_request.validate
end
let(:placement_request) { described_class.new(bookings_school_id: school.id) }
- before(:each) { placement_request.validate }
-
it 'adds an error to bookings_placement_date_id' do
expect(placement_request.errors[:bookings_placement_date_id]).to include \
"Choose a placement date"
@@ -609,7 +602,7 @@
end
context 'validations for availability preference' do
- before :each do
+ before do
placement_request.validate
end
@@ -620,6 +613,7 @@
context 'when the school allows flexible dates' do
let(:placement_request) { described_class.new(bookings_school_id: school.id) }
+
context 'when availability is not present' do
it 'adds an error to availability' do
expect(placement_request.errors[:availability]).to eq \
@@ -641,7 +635,7 @@
end
end
- context '#closed?' do
+ describe '#closed?' do
context 'when cancelled' do
context 'when cancelled by candidate' do
subject { FactoryBot.create :placement_request, :cancelled }
@@ -689,7 +683,7 @@
end
end
- context '#cancellation' do
+ describe '#cancellation' do
context 'when cancelled by candidate' do
subject { create(:placement_request, :cancelled) }
@@ -717,7 +711,7 @@
end
end
- context '#status' do
+ describe '#status' do
context 'default' do
subject { create(:placement_request).status }
@@ -774,6 +768,7 @@
context 'when candidate has attended previous school experiences' do
subject { create(:placement_request, :with_attended_booking).status }
+
it { is_expected.to eq 'Flagged' }
end
@@ -814,7 +809,7 @@
end
end
- context '#dbs' do
+ describe '#dbs' do
context 'when has_dbs_check' do
subject { FactoryBot.create :placement_request, has_dbs_check: true }
@@ -840,18 +835,20 @@
end
end
- context '#under_consideration?' do
+ describe '#under_consideration?' do
context 'when under_consideration_at has a date' do
+ subject { under_consideration_placement_request.under_consideration_at? }
+
let(:under_consideration_placement_request) { create(:placement_request, :under_consideration) }
- subject { under_consideration_placement_request.under_consideration_at? }
it { is_expected.to be(true) }
end
context 'when under_consideration_at is null' do
+ subject { placement_request.under_consideration_at? }
+
let(:placement_request) { create(:placement_request) }
- subject { placement_request.under_consideration_at? }
it { is_expected.to be(false) }
end
end
@@ -861,16 +858,19 @@
context 'when #viewed_at has not already been set' do
before { subject.viewed! }
+
specify 'should set #viewed_at to now' do
expect(subject.viewed_at).to be_within(0.1).of(Time.zone.now)
end
end
context 'when #viewed_at has already been set' do
- let(:ts) { 3.weeks.ago }
subject { FactoryBot.create(:placement_request, viewed_at: ts) }
+ let(:ts) { 3.weeks.ago }
+
before { subject.viewed! }
+
specify 'should not overwrite #viewed_at' do
expect(subject.viewed_at).to eql(ts)
end
@@ -879,10 +879,13 @@
describe '#requested_on' do
subject { create :placement_request }
+
it { is_expected.to have_attributes(requested_on: subject.created_at.to_date) }
end
describe '#requested_subject' do
+ subject { placement_request.requested_subject }
+
let :subject_1 do
create :bookings_subject
end
@@ -899,8 +902,6 @@
create :placement_request, school: school
end
- subject { placement_request.requested_subject }
-
context 'when for a non subject specific date' do
it { is_expected.to eq subject_1 }
end
@@ -917,37 +918,44 @@
context 'with fixed date' do
let(:pr) { build :placement_request, :with_a_fixed_date }
+
it { is_expected.to eql pr.placement_date.date }
end
context 'with flexible date' do
let(:pr) { build :placement_request }
+
it { is_expected.to be_nil }
end
end
describe '#fixed_date_is_bookable?' do
+ subject { pr.fixed_date_is_bookable? }
+
let(:pr) { build :placement_request, :with_a_fixed_date }
let(:date) { pr.placement_date }
- subject { pr.fixed_date_is_bookable? }
context 'for today' do
before { date.date = Time.zone.today }
+
it { is_expected.to be false }
end
context 'for yesterday' do
before { date.date = Time.zone.yesterday }
+
it { is_expected.to be false }
end
context 'for tomorrow' do
before { date.date = Time.zone.tomorrow }
+
it { is_expected.to be true }
end
context 'with flexible' do
let(:pr) { build(:placement_request) }
+
it { is_expected.to be false }
end
end
@@ -987,36 +995,40 @@
describe '#unclear_experience_type?' do
context 'when it is a flex date' do
context 'when experience is virtual' do
- let(:school) { build :bookings_school, :flex_virtual }
subject { build :placement_request, :virtual, school: school }
+ let(:school) { build :bookings_school, :flex_virtual }
+
it 'returns false' do
expect(subject.unclear_experience_type?).to be false
end
end
context 'when experience is in school' do
- let(:school) { build :bookings_school, :flex_inschool }
subject { build :placement_request, :inschool, school: school }
+ let(:school) { build :bookings_school, :flex_inschool }
+
it 'returns false' do
expect(subject.unclear_experience_type?).to be false
end
end
context 'when the experience is both' do
- let(:school) { build :bookings_school, :flex_both }
subject { build :placement_request, school: school }
+ let(:school) { build :bookings_school, :flex_both }
+
it 'returns true' do
expect(subject.unclear_experience_type?).to be true
end
end
context 'when the school and placement request experience types are different' do
- let(:school) { build :bookings_school, :flex_both }
subject { build :placement_request, :virtual, school: school }
+ let(:school) { build :bookings_school, :flex_both }
+
it 'returns true' do
expect(subject.unclear_experience_type?).to be true
end
diff --git a/spec/models/bookings/profile_attributes_convertor_spec.rb b/spec/models/bookings/profile_attributes_convertor_spec.rb
index 43cd058ab5..518954cb21 100644
--- a/spec/models/bookings/profile_attributes_convertor_spec.rb
+++ b/spec/models/bookings/profile_attributes_convertor_spec.rb
@@ -5,14 +5,14 @@
describe "#profile_attrs" do
context 'with completed profile' do
- let(:completed_attrs) do
- build(:school_profile, :completed).attributes
- end
-
subject do
described_class.new(completed_attrs).attributes
end
+ let(:completed_attrs) do
+ build(:school_profile, :completed).attributes
+ end
+
it { is_expected.to include(dbs_policy_conditions: 'required') }
it { is_expected.to include(dbs_policy_details: 'Must have recent dbs check') }
@@ -66,6 +66,10 @@
end
context 'with completed profile with blank fields' do
+ subject do
+ described_class.new(model_attrs).attributes
+ end
+
let(:model_attrs) do
model = build(:school_profile, :completed)
model.dbs_requirement_dbs_policy_conditions = 'notrequired'
@@ -98,10 +102,6 @@
model.attributes
end
- subject do
- described_class.new(model_attrs).attributes
- end
-
it { is_expected.to include(dbs_policy_conditions: 'notrequired') }
it { is_expected.to include(dbs_policy_details: nil) }
it { is_expected.to include(individual_requirements: 'None') }
@@ -141,13 +141,17 @@
end
describe '#phase_ids' do
- before { @early_years = create(:bookings_phase, :early_years) }
- before { @primary = create(:bookings_phase, :primary) }
- before { @secondary = create(:bookings_phase, :secondary) }
- before { @college = create(:bookings_phase, :college) }
- let(:attrs) { build(:school_profile, :completed).attributes }
subject { described_class.new(attrs).phase_ids }
+ before do
+ @early_years = create(:bookings_phase, :early_years)
+ @primary = create(:bookings_phase, :primary)
+ @secondary = create(:bookings_phase, :secondary)
+ @college = create(:bookings_phase, :college)
+ end
+
+ let(:attrs) { build(:school_profile, :completed).attributes }
+
it { is_expected.to include(@early_years.id) }
it { is_expected.to include(@primary.id) }
it { is_expected.to include(@secondary.id) }
diff --git a/spec/models/bookings/profile_publisher_spec.rb b/spec/models/bookings/profile_publisher_spec.rb
index 7e98fe9b6d..0edafa8c06 100644
--- a/spec/models/bookings/profile_publisher_spec.rb
+++ b/spec/models/bookings/profile_publisher_spec.rb
@@ -3,19 +3,19 @@
RSpec.describe Bookings::ProfilePublisher, type: :model do
describe "#new" do
context "with complete School Profile" do
- let(:completed_profile) { create(:school_profile, :completed) }
-
subject do
described_class.new(completed_profile.bookings_school.urn, completed_profile)
end
- it { is_expected.to be_kind_of described_class }
+ let(:completed_profile) { create(:school_profile, :completed) }
+
+ it { is_expected.to be_a described_class }
end
context "with partially complete School Profile" do
let(:incomplete_profile) { create(:school_profile) }
- it "will raise an exception" do
+ it "raises an exception" do
expect {
described_class.new(incomplete_profile.bookings_school.urn, incomplete_profile)
}.to raise_exception Bookings::ProfilePublisher::IncompleteSourceProfileError
@@ -35,28 +35,28 @@
context "for School without Profile" do
subject { described_class.new(school, school_profile).update! }
- it { is_expected.to be_kind_of Bookings::Profile }
+ it { is_expected.to be_a Bookings::Profile }
it { is_expected.to be_persisted }
it { is_expected.to be_valid }
it { is_expected.to have_attributes(primary_phase: true, secondary_phase: true) }
it { expect(subject.school.subject_ids.sort).to eql(school_profile.subject_ids.sort) }
- it { expect(subject.school.phase_ids.length).to eql(4) }
+ it { expect(subject.school.phase_ids.length).to be(4) }
end
context "for School with Profile" do
+ subject { described_class.new(school, school_profile).update! }
+
before do
@initial_profile = create(:bookings_profile, school: school)
end
- subject { described_class.new(school, school_profile).update! }
-
- it { is_expected.to be_kind_of Bookings::Profile }
+ it { is_expected.to be_a Bookings::Profile }
it { is_expected.to be_persisted }
it { is_expected.to be_valid }
it { is_expected.to eql @initial_profile }
it { is_expected.to have_attributes(primary_phase: true, secondary_phase: true) }
it { expect(subject.school.subject_ids.sort).to eql(school_profile.subject_ids.sort) }
- it { expect(subject.school.phase_ids.length).to eql(4) }
+ it { expect(subject.school.phase_ids.length).to be(4) }
end
end
end
diff --git a/spec/models/bookings/profile_spec.rb b/spec/models/bookings/profile_spec.rb
index 99d2702347..1a79f5be95 100644
--- a/spec/models/bookings/profile_spec.rb
+++ b/spec/models/bookings/profile_spec.rb
@@ -42,6 +42,7 @@
describe "validations" do
describe "bookings_school_id" do
before { create(:bookings_profile) }
+
it { is_expected.to validate_uniqueness_of :school_id }
end
@@ -57,16 +58,19 @@
describe "dbs_policy_details" do
context 'when dbs_policy_conditions is required' do
before { subject.dbs_policy_conditions = 'required' }
+
it { is_expected.to validate_presence_of :dbs_policy_details }
end
context 'when dbs_policy_conditions is inschool' do
before { subject.dbs_policy_conditions = 'inschool' }
+
it { is_expected.to validate_presence_of :dbs_policy_details }
end
context 'when dbs_policy_conditions is notrequired' do
before { subject.dbs_policy_conditions = 'notrequired' }
+
it { is_expected.not_to validate_presence_of :dbs_policy_details }
end
end
@@ -117,16 +121,19 @@
context 'with key_stage_early_years' do
before { subject.key_stage_early_years = true }
+
it { expect(subject.valid?).to be true }
end
context 'with key_stage_1' do
before { subject.key_stage_1 = true }
+
it { expect(subject.valid?).to be true }
end
context 'with key_stage_2' do
before { subject.key_stage_2 = true }
+
it { expect(subject.valid?).to be true }
end
@@ -135,6 +142,7 @@
subject.key_stage_early_years = true
subject.key_stage_1 = true
end
+
it { expect(subject.valid?).to be true }
end
end
@@ -146,6 +154,7 @@
secondary_phase: true,
key_stage_2: false)
end
+
it { expect(subject.valid?).to be true }
end
end
@@ -251,6 +260,7 @@
context 'with assigned teacher_training_info' do
subject { described_class.new(teacher_training_info: 'hello world') }
+
it { is_expected.to allow_value('').for(:teacher_training_url) }
it { is_expected.to allow_value('https://test.com').for(:teacher_training_url) }
it { is_expected.to allow_value('http://test.com').for(:teacher_training_url) }
@@ -297,6 +307,7 @@
describe "administration_fee_description" do
context "with amount_pounds set" do
subject { described_class.new(administration_fee_amount_pounds: 10.00) }
+
it { is_expected.to validate_presence_of :administration_fee_description }
end
@@ -308,6 +319,7 @@
describe "administration_fee_interval" do
context "with amount_pounds set" do
subject { described_class.new(administration_fee_amount_pounds: 10.00) }
+
described_class::AVAILABLE_INTERVALS.each do |interval|
it { is_expected.to allow_value(interval).for :administration_fee_interval }
end
@@ -322,6 +334,7 @@
describe "administration_fee_payment_method" do
context "with amount_pounds set" do
subject { described_class.new(administration_fee_amount_pounds: 10.00) }
+
it { is_expected.to validate_presence_of :administration_fee_payment_method }
end
@@ -340,6 +353,7 @@
describe "dbs_fee_description" do
context "with amount_pounds set" do
subject { described_class.new(dbs_fee_amount_pounds: 10.00) }
+
it { is_expected.to validate_presence_of :dbs_fee_description }
end
@@ -351,6 +365,7 @@
describe "dbs_fee_interval" do
context "with amount_pounds set" do
subject { described_class.new(dbs_fee_amount_pounds: 10.00) }
+
described_class::AVAILABLE_INTERVALS.each do |interval|
it { is_expected.to allow_value(interval).for :dbs_fee_interval }
end
@@ -365,6 +380,7 @@
describe "dbs_fee_payment_method" do
context "with amount_pounds set" do
subject { described_class.new(dbs_fee_amount_pounds: 10.00) }
+
it { is_expected.to validate_presence_of :dbs_fee_payment_method }
end
@@ -383,6 +399,7 @@
describe "other_fee_description" do
context "with amount_pounds set" do
subject { described_class.new(other_fee_amount_pounds: 10.00) }
+
it { is_expected.to validate_presence_of :other_fee_description }
end
@@ -394,6 +411,7 @@
describe "other_fee_interval" do
context "with amount_pounds set" do
subject { described_class.new(other_fee_amount_pounds: 10.00) }
+
described_class::AVAILABLE_INTERVALS.each do |interval|
it { is_expected.to allow_value(interval).for :other_fee_interval }
end
@@ -408,6 +426,7 @@
describe "other_fee_payment_method" do
context "with amount_pounds set" do
subject { described_class.new(other_fee_amount_pounds: 10.00) }
+
it { is_expected.to validate_presence_of :other_fee_payment_method }
end
@@ -427,11 +446,13 @@
context 'with has_access_needs_policy' do
before { subject.has_access_needs_policy = true }
+
it { is_expected.to validate_presence_of :access_needs_policy_url }
end
context 'without has_access_needs_policy' do
before { subject.has_access_needs_policy = false }
+
it { is_expected.not_to validate_presence_of :access_needs_policy_url }
end
end
diff --git a/spec/models/bookings/registration_contact_mapper_spec.rb b/spec/models/bookings/registration_contact_mapper_spec.rb
index 2ea5ee459e..e0e798d24e 100644
--- a/spec/models/bookings/registration_contact_mapper_spec.rb
+++ b/spec/models/bookings/registration_contact_mapper_spec.rb
@@ -2,15 +2,18 @@
RSpec.describe Bookings::RegistrationContactMapper do
describe ".new" do
+ subject { described_class.new(registration, contact) }
+
let(:registration) { build(:registration_session) }
let(:contact) { GetIntoTeachingApiClient::SchoolsExperienceSignUp.new }
- subject { described_class.new(registration, contact) }
it { is_expected.to have_attributes(registration_session: registration) }
it { is_expected.to have_attributes(gitis_contact: contact) }
end
describe "#registration_to_contact" do
+ subject { mapper.registration_to_contact }
+
include_context "api latest privacy policy"
include_context "api teaching subjects"
@@ -30,8 +33,6 @@
end
let(:mapper) { described_class.new(registration, contact) }
- subject { mapper.registration_to_contact }
-
it { is_expected.to have_attributes(first_name: registration.personal_information.first_name) }
it { is_expected.to have_attributes(last_name: registration.personal_information.last_name) }
it { is_expected.to have_attributes(email: registration.personal_information.email) }
@@ -59,10 +60,11 @@
end
describe "#contact_to_personal_information" do
+ subject { mapper.contact_to_personal_information }
+
let(:contact) { build(:api_schools_experience_sign_up_with_name) }
let(:registration) { build(:registration_session) }
let(:mapper) { described_class.new(registration, contact) }
- subject { mapper.contact_to_personal_information }
it { is_expected.to include("first_name" => contact.first_name) }
it { is_expected.to include("last_name" => contact.last_name) }
@@ -71,17 +73,18 @@
context 'with whitespace in email address' do
let(:contact) { build(:api_schools_experience_sign_up_with_name, email: " someone@education.gov.uk ") }
- it "will strip the whitespace" do
- is_expected.to include("email" => "someone@education.gov.uk")
+ it "strips the whitespace" do
+ expect(subject).to include("email" => "someone@education.gov.uk")
end
end
end
describe "#contact_to_contact_information" do
+ subject { mapper.contact_to_contact_information }
+
let(:contact) { build(:api_schools_experience_sign_up_with_name) }
let(:registration) { build(:registration_session) }
let(:mapper) { described_class.new(registration, contact) }
- subject { mapper.contact_to_contact_information }
it { is_expected.to include("phone" => contact.telephone) }
it { is_expected.to include("building" => contact.address_line1) }
@@ -92,6 +95,8 @@
end
describe "#contact_to_teaching_preference" do
+ subject { mapper.contact_to_teaching_preference }
+
include_context "api teaching subjects"
let(:maths) { Bookings::Subject.find_by!(name: 'Maths') }
@@ -111,7 +116,6 @@
end
let(:registration) { build(:registration_session) }
let(:mapper) { described_class.new(registration, contact) }
- subject { mapper.contact_to_teaching_preference }
it { is_expected.to include('subject_first_choice' => maths.name) }
it { is_expected.to include('subject_second_choice' => english.name) }
diff --git a/spec/models/bookings/school_search_spec.rb b/spec/models/bookings/school_search_spec.rb
index 93d8fb856e..4afe4cf9fa 100644
--- a/spec/models/bookings/school_search_spec.rb
+++ b/spec/models/bookings/school_search_spec.rb
@@ -16,27 +16,32 @@
describe 'Validation' do
subject { described_class.new({}) }
+
it { is_expected.to validate_length_of(:location).is_at_least(2) }
it { is_expected.not_to be_valid }
context 'with a query parameter' do
subject { described_class.new({ query: "Somewhere" }) }
+
it { is_expected.to be_valid }
end
context 'with a non-compliant UTF8 query string' do
# NB: non-compliant UTF8 query strings are handled elsewhere in the codebase
subject { described_class.new({ query: "Springfield\xa1" }) }
+
it { is_expected.to be_valid }
end
context 'with a location hash' do
subject { described_class.new({ location: { longitude: 1.1, latitude: 2.2 } }) }
+
it { is_expected.to be_valid }
end
context 'with a location string' do
subject { described_class.new({ location: "John o'Groats" }) }
+
it { is_expected.to be_valid }
end
end
@@ -46,12 +51,13 @@
context 'when Geocoder returns invalid results' do
let(:expected_error) { Bookings::SchoolSearch::InvalidGeocoderResultError }
+
before do
allow(Geocoder).to receive(:search).and_return('something bad')
end
specify 'an error should be raised' do
- expect { Bookings::SchoolSearch.new(query: '', location: 'France') }.to raise_error(expected_error)
+ expect { described_class.new(query: '', location: 'France') }.to raise_error(expected_error)
end
end
@@ -74,7 +80,7 @@
)
end
- after { Bookings::SchoolSearch.new(location: 'Mumbai') }
+ after { described_class.new(location: 'Mumbai') }
specify "should append the region to the Geocoder query" do
expect(Geocoder).to receive(:search)
@@ -114,18 +120,19 @@
end
context 'When no conditions are supplied' do
- subject { Bookings::SchoolSearch.new(query: '', location: '').results }
+ subject { described_class.new(query: '', location: '').results }
+
specify 'results should include no schools' do
expect(subject.count).to be_zero
end
end
context 'Only enabled schools should be returned' do
+ subject { described_class.new(location: 'Manchester').results }
+
let!(:enabled_school) { create(:bookings_school, :onboarded, coordinates: point_in_manchester) }
let!(:disabled_school) { create(:bookings_school, :disabled, coordinates: point_in_manchester) }
- subject { Bookings::SchoolSearch.new(location: 'Manchester').results }
-
specify 'should return enabled schools' do
expect(subject).to include(enabled_school)
end
@@ -140,7 +147,7 @@
context 'When text and latitude and longitude are supplied' do
subject do
- Bookings::SchoolSearch.new(query: 'Springfield', location: {
+ described_class.new(query: 'Springfield', location: {
latitude: coords.latitude, longitude: coords.longitude
}).results
end
@@ -156,7 +163,7 @@
context 'When only lat and lon are supplied' do
subject do
- Bookings::SchoolSearch.new(
+ described_class.new(
query: '',
location: { latitude: coords.latitude, longitude: coords.longitude }
).results
@@ -177,12 +184,12 @@
context 'When only latitude is supplied' do
subject do
- Bookings::SchoolSearch.new(query: '', location: {
+ described_class.new(query: '', location: {
latitude: coords.latitude
})
end
- it("should raise error") do
+ it("raises error") do
expect {
subject.results
}.to raise_exception(Bookings::SchoolSearch::InvalidCoordinatesError)
@@ -191,12 +198,12 @@
context 'When only longitude is supplied' do
subject do
- Bookings::SchoolSearch.new(query: '', location: {
+ described_class.new(query: '', location: {
longitude: coords.longitude
})
end
- it("should raise error") do
+ it("raises error") do
expect {
subject.results
}.to raise_exception(Bookings::SchoolSearch::InvalidCoordinatesError)
@@ -211,7 +218,7 @@
end
context 'When text and location are supplied' do
- subject { Bookings::SchoolSearch.new(query: 'Springfield', location: 'Manchester').results }
+ subject { described_class.new(query: 'Springfield', location: 'Manchester').results }
specify 'results should include matching records' do
expect(subject).to include(matching_school)
@@ -223,7 +230,7 @@
end
context 'When only a location is supplied' do
- subject { Bookings::SchoolSearch.new(query: '', location: 'Manchester').results }
+ subject { described_class.new(query: '', location: 'Manchester').results }
let!(:matching_school) do
create(:bookings_school, :onboarded, name: "Springfield Primary School")
@@ -241,12 +248,12 @@
context 'When Geocoder finds no location' do
context 'When the query does not match a school' do
+ subject { described_class.new(location: 'Chippewa, Michigan').results }
+
before do
allow(Geocoder).to receive(:search).and_return([])
end
- subject { Bookings::SchoolSearch.new(location: 'Chippewa, Michigan').results }
-
specify 'results should include all schools' do
expect(subject.size).to be_zero
end
@@ -255,12 +262,12 @@
context 'When Geocoder returns an invalid location' do
context 'When the query matches a school' do
+ subject { described_class.new(location: 'Madrid') }
+
before do
allow(Geocoder).to receive(:search).and_return("ABC123")
end
- subject { Bookings::SchoolSearch.new(location: 'Madrid') }
-
specify 'should fail with a InvalidGeocoderResultError' do
expect { subject.results }.to raise_error(Bookings::SchoolSearch::InvalidGeocoderResultError)
end
@@ -281,13 +288,13 @@
let!(:dbs_notrequired) { create(:bookings_profile, dbs_policy_conditions: 'notrequired') }
context 'Filtering on subjects' do
+ subject { described_class.new(query: '', location: coords_in_manchester, subjects: maths.id).results }
+
before do
matching_school.subjects << maths
non_matching_school.subjects << physics
end
- subject { Bookings::SchoolSearch.new(query: '', location: coords_in_manchester, subjects: maths.id).results }
-
specify 'should return matching results' do
expect(subject).to include(matching_school)
end
@@ -298,13 +305,13 @@
end
context 'Filtering on phases' do
+ subject { described_class.new(query: '', location: coords_in_manchester, phases: college.id).results }
+
before do
matching_school.phases << college
non_matching_school.phases << secondary
end
- subject { Bookings::SchoolSearch.new(query: '', location: coords_in_manchester, phases: college.id).results }
-
specify 'should return matching results' do
expect(subject).to include(matching_school)
end
@@ -315,7 +322,7 @@
end
context 'Filtering on fees' do
- subject { Bookings::SchoolSearch.new(query: '', location: coords_in_manchester, max_fee: 20).results }
+ subject { described_class.new(query: '', location: coords_in_manchester, max_fee: 20).results }
specify 'should return matching results' do
expect(subject).to include(matching_school)
@@ -327,6 +334,8 @@
end
context 'Filtering on dbs' do
+ subject { described_class.new(query: '', location: coords_in_manchester, dbs_policies: [2]).results }
+
let!(:another_matching_school) do
create(
:bookings_school,
@@ -342,8 +351,6 @@
non_matching_school.profile = dbs_required
end
- subject { Bookings::SchoolSearch.new(query: '', location: coords_in_manchester, dbs_policies: [2]).results }
-
specify 'should return both schools requiring DBS for in school or not requiring DBS at all' do
expect(subject).to include(matching_school, another_matching_school)
end
@@ -354,12 +361,12 @@
end
context 'Filtering on disability confident' do
+ subject { described_class.new(query: '', location: coords_in_manchester, disability_confident: '1').results }
+
before do
create(:bookings_profile, :without_supports_access_needs, school: non_matching_school)
end
- subject { Bookings::SchoolSearch.new(query: '', location: coords_in_manchester, disability_confident: '1').results }
-
specify 'should return matching results' do
expect(subject).to include(matching_school)
end
@@ -370,7 +377,7 @@
end
context 'Filtering on parking' do
- subject { Bookings::SchoolSearch.new(query: '', location: coords_in_manchester, parking: '1').results }
+ subject { described_class.new(query: '', location: coords_in_manchester, parking: '1').results }
specify 'should return matching results' do
matching_school.profile.update(parking_provided: true)
@@ -385,20 +392,8 @@
end
context 'Chaining' do
- let(:secondary) { create(:bookings_phase, name: "Secondary") }
- let(:physics) { Bookings::Subject.find_by! name: "Physics" }
-
- before do
- allow(Geocoder).to receive(:search).and_return(geocoder_manchester_search_result)
- end
-
- before do
- matching_school.phases << secondary
- matching_school.subjects << physics
- end
-
subject do
- Bookings::SchoolSearch.new(
+ described_class.new(
query: 'Springf',
location: 'Cheetham Hill',
subjects: physics,
@@ -407,6 +402,15 @@
).results
end
+ let(:secondary) { create(:bookings_phase, name: "Secondary") }
+ let(:physics) { Bookings::Subject.find_by! name: "Physics" }
+
+ before do
+ allow(Geocoder).to receive(:search).and_return(geocoder_manchester_search_result)
+ matching_school.phases << secondary
+ matching_school.subjects << physics
+ end
+
specify 'should allow all search options and filters to work in conjunction' do
expect(subject).to include(matching_school)
end
@@ -415,6 +419,10 @@
context 'Ordering' do
context 'Geographic ordering' do
+ subject do
+ described_class.new(query: '', location: 'Cheetham Hill', radius: 500).results
+ end
+
let(:point_in_manchester) { Bookings::School::GEOFACTORY.point(-2.241, 53.481) }
let(:point_in_leeds) { Bookings::School::GEOFACTORY.point(-1.548, 53.794) }
let(:point_in_glasgow) { Bookings::School::GEOFACTORY.point(-4.219, 55.859) }
@@ -429,10 +437,6 @@
allow(Geocoder).to receive(:search).and_return(geocoder_manchester_search_result)
end
- subject do
- Bookings::SchoolSearch.new(query: '', location: 'Cheetham Hill', radius: 500).results
- end
-
specify 'schools should be ordered by distance, near to far' do
expect(subject.map(&:name)).to eql([mcr_school, leeds_school, york_school, glasgow_school].map(&:name))
end
@@ -445,7 +449,7 @@
let(:max_fee) { 20 }
after do
- Bookings::SchoolSearch.new(
+ described_class.new(
location: 'Bury',
phases: phases,
subjects: subjects,
@@ -595,15 +599,15 @@
end
specify 'total count should match the number of matching schools' do
- expect(Bookings::SchoolSearch.new(location: "Bury", radius: 50).total_count).to eql(matching_schools.length)
+ expect(described_class.new(location: "Bury", radius: 50).total_count).to eql(matching_schools.length)
end
context 'Saving results' do
+ subject { instance.tap(&:total_count) }
+
let(:location) { "Bury" }
let(:query) { nil }
- let(:instance) { Bookings::SchoolSearch.new(location: location, query: query, radius: 50) }
-
- subject { instance.tap(&:total_count) }
+ let(:instance) { described_class.new(location: location, query: query, radius: 50) }
specify 'should save the record' do
expect(subject).to be_persisted
@@ -630,12 +634,8 @@
end
context 'filtering' do
- let(:phases) { [1, 2, 3] }
- let(:subjects) { [2, 3, 4] }
- let(:max_fee) { 30 }
- let(:location) { "Birmingham" }
subject do
- Bookings::SchoolSearch.new(
+ described_class.new(
location: location,
phases: phases,
subjects: subjects,
@@ -643,6 +643,11 @@
)
end
+ let(:phases) { [1, 2, 3] }
+ let(:subjects) { [2, 3, 4] }
+ let(:max_fee) { 30 }
+ let(:location) { "Birmingham" }
+
specify 'should record all search parameters' do
expect(subject.phases).to eql(phases)
expect(subject.subjects).to eql(subjects)
@@ -654,7 +659,7 @@
end
describe "#country" do
- subject { Bookings::SchoolSearch.new(location: "Test") }
+ subject { described_class.new(location: "Test") }
let(:scotland_search_result) do
[
@@ -698,23 +703,26 @@
end
describe '#has_coordinates?' do
- subject { Bookings::SchoolSearch.new(location: "Bury") }
+ subject { described_class.new(location: "Bury") }
context 'when coordinates are present' do
before { allow(subject).to receive(:coordinates).and_return(point_in_leeds) }
+
it { is_expected.to have_coordinates }
end
context 'when coordinates are absent' do
before { allow(subject).to receive(:coordinates).and_return([]) }
+
it { is_expected.not_to have_coordinates }
end
end
context 'whitelisted_urns' do
+ subject { school_search }
+
let(:whitelist) { '1' }
let(:school_search) { described_class.new(location: "Bury", radius: 10) }
- subject { school_search }
before do
allow(ENV).to receive(:[]).and_call_original
@@ -726,10 +734,12 @@
it { is_expected.to have_attributes radius: 1000 }
context 'searching' do
+ subject { school_search.results.map(&:urn) }
+
let(:schools) { create_list :bookings_school, 3, :onboarded }
let(:school_urns) { schools.map(&:urn) }
let(:whitelist) { school_urns.slice(0, 2).join(' ') }
- subject { school_search.results.map(&:urn) }
+
it { is_expected.to include school_urns[0] }
it { is_expected.to include school_urns[1] }
it { is_expected.not_to include school_urns[2] }
@@ -737,6 +747,7 @@
context 'without whitelist' do
let(:whitelist) { '' }
+
it { is_expected.to have_attributes whitelisted_urns?: false }
it { is_expected.to have_attributes whitelisted_urns: [] }
it { is_expected.to have_attributes radius: 10 }
diff --git a/spec/models/bookings/school_spec.rb b/spec/models/bookings/school_spec.rb
index be2a27a388..b6db3829c7 100644
--- a/spec/models/bookings/school_spec.rb
+++ b/spec/models/bookings/school_spec.rb
@@ -26,6 +26,7 @@
context 'overwriting empty strings before validation' do
subject { create(:bookings_school) }
+
before do
subject.availability_info = ''
subject.valid?
@@ -47,18 +48,18 @@
"07865 432 321"
]
- subject { Bookings::School.new }
+ subject { described_class.new }
context field_name do
context 'valid' do
valid_urls.each do |valid_url|
- it { should allow_value(valid_url).for(field_name) }
+ it { is_expected.to allow_value(valid_url).for(field_name) }
end
end
context 'invalid' do
invalid_urls.each do |invalid_url|
- it { should_not allow_value(invalid_url).for(field_name) }
+ it { is_expected.not_to allow_value(invalid_url).for(field_name) }
end
end
end
@@ -82,13 +83,13 @@
context 'valid' do
valid_addresses.each do |valid_address|
- it { should allow_value(valid_address).for(:contact_email) }
+ it { is_expected.to allow_value(valid_address).for(:contact_email) }
end
end
context 'invalid' do
invalid_addresses.each do |invalid_address|
- it { should_not allow_value(invalid_address).for(:contact_email) }
+ it { is_expected.not_to allow_value(invalid_address).for(:contact_email) }
end
end
end
@@ -111,14 +112,14 @@
describe 'Relationships' do
it do
- is_expected.to(
+ expect(subject).to(
have_one(:school_profile)
.with_foreign_key(:bookings_school_id)
)
end
specify do
- is_expected.to(
+ expect(subject).to(
have_many(:bookings_schools_subjects)
.class_name("Bookings::SchoolsSubject")
.with_foreign_key(:bookings_school_id)
@@ -127,7 +128,7 @@
end
specify do
- is_expected.to(
+ expect(subject).to(
have_many(:subjects)
.through(:bookings_schools_subjects)
.class_name("Bookings::Subject")
@@ -136,7 +137,7 @@
end
specify do
- is_expected.to(
+ expect(subject).to(
have_many(:bookings_schools_phases)
.class_name("Bookings::SchoolsPhase")
.with_foreign_key(:bookings_school_id)
@@ -145,7 +146,7 @@
end
specify do
- is_expected.to(
+ expect(subject).to(
have_many(:phases)
.through(:bookings_schools_phases)
.class_name("Bookings::Phase")
@@ -154,7 +155,7 @@
end
specify do
- is_expected.to(
+ expect(subject).to(
belong_to(:school_type)
.with_foreign_key(:bookings_school_type_id)
.class_name("Bookings::SchoolType")
@@ -162,7 +163,7 @@
end
specify do
- is_expected.to(
+ expect(subject).to(
have_many(:bookings_placement_dates)
.with_foreign_key(:bookings_school_id)
.class_name('Bookings::PlacementDate')
@@ -171,7 +172,7 @@
end
specify do
- is_expected.to(
+ expect(subject).to(
have_many(:available_placement_dates)
.with_foreign_key(:bookings_school_id)
.class_name('Bookings::PlacementDate')
@@ -179,7 +180,7 @@
end
specify do
- is_expected.to(
+ expect(subject).to(
have_many(:bookings)
.with_foreign_key(:bookings_school_id)
.class_name('Bookings::Booking')
@@ -188,11 +189,11 @@
end
specify do
- is_expected.to have_one(:profile).class_name("Bookings::Profile")
+ expect(subject).to have_one(:profile).class_name("Bookings::Profile")
end
specify do
- is_expected.to \
+ expect(subject).to \
have_many(:placement_requests)
.with_foreign_key(:bookings_school_id)
.class_name('Bookings::PlacementRequest')
@@ -200,7 +201,7 @@
end
specify do
- is_expected.to \
+ expect(subject).to \
have_many(:events)
.with_foreign_key(:bookings_school_id)
.dependent(:destroy)
@@ -216,7 +217,7 @@
end
describe 'Scopes' do
- subject { Bookings::School }
+ subject { described_class }
context 'Full text searching on Name' do
# provided by FullTextSearch
@@ -428,6 +429,12 @@
end
context 'Availability and placement dates' do
+ let!(:active_date) { create(:bookings_placement_date, bookings_school: fixed_with_dates) }
+ let!(:inactive_date) { create(:bookings_placement_date, bookings_school: fixed_without_dates, active: false) }
+ let!(:fixed_with_dates) { create(:bookings_school, :with_fixed_availability_preference) }
+ let!(:fixed_without_dates) { create(:bookings_school, :with_fixed_availability_preference) }
+ let!(:flexible_with_description) { create(:bookings_school) }
+
specify { expect(described_class).to respond_to(:flexible) }
specify { expect(described_class).to respond_to(:flexible_with_description) }
specify { expect(described_class).to respond_to(:fixed) }
@@ -439,14 +446,7 @@
specify { expect(described_class.new).to have_db_column(:availability_preference_fixed).of_type(:boolean).with_options(default: false) }
specify { expect(described_class.new).to have_db_column(:experience_type).of_type(:string).with_options(null: false, default: :inschool) }
- let!(:flexible_with_description) { create(:bookings_school) }
- let!(:fixed_without_dates) { create(:bookings_school, :with_fixed_availability_preference) }
- let!(:fixed_with_dates) { create(:bookings_school, :with_fixed_availability_preference) }
-
- let!(:inactive_date) { create(:bookings_placement_date, bookings_school: fixed_without_dates, active: false) }
- let!(:active_date) { create(:bookings_placement_date, bookings_school: fixed_with_dates) }
-
- context '.flexible' do
+ describe '.flexible' do
subject { described_class.flexible }
specify 'should include schools that offer flexible dates' do
@@ -458,7 +458,7 @@
end
end
- context '.flexible_with_description' do
+ describe '.flexible_with_description' do
subject { described_class.flexible_with_description }
specify 'should include schools that offer flexible_dates with availability_description' do
@@ -471,7 +471,7 @@
end
end
- context '.fixed' do
+ describe '.fixed' do
subject { described_class.fixed }
specify 'should include schools that offer fixed dates' do
@@ -483,8 +483,9 @@
end
end
- context '.fixed_with_available_dates' do
+ describe '.fixed_with_available_dates' do
subject { described_class.fixed_with_available_dates }
+
specify 'should include schools that offer fixed dates and have available dates' do
expect(subject).to include(fixed_with_dates)
end
@@ -494,7 +495,7 @@
end
end
- context '.with_availability' do
+ describe '.with_availability' do
subject { described_class.with_availability }
specify 'should include schools that are either flexible or fixed with available dates' do
@@ -506,7 +507,7 @@
end
end
- context '.without_availability' do
+ describe '.without_availability' do
subject { described_class.without_availability }
it 'includes schools that are fixed without available dates' do
@@ -544,6 +545,7 @@
context 'when flexible' do
context 'with availability_info' do
subject { build(:bookings_school) }
+
it { is_expected.to have_availability }
end
end
@@ -551,16 +553,19 @@
context 'when fixed' do
context 'with no dates' do
subject { build(:bookings_school, :with_fixed_availability_preference) }
+
it { is_expected.not_to have_availability }
end
context 'with unavailable dates' do
subject { create(:bookings_school, :with_fixed_availability_preference, :with_unavailable_placement_dates) }
+
it { is_expected.not_to have_availability }
end
context 'with available dates' do
subject { create(:bookings_school, :with_fixed_availability_preference, :with_placement_dates) }
+
it { is_expected.to have_availability }
end
end
@@ -569,11 +574,13 @@
describe '#onboarded?' do
context 'without profile' do
subject { create(:bookings_school) }
+
it { is_expected.not_to be_onboarded }
end
context 'with profile' do
subject { create(:bookings_profile).school }
+
it { is_expected.to be_onboarded }
end
end
@@ -585,6 +592,7 @@
context 'when the school is enabled' do
subject { create(:bookings_school) }
+
before { subject.enable! }
specify 'the school should remain enabled' do
@@ -598,6 +606,7 @@
context 'when the school is disabled' do
subject { create(:bookings_school, :disabled) }
+
before { subject.enable! }
specify 'should enable the school' do
@@ -618,6 +627,7 @@
context 'when the school is disabled' do
subject { create(:bookings_school, :disabled) }
+
before { subject.disable! }
specify 'the school should remain disabled' do
@@ -631,6 +641,7 @@
context 'when the school is enabled' do
subject { create(:bookings_school) }
+
before { subject.disable! }
specify 'should disable the school' do
diff --git a/spec/models/bookings/school_sync_spec.rb b/spec/models/bookings/school_sync_spec.rb
index 2dce088aa2..5048cfd233 100644
--- a/spec/models/bookings/school_sync_spec.rb
+++ b/spec/models/bookings/school_sync_spec.rb
@@ -1,23 +1,22 @@
require 'rails_helper'
describe Bookings::SchoolSync do
- let(:email_override) { 'test@test.org' }
subject { described_class.new(email_override: email_override) }
+ let(:email_override) { 'test@test.org' }
+
specify { expect(subject.email_override).to eql(email_override) }
specify { expect(subject).to respond_to(:sync) }
context 'when syncing is disabled' do
before do
- allow(subject).to receive(:sync_disabled?).and_return(true)
- allow(subject).to receive(:import_and_update).and_return(true)
+ allow(subject).to receive_messages(sync_disabled?: true, import_and_update: true)
allow(Rails.logger).to receive(:warn).and_return(true)
+ subject.sync
end
let(:disabled_message) { 'GIAS sync attempted but disabled' }
- before { subject.sync }
-
specify 'calling sync should print a warning to the log' do
expect(Rails.logger).to have_received(:warn).with(disabled_message)
end
diff --git a/spec/models/bookings/school_type_spec.rb b/spec/models/bookings/school_type_spec.rb
index 63f727a09a..bb1d3eff65 100644
--- a/spec/models/bookings/school_type_spec.rb
+++ b/spec/models/bookings/school_type_spec.rb
@@ -10,7 +10,7 @@
describe 'Relationships' do
specify do
- is_expected.to have_many(:schools).with_foreign_key(:bookings_school_type_id)
+ expect(subject).to have_many(:schools).with_foreign_key(:bookings_school_type_id)
end
end
end
diff --git a/spec/models/bookings/schools_phase_spec.rb b/spec/models/bookings/schools_phase_spec.rb
index 505a004023..efa7802366 100644
--- a/spec/models/bookings/schools_phase_spec.rb
+++ b/spec/models/bookings/schools_phase_spec.rb
@@ -7,20 +7,20 @@
end
describe 'Validation' do
- context '#bookings_school' do
+ describe '#bookings_school' do
it { is_expected.to validate_presence_of(:bookings_school) }
end
- context '#bookings_school' do
+ describe '#bookings_school' do
it { is_expected.to validate_presence_of(:bookings_phase) }
end
- context '#bookings_phase_id' do
+ describe '#bookings_phase_id' do
context 'Uniqueness' do
subject { create(:bookings_schools_phase) }
it do
- is_expected.to(
+ expect(subject).to(
validate_uniqueness_of(:bookings_phase_id)
.scoped_to(:bookings_school_id)
)
diff --git a/spec/models/bookings/schools_subject_spec.rb b/spec/models/bookings/schools_subject_spec.rb
index 76edc0cdb9..7da40bfccb 100644
--- a/spec/models/bookings/schools_subject_spec.rb
+++ b/spec/models/bookings/schools_subject_spec.rb
@@ -7,18 +7,18 @@
end
describe 'Validation' do
- context '#bookings_school' do
+ describe '#bookings_school' do
it { is_expected.to validate_presence_of(:bookings_school) }
end
- context '#bookings_subject' do
+ describe '#bookings_subject' do
it { is_expected.to validate_presence_of(:bookings_subject) }
context 'Uniqueness' do
subject { create(:bookings_schools_subject) }
it do
- is_expected.to(
+ expect(subject).to(
validate_uniqueness_of(:bookings_subject_id)
.scoped_to(:bookings_school_id)
)
diff --git a/spec/models/bookings/subject_spec.rb b/spec/models/bookings/subject_spec.rb
index a188dc7a9b..e737bcfb70 100644
--- a/spec/models/bookings/subject_spec.rb
+++ b/spec/models/bookings/subject_spec.rb
@@ -4,14 +4,16 @@
describe "Validation" do
context "Name" do
it { is_expected.to validate_presence_of(:name) }
+
it do
- is_expected.to validate_length_of(:name)
+ expect(subject).to validate_length_of(:name)
.is_at_least(2)
.is_at_most(64)
end
context 'Uniqueness' do
subject { create(:bookings_subject) }
+
it { is_expected.to validate_uniqueness_of(:name) }
end
end
@@ -19,7 +21,7 @@
describe "Relationsips" do
specify do
- is_expected.to(
+ expect(subject).to(
have_many(:bookings_schools_subjects)
.class_name("Bookings::SchoolsSubject")
.with_foreign_key(:bookings_subject_id)
@@ -28,7 +30,7 @@
end
specify do
- is_expected.to(
+ expect(subject).to(
have_many(:schools)
.through(:bookings_schools_subjects)
.class_name("Bookings::School")
@@ -37,47 +39,47 @@
end
specify do
- is_expected.to have_many(:placement_date_subjects).dependent(:destroy)
+ expect(subject).to have_many(:placement_date_subjects).dependent(:destroy)
end
specify do
- is_expected.to have_many(:onboarding_profile_subjects).dependent(:destroy)
+ expect(subject).to have_many(:onboarding_profile_subjects).dependent(:destroy)
end
specify do
- is_expected.to have_many(:placement_requests)
+ expect(subject).to have_many(:placement_requests)
.with_foreign_key(:bookings_subject_id)
end
end
describe "Scopes" do
describe 'default_scope' do
+ subject { described_class.all.to_a }
+
let!(:visible) { create(:bookings_subject, hidden: false) }
let!(:hidden) { create(:bookings_subject, hidden: true) }
- subject { described_class.all.to_a }
-
- it 'should include non-hidden subjects' do
- is_expected.to include(visible)
+ it 'includes non-hidden subjects' do
+ expect(subject).to include(visible)
end
- it 'should not include hidden subjects' do
- is_expected.not_to include(hidden)
+ it 'does not include hidden subjects' do
+ expect(subject).not_to include(hidden)
end
end
describe '.secondary' do
+ subject { described_class.secondary_subjects.to_a }
+
let!(:secondary) { create(:bookings_subject, secondary_subject: true) }
let!(:primary) { create(:bookings_subject, secondary_subject: false) }
- subject { described_class.secondary_subjects.to_a }
-
- it 'should include secondary subjects' do
- is_expected.to include(secondary)
+ it 'includes secondary subjects' do
+ expect(subject).to include(secondary)
end
- it 'should not include non-secondary subjects' do
- is_expected.not_to include(primary)
+ it 'does not include non-secondary subjects' do
+ expect(subject).not_to include(primary)
end
end
end
diff --git a/spec/models/candidates/booking_feedback_spec.rb b/spec/models/candidates/booking_feedback_spec.rb
index 095e610d7f..7d1e848c6b 100644
--- a/spec/models/candidates/booking_feedback_spec.rb
+++ b/spec/models/candidates/booking_feedback_spec.rb
@@ -2,13 +2,13 @@
describe Candidates::BookingFeedback, type: :model do
it do
- is_expected.to belong_to(:booking)
+ expect(subject).to belong_to(:booking)
.class_name("Bookings::Booking")
.with_foreign_key("bookings_booking_id")
end
it do
- is_expected.to define_enum_for(:effect_on_decision)
+ expect(subject).to define_enum_for(:effect_on_decision)
.with_values(%i[negatively positively unaffected])
end
@@ -27,7 +27,7 @@
it do
subject.booking = create(:bookings_booking)
- is_expected.to validate_uniqueness_of(:bookings_booking_id)
+ expect(subject).to validate_uniqueness_of(:bookings_booking_id)
end
end
end
diff --git a/spec/models/candidates/school_search_spec.rb b/spec/models/candidates/school_search_spec.rb
index ee0c3ce43d..59bc2a5a3d 100644
--- a/spec/models/candidates/school_search_spec.rb
+++ b/spec/models/candidates/school_search_spec.rb
@@ -14,7 +14,7 @@
it { is_expected.to eq(%w[location]) }
end
- context '.new' do
+ describe '.new' do
subject do
described_class.new(
query: 'this',
@@ -54,11 +54,11 @@
it { expect(subject).to delegate_method(:parking_count).to(:school_search) }
end
- context '.subjects=' do
+ describe '.subjects=' do
context 'with blank strings' do
before { subject.subjects = [1, '', 3] }
- it 'should remove blank strings' do
+ it 'removes blank strings' do
expect(subject.subjects).to eq [1, 3]
end
end
@@ -66,7 +66,7 @@
context 'with nils' do
before { subject.subjects = [1, 3, nil] }
- it 'should remove nils' do
+ it 'removes nils' do
expect(subject.subjects).to eq [1, 3]
end
end
@@ -82,17 +82,17 @@
context 'with string values' do
before { subject.subjects = ['1', '2', 3] }
- it 'should convert to integers' do
+ it 'converts to integers' do
expect(subject.subjects).to eq [1, 2, 3]
end
end
end
- context '.phases=' do
+ describe '.phases=' do
context 'with blank strings' do
before { subject.phases = [1, '', 3] }
- it 'should remove blank strings' do
+ it 'removes blank strings' do
expect(subject.phases).to eq [1, 3]
end
end
@@ -100,7 +100,7 @@
context 'with nils' do
before { subject.phases = [1, 3, nil] }
- it 'should remove nils' do
+ it 'removes nils' do
expect(subject.phases).to eq [1, 3]
end
end
@@ -116,17 +116,17 @@
context 'with string values' do
before { subject.phases = ['1', '2', 3] }
- it 'should convert to integers' do
+ it 'converts to integers' do
expect(subject.phases).to eq [1, 2, 3]
end
end
end
- context '.dbs_policies=' do
+ describe '.dbs_policies=' do
context 'with blank strings' do
before { subject.dbs_policies = [1, '', 3] }
- it 'should remove blank strings' do
+ it 'removes blank strings' do
expect(subject.dbs_policies).to eq [1, 3]
end
end
@@ -134,7 +134,7 @@
context 'with nils' do
before { subject.dbs_policies = [1, 3, nil] }
- it 'should remove nils' do
+ it 'removes nils' do
expect(subject.dbs_policies).to eq [1, 3]
end
end
@@ -150,7 +150,7 @@
context 'with string values' do
before { subject.dbs_policies = ['1', '2', 3] }
- it 'should convert to integers' do
+ it 'converts to integers' do
expect(subject.dbs_policies).to eq [1, 2, 3]
end
end
@@ -160,7 +160,7 @@
context 'with known value' do
before { subject.max_fee = '30' }
- it('should be 30') do
+ it('is 30') do
expect(subject.max_fee).to eq '30'
end
end
@@ -168,7 +168,7 @@
context 'with known value as integer' do
before { subject.max_fee = 30 }
- it('should be 30') do
+ it('is 30') do
expect(subject.max_fee).to eq '30'
end
end
@@ -176,7 +176,7 @@
context 'with unknown value' do
before { subject.max_fee = '20000' }
- it('should be blank') do
+ it('is blank') do
expect(subject.max_fee).to eq ''
end
end
@@ -184,7 +184,7 @@
context 'with blank value' do
before { subject.max_fee = '' }
- it('should be blank') do
+ it('is blank') do
expect(subject.max_fee).to eq ''
end
end
@@ -192,57 +192,63 @@
context 'with nil value' do
before { subject.max_fee = nil }
- it('should be blank') do
+ it('is blank') do
expect(subject.max_fee).to eq ''
end
end
end
- context '.results' do
+ describe '.results' do
subject { described_class.new(query: 'Test School') }
it 'returns array of Schools' do
- expect(subject.results).to be_kind_of Enumerable
+ expect(subject.results).to be_a Enumerable
end
end
- context '.total_count' do
+ describe '.total_count' do
subject { described_class.new(query: 'Test School') }
it 'returns array of Schools' do
- expect(subject.total_count).to be_kind_of Integer
+ expect(subject.total_count).to be_a Integer
end
end
- context '.valid_search?' do
+ describe '.valid_search?' do
context 'with query' do
subject { described_class.new(query: 'Test School') }
- it('should be valid') { expect(subject.valid_search?).to be true }
+
+ it('is valid') { expect(subject.valid_search?).to be true }
end
context 'with only location' do
subject { described_class.new(location: 'Manchester', distance: '') }
- it('should be invalid') { expect(subject.valid_search?).to be false }
+
+ it('is invalid') { expect(subject.valid_search?).to be false }
end
context 'with only distance' do
subject { described_class.new(distance: '10') }
- it('should be invalid') { expect(subject.valid_search?).to be false }
+
+ it('is invalid') { expect(subject.valid_search?).to be false }
end
context 'with location and distance' do
subject { described_class.new(location: 'Manchester', distance: '10') }
- it('should be valid') { expect(subject.valid_search?).to be true }
+
+ it('is valid') { expect(subject.valid_search?).to be true }
end
context 'with latitude and distance' do
subject { described_class.new(latitude: '-2.241', distance: '10') }
- it('should be invalid') { expect(subject.valid_search?).to be false }
+
+ it('is invalid') { expect(subject.valid_search?).to be false }
end
context 'with longitude and distance' do
subject { described_class.new(longitude: '53.481', distance: '10') }
- it('should be invalid') { expect(subject.valid_search?).to be false }
+
+ it('is invalid') { expect(subject.valid_search?).to be false }
end
context 'with latitude, longitude and distance' do
@@ -252,7 +258,7 @@
)
end
- it('should be valid') { expect(subject.valid_search?).to be true }
+ it('is valid') { expect(subject.valid_search?).to be true }
end
context 'with query, location and distance' do
@@ -264,29 +270,31 @@
)
end
- it('should be valid') { expect(subject.valid_search?).to be true }
+ it('is valid') { expect(subject.valid_search?).to be true }
end
end
- context '.filtering_results' do
+ describe '.filtering_results' do
context 'for blank search' do
subject { described_class.new }
- it "will be false" do
- expect(subject.filtering_results?).to be_falsey
+ it "is false" do
+ expect(subject).not_to be_filtering_results
end
end
context 'for valid search' do
subject { described_class.new(query: "test") }
- it "will be true" do
- expect(subject.filtering_results?).to be_truthy
+ it "is true" do
+ expect(subject).to be_filtering_results
end
end
end
describe "#applied_filters" do
+ subject { instance.applied_filters }
+
let!(:subject_1) { create(:bookings_subject, name: "Subject 1") }
let!(:subject_2) { create(:bookings_subject, name: "Subject 2") }
let!(:phase_3) { create(:bookings_phase, :primary) }
@@ -302,10 +310,8 @@
)
end
- subject { instance.applied_filters }
-
it do
- is_expected.to eq({
+ expect(subject).to eq({
"Subjects" => {
subjects: [{ value: subject_1.id, text: "Subject 1" }, { value: subject_2.id, text: "Subject 2" }]
},
diff --git a/spec/models/candidates/school_spec.rb b/spec/models/candidates/school_spec.rb
index c4f46e4f68..0e16c6c651 100644
--- a/spec/models/candidates/school_spec.rb
+++ b/spec/models/candidates/school_spec.rb
@@ -1,17 +1,17 @@
require 'rails_helper'
describe Candidates::School do
- context '.find' do
+ describe '.find' do
before { @school = create(:bookings_school) }
context('with valid identifier') do
- it "will return school" do
+ it "returns school" do
expect(described_class.find(@school.to_param)).to eq(@school)
end
end
context('with invalid URN') do
- it "will raise ActiveRecord::RecordNotFound" do
+ it "raises ActiveRecord::RecordNotFound" do
expect {
described_class.find('abc123')
}.to raise_exception(ActiveRecord::RecordNotFound)
@@ -19,7 +19,7 @@
end
end
- context '.phases' do
+ describe '.phases' do
before do
@third = create(:bookings_phase, name: 'third', position: 3)
@first = create(:bookings_phase, name: 'first', position: 1)
@@ -28,7 +28,7 @@
@phases = described_class.phases
end
- it 'should return an array of Phases ordered by the age period' do
+ it 'returns an array of Phases ordered by the age period' do
expect(@phases).to eq([
[@first.id, @first.name],
[@second.id, @second.name],
@@ -37,7 +37,7 @@
end
end
- context '.subjects' do
+ describe '.subjects' do
before do
Bookings::Subject.destroy_all
@later = create(:bookings_subject, name: 'Later')
@@ -45,7 +45,7 @@
@subjects = described_class.subjects
end
- it "should return a alphabetical array of subjects" do
+ it "returns a alphabetical array of subjects" do
expect(@subjects).to eq([
[@earlier.id, @earlier.name],
[@later.id, @later.name]
diff --git a/spec/models/candidates/session_spec.rb b/spec/models/candidates/session_spec.rb
index 4294d6cc12..a1615ad629 100644
--- a/spec/models/candidates/session_spec.rb
+++ b/spec/models/candidates/session_spec.rb
@@ -20,6 +20,7 @@
describe 'validates' do
subject { described_class.new }
+
it { is_expected.to validate_presence_of(:email) }
it { is_expected.to validate_presence_of(:firstname) }
it { is_expected.to validate_presence_of(:lastname) }
@@ -37,8 +38,8 @@
it { expect(@candidate).to eql(token.candidate) }
- it "should clear out other tokens" do
- expect(token.candidate.session_tokens.valid.count).to eql(0)
+ it "clears out other tokens" do
+ expect(token.candidate.session_tokens.valid.count).to be(0)
end
end
@@ -47,8 +48,8 @@
it { expect(@candidate).to be_nil }
- it "should not remove tokens" do
- expect(Candidates::SessionToken.valid.count).to eql(2)
+ it "does not remove tokens" do
+ expect(Candidates::SessionToken.valid.count).to be(2)
end
end
end
diff --git a/spec/models/candidates/session_token_spec.rb b/spec/models/candidates/session_token_spec.rb
index b1370c274b..da8eec9ad8 100644
--- a/spec/models/candidates/session_token_spec.rb
+++ b/spec/models/candidates/session_token_spec.rb
@@ -20,46 +20,48 @@
describe '.unconfirmed' do
subject { described_class.unconfirmed.to_a }
- it "should only return confirmed token" do
- is_expected.to eq([unconfirmed])
+ it "onlies return confirmed token" do
+ expect(subject).to eq([unconfirmed])
end
end
describe '.confirmed' do
subject { described_class.confirmed.to_a }
- it "should only return confirmed token" do
- is_expected.to eq([confirmed])
+ it "onlies return confirmed token" do
+ expect(subject).to eq([confirmed])
end
end
end
describe '.unexpired' do
+ subject { described_class.unexpired.to_a }
+
let!(:valid) { create(:candidate_session_token) }
let!(:expired) { create(:candidate_session_token, :expired) }
- subject { described_class.unexpired.to_a }
-
- it "should only return the valid token" do
- is_expected.to eq([valid])
+ it "onlies return the valid token" do
+ expect(subject).to eq([valid])
end
end
describe '.valid' do
+ subject { described_class.valid.to_a }
+
let!(:valid) { create(:candidate_session_token) }
let!(:expired) { create(:candidate_session_token, :expired) }
let!(:first) { create(:candidate_session_token, created_at: 10.days.ago) }
- subject { described_class.valid.to_a }
-
- it "should only return the valid token" do
- is_expected.to eq([valid])
+ it "onlies return the valid token" do
+ expect(subject).to eq([valid])
end
end
describe '.create' do
- let(:candidate) { create(:candidate) }
subject { candidate.session_tokens.create }
+
+ let(:candidate) { create(:candidate) }
+
it { is_expected.to be_persisted }
it { is_expected.to have_attribute(:token) }
end
@@ -67,16 +69,19 @@
describe '#expired?' do
context 'with valid' do
subject { build(:candidate_session_token) }
+
it("is not expired") { is_expected.not_to be_expired }
end
context 'with flagged expired' do
subject { build(:candidate_session_token, :expired) }
+
it("is expired") { is_expected.to be_expired }
end
context 'with too old' do
subject { build(:candidate_session_token, :auto_expired) }
+
it("is expired") { is_expected.to be_expired }
end
end
@@ -84,18 +89,20 @@
describe '#expire!' do
context 'with already expired' do
let(:token) { build(:candidate_session_token, expired_at: 10.days.ago) }
+
before { token.expire! }
- it("will be expired now") do
+ it("is expired now") do
expect(token.expired_at).to be < 9.days.ago
end
end
context 'with unexpired' do
let(:token) { build(:candidate_session_token) }
+
before { token.expire! }
- it("will be expired now") do
+ it("is expired now") do
expect(token.expired_at).to be > 1.minute.ago
end
end
@@ -108,11 +115,11 @@
before { described_class.expire_all! }
- it 'will invalidate other login tokens from same candidate' do
+ it 'invalidates other login tokens from same candidate' do
expect(second.reload.expired?).to be true
end
- it 'will not expire already expired tokens' do
+ it 'does not expire already expired tokens' do
expect(third.reload.expired_at).to be < 3.minutes.ago
end
end
@@ -124,22 +131,22 @@
before { first.confirm! }
- it "will confirm current_token" do
+ it "confirms current_token" do
expect(first.reload).to be_confirmed
expect(first).not_to be_expired
end
- it "will expire other tokens for same candidate" do
+ it "expires other tokens for same candidate" do
expect(second.reload).to be_expired
expect(second).not_to be_confirmed
end
- it "will not affect other candidates tokens" do
+ it "does not affect other candidates tokens" do
expect(third.reload).not_to be_expired
expect(third.reload).not_to be_confirmed
end
- it "will confirm the candidate" do
+ it "confirms the candidate" do
expect(first.candidate.reload).to be_confirmed
end
end
diff --git a/spec/models/candidates/verification_code_spec.rb b/spec/models/candidates/verification_code_spec.rb
index 0ad9aafeea..c88fe85637 100644
--- a/spec/models/candidates/verification_code_spec.rb
+++ b/spec/models/candidates/verification_code_spec.rb
@@ -67,6 +67,8 @@
end
describe "#issue_verification_code" do
+ subject { instance.issue_verification_code }
+
let(:code) { nil }
let(:request) do
@@ -77,8 +79,6 @@
)
end
- subject { instance.issue_verification_code }
-
before do
allow_any_instance_of(GetIntoTeachingApiClient::CandidatesApi).to \
receive(:create_candidate_access_token).with(request)
diff --git a/spec/models/concerns/encrypted_attributes_spec.rb b/spec/models/concerns/encrypted_attributes_spec.rb
index 0d47f69d46..2111a01a55 100644
--- a/spec/models/concerns/encrypted_attributes_spec.rb
+++ b/spec/models/concerns/encrypted_attributes_spec.rb
@@ -22,7 +22,7 @@
subject { instance.encrypted_attributes }
it "encrypts attributes flagged for encryption" do
- is_expected.to include({
+ expect(subject).to include({
"name" => "EMLFEkHwBtL0",
"email" => "V0DuvAtJPsp4skoCYxU10S2nFDpC1pSLQF5kIwLhPRTXkFe5Hn4",
"height" => nil,
@@ -32,10 +32,10 @@
end
describe ".new_decrypt" do
- let(:encrypted_attributes) { instance.encrypted_attributes }
-
subject { test_model.new_decrypt(encrypted_attributes).attributes }
+ let(:encrypted_attributes) { instance.encrypted_attributes }
+
it { is_expected.to eq(instance.attributes) }
context "when passed permitted ActionController::Parameters" do
diff --git a/spec/models/concerns/geographic_search_spec.rb b/spec/models/concerns/geographic_search_spec.rb
index 949b4ff66e..ad85e0db51 100644
--- a/spec/models/concerns/geographic_search_spec.rb
+++ b/spec/models/concerns/geographic_search_spec.rb
@@ -35,10 +35,9 @@
context 'should use default value when supplied a nil radius' do
before do
allow(Conversions::Distance::Miles::ToMetres).to receive(:convert).and_return(50)
+ subject.close_to(mcr_piccadilly, radius: nil)
end
- before { subject.close_to(mcr_piccadilly, radius: nil) }
-
specify 'should use the specified default value when nil supplied' do
expect(Conversions::Distance::Miles::ToMetres).to have_received(:convert).with(subject::DEFAULT_RADIUS)
end
diff --git a/spec/models/concerns/yaml_model_spec.rb b/spec/models/concerns/yaml_model_spec.rb
index 792c15fd9a..357767e7c2 100644
--- a/spec/models/concerns/yaml_model_spec.rb
+++ b/spec/models/concerns/yaml_model_spec.rb
@@ -12,7 +12,7 @@ class YamlTestModel
let(:described_class) { YamlTestModel }
describe '.data_path' do
- it "should be assigned" do
+ it "is assigned" do
expect(described_class.send(:data_path)).to eql \
Rails.root.join('data', 'yaml_test_models')
end
@@ -29,6 +29,7 @@ class YamlTestModel
describe '.find' do
subject { described_class.find test_dob }
+
it { is_expected.to have_attributes dob: Date.parse('1978-01-01') }
it { is_expected.to have_attributes firstname: 'James' }
it { is_expected.to have_attributes lastname: 'Smith' }
@@ -36,20 +37,25 @@ class YamlTestModel
describe '.ids' do
subject { described_class.ids }
+
it { is_expected.to eql [test_dob, second_dob] }
end
describe '#==' do
+ subject { described_class.new attrs }
+
let(:attrs) { { dob: '19800620', firstname: 'Sarah', lastname: 'Jane' } }
let(:other) { described_class.new attrs }
- subject { described_class.new attrs }
+
it { is_expected.to eq other }
end
describe '.all' do
+ subject { described_class.all }
+
let(:first) { described_class.find test_dob }
let(:second) { described_class.find second_dob }
- subject { described_class.all }
+
it { is_expected.to eq [first, second] }
end
end
diff --git a/spec/models/cookie_preference_spec.rb b/spec/models/cookie_preference_spec.rb
index e65b8a8cfd..89db9ab37f 100644
--- a/spec/models/cookie_preference_spec.rb
+++ b/spec/models/cookie_preference_spec.rb
@@ -11,6 +11,7 @@
context 'required should be editable' do
before { subject.required = false }
+
it { is_expected.to have_attributes required: true }
end
end
@@ -21,7 +22,7 @@
it { is_expected.to allow_value(false).for(:analytics) }
it do
- is_expected.not_to allow_value(nil).for(:analytics)
+ expect(subject).not_to allow_value(nil).for(:analytics)
.with_message('Choose On or Off for cookies which measure website use')
end
end
@@ -29,6 +30,7 @@
describe 'methods' do
before { freeze_time }
+
it { is_expected.to have_attributes cookie_key: 'cookie_preference-v1' }
it { is_expected.to have_attributes expires: 1.year.from_now }
end
@@ -38,18 +40,21 @@
context 'with true' do
let(:all) { true }
+
it { is_expected.to have_attributes required: true }
it { is_expected.to have_attributes analytics: true }
end
context 'with 1' do
let(:all) { '1' }
+
it { is_expected.to have_attributes required: true }
it { is_expected.to have_attributes analytics: true }
end
context 'with something else' do
let(:all) { '0' }
+
it { is_expected.to have_attributes required: true }
it { is_expected.to have_attributes analytics: nil }
end
@@ -57,12 +62,15 @@
describe '#to_json' do
subject { described_class.new.to_json }
+
it { is_expected.to eql({ 'analytics' => nil, 'required' => true }.to_json) }
end
describe '.from_json' do
- let(:json) { { analytics: true }.to_json }
subject { described_class.from_json(json) }
+
+ let(:json) { { analytics: true }.to_json }
+
it { is_expected.to have_attributes analytics: true }
end
@@ -71,11 +79,13 @@
context 'with cookie' do
let(:cookie) { { analytics: true }.to_json }
+
it { is_expected.to have_attributes analytics: true }
end
context 'without cookie' do
let(:cookie) { nil }
+
it { is_expected.to have_attributes analytics: nil }
end
end
@@ -84,16 +94,16 @@
subject { described_class.all_cookies }
it do
- is_expected.to eql \
+ expect(subject).to eql \
%w[_ga _gid ai_session ai_user]
end
end
describe '.cookies' do
- before { allow(ENV).to receive(:[]).and_call_original }
-
subject { described_class.cookies }
+ before { allow(ENV).to receive(:[]).and_call_original }
+
context "analytics cookies" do
it { is_expected.to include({ analytics: %w[_ga _gid ai_session ai_user] }) }
end
@@ -106,13 +116,14 @@
let(:preference) { described_class.new(analytics: true) }
it do
- is_expected.to eql \
+ expect(subject).to eql \
%w[_ga _gid ai_session ai_user]
end
end
context 'with analytics rejected' do
let(:preference) { described_class.new(analytics: false) }
+
it { is_expected.to be_empty }
end
end
@@ -122,6 +133,7 @@
context 'with analytics accepted' do
let(:preference) { described_class.new(analytics: true) }
+
it { is_expected.to be_empty }
end
@@ -129,7 +141,7 @@
let(:preference) { described_class.new(analytics: false) }
it do
- is_expected.to eql \
+ expect(subject).to eql \
%w[_ga _gid ai_session ai_user]
end
end
@@ -137,7 +149,8 @@
describe '.category' do
subject { described_class.category '_ga' }
- it { is_expected.to eql(:analytics) }
+
+ it { is_expected.to be(:analytics) }
end
describe '.allowed?' do
@@ -146,16 +159,19 @@
context 'for neither accepted nor rejected' do
let(:params) { {} }
+
it { is_expected.to be false }
end
context 'for accepted' do
let(:params) { { analytics: true } }
+
it { is_expected.to be true }
end
context 'for rejected' do
let(:params) { { analytics: false } }
+
it { is_expected.to be false }
end
end
@@ -165,16 +181,19 @@
context 'without neither accepted or rejected' do
let(:params) { {} }
+
it { is_expected.to be false }
end
context 'with accepted' do
let(:params) { { analytics: true } }
+
it { is_expected.to be true }
end
context 'with rejected' do
let(:params) { { analytics: false } }
+
it { is_expected.to be false }
end
end
diff --git a/spec/models/event_spec.rb b/spec/models/event_spec.rb
index 4950b2fac5..b55fc5cac1 100644
--- a/spec/models/event_spec.rb
+++ b/spec/models/event_spec.rb
@@ -22,21 +22,25 @@
context 'presence of school or candidate' do
context 'when both are missing' do
subject { build(:event, :without_bookings_candidate, :without_bookings_school) }
+
specify { expect(subject).not_to be_valid }
end
context 'when the school is missing' do
subject { create(:event, :without_bookings_school) }
+
specify { expect(subject).to be_valid }
end
context 'when the candidate is missing' do
subject { create(:event, :without_bookings_candidate) }
+
specify { expect(subject).to be_valid }
end
context 'when both are present' do
subject { create(:event) }
+
specify { expect(subject).to be_valid }
end
end
diff --git a/spec/models/feature_spec.rb b/spec/models/feature_spec.rb
index aa38ff985e..ed283583b5 100644
--- a/spec/models/feature_spec.rb
+++ b/spec/models/feature_spec.rb
@@ -15,7 +15,7 @@
end
context "when feature in config" do
- before { allow(Rails).to receive(:env) { "production" } }
+ before { allow(Rails).to receive(:env).and_return("production") }
context "when enabled in environment" do
it "returns true" do
@@ -39,7 +39,7 @@
]
end
- it "returns a list of #{Feature}" do
+ it "returns a list of #{described_class}" do
expect(subject.all).to match_array expected_features
end
end
@@ -52,16 +52,16 @@
describe ".new" do
context "when environment not in Rails configured environments" do
- let(:bad_environment_feature) { Feature.new("bad", "bad", %w[does_not_exist]) }
+ let(:bad_environment_feature) { described_class.new("bad", "bad", %w[does_not_exist]) }
- it "raises #{Feature::IncorrectEnvironmentError} " do
+ it "raises #{Feature::IncorrectEnvironmentError}" do
expect { bad_environment_feature }.to raise_error(Feature::IncorrectEnvironmentError)
end
end
end
describe ".enabled_for?" do
- subject { Feature.new("feature_name", "description", %w[development]) }
+ subject { described_class.new("feature_name", "description", %w[development]) }
context "when enabled for the environment" do
it "returns true" do
diff --git a/spec/models/healthcheck_spec.rb b/spec/models/healthcheck_spec.rb
index e04d4fc6af..20f11cd68e 100644
--- a/spec/models/healthcheck_spec.rb
+++ b/spec/models/healthcheck_spec.rb
@@ -2,6 +2,7 @@
RSpec.describe Healthcheck do
let(:gitsha) { "d64e925a5c70b05246e493de7b60af73e1dfa9dd" }
+
shafile = "/etc/school-experience-sha"
describe "#app_sha" do
@@ -20,7 +21,7 @@
allow(File).to receive(:read).with(shafile).and_raise Errno::ENOENT
end
- it { is_expected.to eql nil }
+ it { is_expected.to be_nil }
end
end
@@ -67,14 +68,14 @@
end
describe "#test_redis" do
+ subject { described_class.new.test_redis }
+
before do
allow(ENV).to receive(:[]).and_call_original
allow(ENV).to receive(:[]).with("REDIS_URL").and_return \
"redis://localhost:6379/1"
end
- subject { described_class.new.test_redis }
-
context "with working connection" do
before do
allow(REDIS).to receive(:ping).and_return("PONG")
@@ -105,17 +106,17 @@
allow(ENV).to receive(:[]).with("REDIS_URL").and_return nil
end
- it { is_expected.to be nil }
+ it { is_expected.to be_nil }
end
end
describe "#test_dfe_signin_api" do
+ subject { described_class.new.test_dfe_signin_api }
+
before do
allow(Schools::DFESignInAPI::Organisations).to receive(:enabled?).and_return(true)
end
- subject { described_class.new.test_dfe_signin_api }
-
context "with working connection" do
before do
allow_any_instance_of(Schools::DFESignInAPI::Organisations).to receive(:uuids).and_return({})
@@ -129,7 +130,7 @@
[RuntimeError, Redis::CannotConnectError].each do |error|
allow_any_instance_of(Schools::DFESignInAPI::Organisations).to receive(:response).and_raise error
- is_expected.to be false
+ expect(subject).to be false
end
end
end
@@ -144,9 +145,10 @@
end
describe "#to_h" do
+ subject { described_class.new.to_h }
+
include_context "api healthy"
- subject { described_class.new.to_h }
it { is_expected.to include :deployment_id }
it { is_expected.to include :app_sha }
it { is_expected.to include :dfe_auth }
@@ -158,9 +160,10 @@
end
describe "#to_json" do
+ subject { JSON.parse described_class.new.to_json }
+
include_context "api healthy"
- subject { JSON.parse described_class.new.to_json }
it { is_expected.to include "deployment_id" }
it { is_expected.to include "app_sha" }
it { is_expected.to include "dfe_auth" }
diff --git a/spec/models/schools/attendance_records_spec.rb b/spec/models/schools/attendance_records_spec.rb
index 53d100d4cc..b861a80ec5 100644
--- a/spec/models/schools/attendance_records_spec.rb
+++ b/spec/models/schools/attendance_records_spec.rb
@@ -2,14 +2,16 @@
describe Schools::AttendanceRecords, type: :model do
describe "#records" do
+ subject { records.records }
+
let(:booking) { create :bookings_booking, :accepted, :attended }
let(:school_urns) { [booking.bookings_school.urn] }
let(:candidate_id) { booking.bookings_placement_request.candidate_id }
- subject { records.records }
context 'with matching urn' do
context 'but different candidate' do
let(:records) { described_class.new 10_000_000, school_urns }
+
it { is_expected.not_to include booking }
end
@@ -22,11 +24,13 @@
context 'and did not attend' do
let(:booking) { create :bookings_booking, :accepted, :unattended }
+
it { is_expected.to include booking }
end
context 'and no attendance info' do
let(:booking) { create :bookings_booking, :accepted }
+
it { is_expected.not_to include booking }
end
end
@@ -34,6 +38,7 @@
context 'for URN not in list' do
let(:records) { described_class.new candidate_id, [999_999_999, 999_999_990] }
+
it { is_expected.not_to include booking }
end
end
@@ -78,16 +83,19 @@
describe '#attended_count' do
subject { records.attended_count }
+
it { is_expected.to eq 1 }
context 'for both schools' do
let(:urns) { [school.urn, second_school.urn] }
+
it { is_expected.to eq 2 }
end
end
describe '#did_not_attend_count' do
subject { records.did_not_attend_count }
+
it { is_expected.to eq 1 }
end
end
diff --git a/spec/models/schools/attendance_spec.rb b/spec/models/schools/attendance_spec.rb
index 8e1d37235d..e0caa2007d 100644
--- a/spec/models/schools/attendance_spec.rb
+++ b/spec/models/schools/attendance_spec.rb
@@ -1,6 +1,8 @@
require 'rails_helper'
describe Schools::Attendance do
+ subject { attendance }
+
let(:booking_1) { create(:bookings_booking, :accepted) }
let(:booking_2) { create(:bookings_booking, :accepted) }
let(:booking_3) { create(:bookings_booking, :accepted) }
@@ -33,8 +35,6 @@
receive(:from_booking) { feedback_request_double }
end
- subject { attendance }
-
describe '#initialize' do
specify 'should correctly assign bookings' do
expect(subject.bookings).to match_array(bookings)
@@ -51,15 +51,15 @@
describe '#save' do
context 'when booking cancelled' do
+ subject! { attendance.save }
+
before do
create :cancellation, :sent, placement_request: booking_1.bookings_placement_request
bookings.each(&:reload)
end
- subject! { attendance.save }
-
specify 'should not update cancelled bookings' do
- expect(booking_1.reload.attended).to be nil
+ expect(booking_1.reload.attended).to be_nil
end
specify 'sends feedback emails for attended (and not cancelled) bookings' do
@@ -77,19 +77,18 @@
end
specify 'save should return false' do
- is_expected.to be false
+ expect(subject).to be false
end
specify 'attendance should have 1 error' do
- expect(attendance.errors.messages.length).to eql 1
- expect(attendance.errors.messages[:bookings_params].length).to eql 1
+ expect(attendance.errors.messages.length).to be 1
+ expect(attendance.errors.messages[:bookings_params].length).to be 1
expect(attendance.errors.messages[:bookings_params].first).to \
match(/unable to set attendance/i)
end
specify 'attendance.updated_bookings' do
- expect(attendance.updated_bookings).to match_array \
- [booking_2.id, booking_3.id]
+ expect(attendance.updated_bookings).to contain_exactly(booking_2.id, booking_3.id)
end
end
@@ -103,7 +102,7 @@
end
specify 'save should return true' do
- is_expected.to be true
+ expect(subject).to be true
end
specify 'attendance.updated_bookings' do
@@ -125,7 +124,7 @@
end
specify 'should correctly update bookings with param values' do
- bookings_params.each do |id, _status|
+ bookings_params.each_key do |id|
booking = Bookings::Booking.find(id)
expect(Bookings::Gitis::SchoolExperience).to \
diff --git a/spec/models/schools/change_school_spec.rb b/spec/models/schools/change_school_spec.rb
index 9734619d80..e3cfbbe055 100644
--- a/spec/models/schools/change_school_spec.rb
+++ b/spec/models/schools/change_school_spec.rb
@@ -31,8 +31,6 @@
receive(:has_school_experience_role?) { user_has_role }
end
- subject { change_school }
-
describe 'attributes' do
it { is_expected.to respond_to :change_to_urn }
end
@@ -46,24 +44,25 @@
subject { change_school.available_schools }
it 'only returns schools which we have in our system' do
- is_expected.to contain_exactly(first_school, second_school)
+ expect(subject).to contain_exactly(first_school, second_school)
end
it 'returns schools in alphabetical order' do
- is_expected.to eq([second_school, first_school])
+ expect(subject).to eq([second_school, first_school])
end
context 'when a school has outstanding tasks' do
before { create :placement_request, school: first_school }
it 'returns schools with the most outstanding tasks first' do
- is_expected.to eq([first_school, second_school])
+ expect(subject).to eq([first_school, second_school])
end
end
end
describe '#school_uuid' do
let(:change_to_urn) { second_school.urn }
+
it { is_expected.to have_attributes school_uuid: uuid_map.keys[1] }
end
@@ -83,8 +82,8 @@
end
context 'with valid urn' do
- it 'should return school' do
- is_expected.to eql second_school
+ it 'returns school' do
+ expect(subject).to eql second_school
end
end
@@ -98,10 +97,13 @@
describe '#task_count_for_urn' do
context 'with unexpected URN' do
subject { change_school.task_count_for_urn 987_654 }
+
it { is_expected.to be_nil }
end
context 'with known URN' do
+ subject { change_school.task_count_for_urn first_school.urn }
+
before do
create :placement_request, school: first_school
create :placement_request, school: second_school
@@ -111,10 +113,8 @@
end
end
- subject { change_school.task_count_for_urn first_school.urn }
-
- it "should include count only for requested school" do
- is_expected.to eql 2
+ it "includes count only for requested school" do
+ expect(subject).to be 2
end
end
end
diff --git a/spec/models/schools/csv_export_spec.rb b/spec/models/schools/csv_export_spec.rb
index 31238b7685..7087e8d990 100644
--- a/spec/models/schools/csv_export_spec.rb
+++ b/spec/models/schools/csv_export_spec.rb
@@ -33,17 +33,17 @@
describe "header rows" do
subject { parsed_csv[0] }
- it "should contain a header row" do
- is_expected.to eql \
+ it "contains a header row" do
+ expect(subject).to eql \
["Id", "Name", "Email", "Date", "Duration", "Subject", "Second Subject", "Status", "Attendance"]
end
end
describe "data rows" do
- include_context "api sign ups for requests"
-
subject { parsed_csv.slice(1...).map(&:first).map(&:to_i) }
+ include_context "api sign ups for requests"
+
let(:first) { create(:bookings_booking).bookings_placement_request }
let(:school) { first.school }
let(:second) { create :bookings_placement_request, school: school }
@@ -52,12 +52,12 @@
end
let(:requests) { [first, second] }
- it "should contain placement requests from this academic year" do
- is_expected.to eql [first.id, second.id]
+ it "contains placement requests from this academic year" do
+ expect(subject).to eql [first.id, second.id]
end
- it "should not contain placement requests from earlier academic years" do
- is_expected.not_to include historical.id
+ it "does not contain placement requests from earlier academic years" do
+ expect(subject).not_to include historical.id
end
context "crm data" do
diff --git a/spec/models/schools/prepopulate_school_profile_spec.rb b/spec/models/schools/prepopulate_school_profile_spec.rb
index 3225f09df1..44ff16a67c 100644
--- a/spec/models/schools/prepopulate_school_profile_spec.rb
+++ b/spec/models/schools/prepopulate_school_profile_spec.rb
@@ -38,23 +38,22 @@
end
describe ".enabled?" do
+ subject { described_class }
+
before do
- allow(Rails.configuration.x).to receive(:dfe_sign_in_api_enabled) { true }
- allow(Rails.configuration.x).to receive(:dfe_sign_in_api_school_change_enabled) { true }
+ allow(Rails.configuration.x).to receive_messages(dfe_sign_in_api_enabled: true, dfe_sign_in_api_school_change_enabled: true)
end
- subject { described_class }
-
it { is_expected.to be_enabled }
context "when dfe_sign_in_api_enabled is false" do
- before { allow(Rails.configuration.x).to receive(:dfe_sign_in_api_enabled) { false } }
+ before { allow(Rails.configuration.x).to receive(:dfe_sign_in_api_enabled).and_return(false) }
it { is_expected.not_to be_enabled }
end
context "when dfe_sign_in_api_school_change_enabled is false" do
- before { allow(Rails.configuration.x).to receive(:dfe_sign_in_api_school_change_enabled) { false } }
+ before { allow(Rails.configuration.x).to receive(:dfe_sign_in_api_school_change_enabled).and_return(false) }
it { is_expected.not_to be_enabled }
end
@@ -64,11 +63,11 @@
subject { instance.available_schools }
it "only returns schools which we have in our system and are onboarded, excluding the current school" do
- is_expected.to contain_exactly(first_school, second_school)
+ expect(subject).to contain_exactly(first_school, second_school)
end
it "returns schools in alphabetical order" do
- is_expected.to eq([second_school, first_school])
+ expect(subject).to eq([second_school, first_school])
end
end
diff --git a/spec/models/schools/school_profile_spec.rb b/spec/models/schools/school_profile_spec.rb
index dc14a7be2a..5fdb6e55f2 100644
--- a/spec/models/schools/school_profile_spec.rb
+++ b/spec/models/schools/school_profile_spec.rb
@@ -3,220 +3,220 @@
describe Schools::SchoolProfile, type: :model do
context 'attributes' do
it do
- is_expected.to have_db_column(:bookings_school_id).of_type :integer
+ expect(subject).to have_db_column(:bookings_school_id).of_type :integer
end
it do
- is_expected.to \
+ expect(subject).to \
have_db_column(:dbs_requirement_requires_check).of_type :boolean
end
it do
- is_expected.to \
+ expect(subject).to \
have_db_column(:dbs_requirement_dbs_policy_conditions).of_type :string
end
it do
- is_expected.to \
+ expect(subject).to \
have_db_column(:dbs_requirement_dbs_policy_details).of_type :text
end
it do
- is_expected.to \
+ expect(subject).to \
have_db_column(:dbs_requirement_no_dbs_policy_details).of_type :text
end
it do
- is_expected.to \
+ expect(subject).to \
have_db_column(:candidate_requirement_dbs_requirement).of_type :string
end
it do
- is_expected.to \
+ expect(subject).to \
have_db_column(:candidate_requirement_dbs_policy).of_type :text
end
it do
- is_expected.to \
+ expect(subject).to \
have_db_column(:candidate_requirement_requirements).of_type :boolean
end
it do
- is_expected.to \
+ expect(subject).to \
have_db_column(:candidate_requirement_requirements_details).of_type :text
end
it do
- is_expected.to \
+ expect(subject).to \
have_db_column(:fees_administration_fees).of_type :boolean
end
it do
- is_expected.to have_db_column(:fees_dbs_fees).of_type :boolean
+ expect(subject).to have_db_column(:fees_dbs_fees).of_type :boolean
end
it do
- is_expected.to have_db_column(:fees_other_fees).of_type :boolean
+ expect(subject).to have_db_column(:fees_other_fees).of_type :boolean
end
%w[administration_fee dbs_fee other_fee].each do |fee|
it do
- is_expected.to \
+ expect(subject).to \
have_db_column(:"#{fee}_amount_pounds")
.of_type(:decimal).with_options(precision: 6, scale: 2)
end
it do
- is_expected.to have_db_column(:"#{fee}_description").of_type :text
+ expect(subject).to have_db_column(:"#{fee}_description").of_type :text
end
it do
- is_expected.to have_db_column(:"#{fee}_interval").of_type :string
+ expect(subject).to have_db_column(:"#{fee}_interval").of_type :string
end
it do
- is_expected.to have_db_column(:"#{fee}_payment_method").of_type :text
+ expect(subject).to have_db_column(:"#{fee}_payment_method").of_type :text
end
end
it do
- is_expected.to have_db_column(:phases_list_primary).of_type :boolean
+ expect(subject).to have_db_column(:phases_list_primary).of_type :boolean
end
it do
- is_expected.to have_db_column(:phases_list_secondary).of_type :boolean
+ expect(subject).to have_db_column(:phases_list_secondary).of_type :boolean
end
it do
- is_expected.to have_db_column(:phases_list_college).of_type :boolean
+ expect(subject).to have_db_column(:phases_list_college).of_type :boolean
end
it do
- is_expected.to \
+ expect(subject).to \
have_db_column(:phases_list_secondary_and_college).of_type :boolean
end
it do
- is_expected.to have_db_column(:description_details).of_type :text
+ expect(subject).to have_db_column(:description_details).of_type :text
end
it do
- is_expected.to have_db_column(:candidate_dress_code_business_dress).of_type :boolean
+ expect(subject).to have_db_column(:candidate_dress_code_business_dress).of_type :boolean
end
it do
- is_expected.to have_db_column(:candidate_dress_code_cover_up_tattoos).of_type :boolean
+ expect(subject).to have_db_column(:candidate_dress_code_cover_up_tattoos).of_type :boolean
end
it do
- is_expected.to have_db_column(:candidate_dress_code_remove_piercings).of_type :boolean
+ expect(subject).to have_db_column(:candidate_dress_code_remove_piercings).of_type :boolean
end
it do
- is_expected.to have_db_column(:candidate_dress_code_smart_casual).of_type :boolean
+ expect(subject).to have_db_column(:candidate_dress_code_smart_casual).of_type :boolean
end
it do
- is_expected.to have_db_column(:candidate_dress_code_other_dress_requirements).of_type :boolean
+ expect(subject).to have_db_column(:candidate_dress_code_other_dress_requirements).of_type :boolean
end
it do
- is_expected.to have_db_column(:candidate_dress_code_step_completed).of_type :boolean
+ expect(subject).to have_db_column(:candidate_dress_code_step_completed).of_type :boolean
end
it do
- is_expected.to have_db_column(:candidate_dress_code_other_dress_requirements_detail).of_type :string
+ expect(subject).to have_db_column(:candidate_dress_code_other_dress_requirements_detail).of_type :string
end
it do
- is_expected.to have_db_column(:candidate_parking_information_parking_provided).of_type :boolean
+ expect(subject).to have_db_column(:candidate_parking_information_parking_provided).of_type :boolean
end
it do
- is_expected.to have_db_column(:candidate_parking_information_parking_details).of_type :string
+ expect(subject).to have_db_column(:candidate_parking_information_parking_details).of_type :string
end
it do
- is_expected.to have_db_column(:candidate_parking_information_nearby_parking_details).of_type :string
+ expect(subject).to have_db_column(:candidate_parking_information_nearby_parking_details).of_type :string
end
it do
- is_expected.to have_db_column(:candidate_experience_schedule_start_time).of_type :string
+ expect(subject).to have_db_column(:candidate_experience_schedule_start_time).of_type :string
end
it do
- is_expected.to have_db_column(:candidate_experience_schedule_end_time).of_type :string
+ expect(subject).to have_db_column(:candidate_experience_schedule_end_time).of_type :string
end
it do
- is_expected.to have_db_column(:candidate_experience_schedule_times_flexible).of_type :boolean
+ expect(subject).to have_db_column(:candidate_experience_schedule_times_flexible).of_type :boolean
end
it do
- is_expected.to \
+ expect(subject).to \
have_db_column(:candidate_experience_schedule_times_flexible_details).of_type :text
end
it do
- is_expected.to \
+ expect(subject).to \
have_db_column(:experience_outline_candidate_experience).of_type :text
end
it do
- is_expected.to \
+ expect(subject).to \
have_db_column(:teacher_training_provides_teacher_training).of_type :boolean
end
it do
- is_expected.to \
+ expect(subject).to \
have_db_column(:teacher_training_teacher_training_details).of_type :text
end
it do
- is_expected.to \
+ expect(subject).to \
have_db_column(:teacher_training_teacher_training_url).of_type :string
end
it do
- is_expected.to have_db_column(:admin_contact_full_name).of_type :string
+ expect(subject).to have_db_column(:admin_contact_full_name).of_type :string
end
it do
- is_expected.to have_db_column(:admin_contact_email).of_type :string
+ expect(subject).to have_db_column(:admin_contact_email).of_type :string
end
it do
- is_expected.to have_db_column(:admin_contact_email_secondary).of_type :string
+ expect(subject).to have_db_column(:admin_contact_email_secondary).of_type :string
end
it do
- is_expected.to \
+ expect(subject).to \
have_db_column(:confirmation_acceptance).of_type(:boolean)
end
it do
- is_expected.to \
+ expect(subject).to \
have_db_column(:candidate_requirements_selection_step_completed)
.of_type(:boolean).with_options(default: false)
end
it do
- is_expected.to \
+ expect(subject).to \
have_db_column(:access_needs_detail_description).of_type(:string)
end
it do
- is_expected.to \
+ expect(subject).to \
have_db_column(:disability_confident_is_disability_confident).of_type(:boolean)
end
it do
- is_expected.to \
+ expect(subject).to \
have_db_column(:access_needs_policy_has_access_needs_policy).of_type(:boolean)
end
it do
- is_expected.to have_db_column(:access_needs_policy_url).of_type(:string)
+ expect(subject).to have_db_column(:access_needs_policy_url).of_type(:string)
end
end
@@ -232,15 +232,15 @@
context 'validations' do
it do
- is_expected.to validate_presence_of :bookings_school
+ expect(subject).to validate_presence_of :bookings_school
end
end
context 'associations' do
context 'subjects' do
- let(:bookings_school) { create(:bookings_school) }
subject { described_class.create!(bookings_school: bookings_school) }
+ let(:bookings_school) { create(:bookings_school) }
let :bookings_subject do
FactoryBot.create :bookings_subject
end
@@ -249,7 +249,7 @@
subject.subjects << bookings_subject
end
- context '#subjects' do
+ describe '#subjects' do
it 'only returns subjects' do
expect(subject.subjects.to_a).to eq [bookings_subject]
end
@@ -263,7 +263,7 @@
described_class.new bookings_school: bookings_school
end
- context '#dbs_requirement' do
+ describe '#dbs_requirement' do
let :form_model do
FactoryBot.build :dbs_requirement
end
@@ -287,7 +287,7 @@
end
end
- context '#fees' do
+ describe '#fees' do
let :form_model do
FactoryBot.build :fees
end
@@ -352,7 +352,7 @@
end
end
- context '#phases_list' do
+ describe '#phases_list' do
let :form_model do
FactoryBot.build :phases_list
end
@@ -383,7 +383,7 @@
end
end
- context '#key_stage_list' do
+ describe '#key_stage_list' do
let :form_model do
FactoryBot.build :key_stage_list
end
@@ -405,7 +405,7 @@
end
end
- context '#description' do
+ describe '#description' do
let :form_model do
FactoryBot.build :description
end
@@ -423,7 +423,7 @@
end
end
- context '#candidate_dress_code' do
+ describe '#candidate_dress_code' do
let :form_model do
FactoryBot.build :candidate_dress_code
end
@@ -451,7 +451,7 @@
end
end
- context '#candidate_parking_information' do
+ describe '#candidate_parking_information' do
let :form_model do
FactoryBot.build :candidate_parking_information
end
@@ -476,7 +476,7 @@
end
end
- context '#candidate_experience_schedule' do
+ describe '#candidate_experience_schedule' do
let :form_model do
FactoryBot.build :candidate_experience_schedule
end
@@ -502,7 +502,7 @@
end
end
- context '#access_needs_support' do
+ describe '#access_needs_support' do
let :form_model do
FactoryBot.build :access_needs_support
end
@@ -523,7 +523,7 @@
end
end
- context '#access_needs_detail' do
+ describe '#access_needs_detail' do
let :form_model do
FactoryBot.build :access_needs_detail
end
@@ -544,7 +544,7 @@
end
end
- context '#disability_confident' do
+ describe '#disability_confident' do
let :form_model do
FactoryBot.build :disability_confident
end
@@ -565,7 +565,7 @@
end
end
- context '#access_needs_policy' do
+ describe '#access_needs_policy' do
let :form_model do
FactoryBot.build :access_needs_policy
end
@@ -586,7 +586,7 @@
end
end
- context '#experience_outline' do
+ describe '#experience_outline' do
let :form_model do
FactoryBot.build :experience_outline
end
@@ -605,7 +605,7 @@
end
end
- context '#teacher_training' do
+ describe '#teacher_training' do
let :form_model do
FactoryBot.build :teacher_training
end
@@ -630,7 +630,7 @@
end
end
- context '#admin_contact' do
+ describe '#admin_contact' do
let :form_model do
FactoryBot.build :admin_contact
end
@@ -651,7 +651,7 @@
end
end
- context '#confirmation' do
+ describe '#confirmation' do
let :form_model do
FactoryBot.build :confirmation
end
@@ -782,10 +782,10 @@
end
describe "#dup" do
- let(:profile) { create(:school_profile, :completed) }
-
subject(:duplicate) { profile.dup }
+ let(:profile) { create(:school_profile, :completed) }
+
it "duplicates the profile and related subjects" do
expected_attributes = profile.attributes.without(%w[id created_at updated_at])
expect(duplicate).to have_attributes(expected_attributes)
@@ -793,7 +793,7 @@
end
end
- context '#requires_subjects?' do
+ describe '#requires_subjects?' do
let :school_profile do
FactoryBot.create :school_profile
end
@@ -828,11 +828,11 @@
end
describe "#current_step" do
+ subject { school_profile.current_step(previous_step) }
+
let(:previous_step) { nil }
let(:school_profile) { build(:school_profile) }
- subject { school_profile.current_step(previous_step) }
-
it { is_expected.to be(:dbs_requirement) }
context "when the task_progress_on_boarding feature is enabled" do
@@ -848,10 +848,10 @@
end
describe "#completed?" do
- let(:school_profile) { build(:school_profile) }
-
subject { school_profile }
+ let(:school_profile) { build(:school_profile) }
+
it { is_expected.not_to be_completed }
context "when completed" do
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 85b7597f09..9c242f3580 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -15,8 +15,9 @@
subject(:exchange) { described_class.exchange(dfe_sign_in_user) }
it { expect { exchange }.to change(described_class, :count).by(1) }
+
it do
- is_expected.to have_attributes(
+ expect(subject).to have_attributes(
sub: dfe_sign_in_user.sub,
given_name: dfe_sign_in_user.given_name,
family_name: dfe_sign_in_user.family_name,
diff --git a/spec/notify/notify_despatchers/notify_spec.rb b/spec/notify/notify_despatchers/notify_spec.rb
index 8548bdde42..e95a466b18 100644
--- a/spec/notify/notify_despatchers/notify_spec.rb
+++ b/spec/notify/notify_despatchers/notify_spec.rb
@@ -16,7 +16,7 @@
end
end
- it "should send emails with the correct parameters" do
+ it "sends emails with the correct parameters" do
recipients.each do |recipient|
expect(NotifyService.instance).to have_received(notify_method).with notify_params.call(recipient)
end
@@ -28,7 +28,7 @@
subject.new to: recipients, name: nil
end
- it "should raise an error whilst trying to enqueue" do
+ it "raises an error whilst trying to enqueue" do
expect { notification.despatch_later! }.to \
raise_exception NotifyDespatchers::Base::InvalidPersonalisationError
end
@@ -38,13 +38,14 @@
let :notification do
subject.new to: recipients, name: 1
end
+
before do
perform_enqueued_jobs do
notification.despatch_later!
end
end
- it "should cast personalisations to string" do
+ it "casts personalisations to string" do
recipients.each do |recipient|
expect(NotifyService.instance).to have_received(notify_method).with notify_params.call(recipient, { name: "1" })
end
@@ -94,6 +95,8 @@ def personalisation
describe NotifyDespatchers::Base do
include ActiveJob::TestHelper
+ subject { described_class.new(to: to) }
+
let(:to) { 'somename@somecompany.org' }
before do
@@ -101,8 +104,6 @@ def personalisation
allow(NotifyService.instance).to receive(:send_sms)
end
- subject { NotifyDespatchers::Base.new(to: to) }
-
describe 'Attributes' do
it { is_expected.to respond_to(:to) }
end
@@ -123,20 +124,20 @@ def personalisation
describe 'Methods' do
describe '#despatch_later!' do
- it "should fail with NotImplementedError'" do
+ it "fails with NotImplementedError'" do
expect { subject.despatch_later! }.to raise_error(NotImplementedError, 'You must implement the despatch_later! method')
end
end
context 'Private methods' do
describe '#personalisation' do
- it "should fail with 'Not implemented'" do
+ it "fails with 'Not implemented'" do
expect { subject.send(:personalisation) }.to raise_error('Not implemented')
end
end
describe '#template_id' do
- it "should fail with 'Not implemented'" do
+ it "fails with 'Not implemented'" do
expect { subject.send(:template_id) }.to raise_error('Not implemented')
end
end
@@ -146,6 +147,8 @@ def personalisation
describe NotifyDespatchers::Email do
include ActiveJob::TestHelper
+ subject { StubEmailNotification }
+
let(:to) { 'somename@somecompany.org' }
let :recipients do
%w[test1@user.com test2@user.com]
@@ -162,12 +165,13 @@ def personalisation
end
let(:notification) { subject.new to: recipients, name: 'Test User' }
- subject { StubEmailNotification }
include_examples "notify_client"
end
describe NotifyDespatchers::Sms do
include ActiveJob::TestHelper
+ subject { StubSmsNotification }
+
let(:to) { '07777777777' }
let :recipients do
%w[07777777778 07777777779]
@@ -184,14 +188,12 @@ def personalisation
end
let(:notification) { subject.new to: recipients, name: 'Test User' }
- before { allow(Feature).to receive(:enabled?).with(:sms) { true } }
-
- subject { StubSmsNotification }
+ before { allow(Feature).to receive(:enabled?).with(:sms).and_return(true) }
include_examples "notify_client"
context "when in non-production environments" do
- before { allow(Feature).to receive(:enabled?).with(:sms) { false } }
+ before { allow(Feature).to receive(:enabled?).with(:sms).and_return(false) }
it "does not despatch SMS" do
perform_enqueued_jobs do
diff --git a/spec/notify/notify_email/candidate_booking_cancellation_spec.rb b/spec/notify/notify_email/candidate_booking_cancellation_spec.rb
index 946fe71509..539974f198 100644
--- a/spec/notify/notify_email/candidate_booking_cancellation_spec.rb
+++ b/spec/notify/notify_email/candidate_booking_cancellation_spec.rb
@@ -1,7 +1,7 @@
require 'rails_helper'
describe NotifyEmail::CandidateBookingCancellation do
- it_should_behave_like "email template", "af2311b2-7b7e-4342-b1da-bba957273b3e",
+ it_behaves_like "email template", "af2311b2-7b7e-4342-b1da-bba957273b3e",
school_name: "Springfield Elementary School",
placement_start_date_with_duration: "2020-04-05",
school_search_url: 'https://www.springfield.edu/search'
diff --git a/spec/notify/notify_email/candidate_booking_confirmation_spec.rb b/spec/notify/notify_email/candidate_booking_confirmation_spec.rb
index 741fe1c6aa..2f2f0abbcf 100644
--- a/spec/notify/notify_email/candidate_booking_confirmation_spec.rb
+++ b/spec/notify/notify_email/candidate_booking_confirmation_spec.rb
@@ -1,7 +1,7 @@
require 'rails_helper'
describe NotifyEmail::CandidateBookingConfirmation do
- it_should_behave_like "email template", "f66aaa08-df33-4be6-95b6-7e1cf8595a2b",
+ it_behaves_like "email template", "f66aaa08-df33-4be6-95b6-7e1cf8595a2b",
school_name: "Springfield Elementary",
candidate_name: "Kearney Zzyzwicz",
placement_schedule: "2022-03-04 for 3 days",
@@ -21,6 +21,8 @@
cancellation_url: 'https://example.com/candiates/cancel/abc-123'
describe ".from_booking" do
+ subject { described_class.from_booking(to, candidate_name, booking, cancellation_url) }
+
before do
stub_const(
'Notify::API_KEY',
@@ -28,21 +30,17 @@
)
end
- specify { expect(described_class).to respond_to(:from_booking) }
-
- let!(:school) { create(:bookings_school, urn: 11_048) }
- let!(:profile) { create(:bookings_profile, school: school) }
- let(:to) { "morris.szyslak@moes.net" }
- let(:candidate_name) { "morris.szyslak" }
-
- let!(:pr) { create(:bookings_placement_request, school: school) }
+ let!(:cancellation_url) { "https://example.com/candidates/cancel/#{booking.token}" }
let!(:booking) do
create :bookings_booking, :accepted, bookings_placement_request: pr
end
+ let!(:pr) { create(:bookings_placement_request, school: school) }
+ let(:candidate_name) { "morris.szyslak" }
+ let(:to) { "morris.szyslak@moes.net" }
+ let!(:profile) { create(:bookings_profile, school: school) }
+ let!(:school) { create(:bookings_school, urn: 11_048) }
- let!(:cancellation_url) { "https://example.com/candidates/cancel/#{booking.token}" }
-
- subject { described_class.from_booking(to, candidate_name, booking, cancellation_url) }
+ specify { expect(described_class).to respond_to(:from_booking) }
it { is_expected.to be_a(described_class) }
diff --git a/spec/notify/notify_email/candidate_booking_date_changed_spec.rb b/spec/notify/notify_email/candidate_booking_date_changed_spec.rb
index a6e87f9079..a5c93d92d1 100644
--- a/spec/notify/notify_email/candidate_booking_date_changed_spec.rb
+++ b/spec/notify/notify_email/candidate_booking_date_changed_spec.rb
@@ -1,7 +1,7 @@
require 'rails_helper'
describe NotifyEmail::CandidateBookingDateChanged do
- it_should_behave_like "email template", "3c1fd380-db1c-4efb-8e98-f3a0ef3e2661",
+ it_behaves_like "email template", "3c1fd380-db1c-4efb-8e98-f3a0ef3e2661",
school_name: "Springfield Elementary",
candidate_name: "Kearney Zzyzwicz",
placement_schedule: "2022-03-04 for 3 days",
@@ -23,6 +23,8 @@
new_date: '28 July 2019'
describe ".from_booking" do
+ subject { described_class.from_booking(to, candidate_name, booking, cancellation_url, old_date) }
+
before do
stub_const(
'Notify::API_KEY',
@@ -30,23 +32,19 @@
)
end
- specify { expect(described_class).to respond_to(:from_booking) }
-
- let!(:school) { create(:bookings_school, urn: 11_048) }
- let!(:profile) { create(:bookings_profile, experience_details: experience_details, school: school) }
- let(:experience_details) { 'some info' }
- let(:to) { "morris.szyslak@moes.net" }
- let(:candidate_name) { "morris.szyslak" }
- let(:old_date) { '09 October 2019' }
-
- let!(:pr) { create(:bookings_placement_request, school: school) }
+ let!(:cancellation_url) { "https://example.com/candidates/cancel/#{booking.token}" }
let!(:booking) do
create :bookings_booking, :accepted, bookings_placement_request: pr
end
+ let!(:pr) { create(:bookings_placement_request, school: school) }
+ let(:old_date) { '09 October 2019' }
+ let(:candidate_name) { "morris.szyslak" }
+ let(:to) { "morris.szyslak@moes.net" }
+ let(:experience_details) { 'some info' }
+ let!(:profile) { create(:bookings_profile, experience_details: experience_details, school: school) }
+ let!(:school) { create(:bookings_school, urn: 11_048) }
- let!(:cancellation_url) { "https://example.com/candidates/cancel/#{booking.token}" }
-
- subject { described_class.from_booking(to, candidate_name, booking, cancellation_url, old_date) }
+ specify { expect(described_class).to respond_to(:from_booking) }
it { is_expected.to be_a(described_class) }
diff --git a/spec/notify/notify_email/candidate_booking_feedback_spec.rb b/spec/notify/notify_email/candidate_booking_feedback_spec.rb
index 80d876d61e..8eb86258c2 100644
--- a/spec/notify/notify_email/candidate_booking_feedback_spec.rb
+++ b/spec/notify/notify_email/candidate_booking_feedback_spec.rb
@@ -1,13 +1,15 @@
require "rails_helper"
describe NotifyEmail::CandidateBookingFeedbackRequest do
- it_should_behave_like "email template", "189569bd-3115-43e0-8396-be14480a5f2d",
+ it_behaves_like "email template", "189569bd-3115-43e0-8396-be14480a5f2d",
school_name: "Springfield Elementary",
candidate_name: "Kearney Zzyzwicz",
placement_schedule: "2022-03-04 for 3 days",
feedback_url: "https://example.com/candiates/bookings/abc-123/feedback/new"
describe ".from_booking" do
+ subject { described_class.from_booking(booking) }
+
let(:booking) { create(:bookings_booking) }
let(:candidate) { booking.bookings_placement_request.candidate }
@@ -16,8 +18,6 @@
candidate.gitis_uuid = candidate.gitis_contact.candidate_id
end
- subject { described_class.from_booking(booking) }
-
context "correctly assigning attributes" do
it "candidate_name is correctly-assigned" do
expect(subject.candidate_name).to eql(booking.candidate_name)
diff --git a/spec/notify/notify_email/candidate_booking_reminder_spec.rb b/spec/notify/notify_email/candidate_booking_reminder_spec.rb
index e81bfdd889..32531a7800 100644
--- a/spec/notify/notify_email/candidate_booking_reminder_spec.rb
+++ b/spec/notify/notify_email/candidate_booking_reminder_spec.rb
@@ -1,7 +1,7 @@
require 'rails_helper'
describe NotifyEmail::CandidateBookingReminder do
- it_should_behave_like "email template", "b3e75ee5-61cf-49c5-a145-c0710c54347d",
+ it_behaves_like "email template", "b3e75ee5-61cf-49c5-a145-c0710c54347d",
time_until_booking: "2 weeks",
school_name: "Springfield Elementary",
candidate_name: "Kearney Zzyzwicz",
@@ -21,22 +21,18 @@
cancellation_url: "#{Rails.configuration.x.base_url}/candiates/cancel/abc-123"
describe ".from_booking" do
+ subject { described_class.from_booking(to, time_until_booking, booking, cancellation_url) }
+
before do
stub_const(
'Notify::API_KEY',
["somekey", SecureRandom.uuid, SecureRandom.uuid].join("-")
)
+ allow(booking).to receive(:candidate_name).and_return(candidate_name)
+ allow(booking).to receive(:candidate_name).and_return(candidate_name)
end
- specify { expect(described_class).to respond_to(:from_booking) }
-
- let(:time_until_booking) { "2 weeks" }
- let!(:school) { create(:bookings_school) }
- let!(:profile) { create(:bookings_profile, school: school) }
- let(:to) { "morris.szyslak@moes.net" }
- let(:candidate_name) { "morris.szyslak" }
-
- let!(:pr) { create(:bookings_placement_request, school: school) }
+ let!(:cancellation_url) { "#{Rails.configuration.x.base_url}/candidates/cancel/#{booking.token}" }
let!(:booking) do
create(
:bookings_booking,
@@ -44,14 +40,14 @@
bookings_placement_request: pr
)
end
+ let!(:pr) { create(:bookings_placement_request, school: school) }
+ let(:candidate_name) { "morris.szyslak" }
+ let(:to) { "morris.szyslak@moes.net" }
+ let!(:profile) { create(:bookings_profile, school: school) }
+ let!(:school) { create(:bookings_school) }
+ let(:time_until_booking) { "2 weeks" }
- before do
- allow(booking).to receive(:candidate_name).and_return(candidate_name)
- end
-
- let!(:cancellation_url) { "#{Rails.configuration.x.base_url}/candidates/cancel/#{booking.token}" }
-
- subject { described_class.from_booking(to, time_until_booking, booking, cancellation_url) }
+ specify { expect(described_class).to respond_to(:from_booking) }
it { is_expected.to be_a(described_class) }
diff --git a/spec/notify/notify_email/candidate_booking_school_cancels_booking_spec.rb b/spec/notify/notify_email/candidate_booking_school_cancels_booking_spec.rb
index 918367c1e7..7e441e4825 100644
--- a/spec/notify/notify_email/candidate_booking_school_cancels_booking_spec.rb
+++ b/spec/notify/notify_email/candidate_booking_school_cancels_booking_spec.rb
@@ -1,7 +1,7 @@
require 'rails_helper'
describe NotifyEmail::CandidateBookingSchoolCancelsBooking do
- it_should_behave_like "email template", "d7e4fd68-0f01-4a9e-96f1-62a8a77a9de1",
+ it_behaves_like "email template", "d7e4fd68-0f01-4a9e-96f1-62a8a77a9de1",
school_name: "Springfield Elementary School",
candidate_name: "James Jones",
rejection_reasons: "We're oversubscribed",
diff --git a/spec/notify/notify_email/candidate_magic_link_spec.rb b/spec/notify/notify_email/candidate_magic_link_spec.rb
index 8c83e36cc7..a79b1b5a01 100644
--- a/spec/notify/notify_email/candidate_magic_link_spec.rb
+++ b/spec/notify/notify_email/candidate_magic_link_spec.rb
@@ -1,7 +1,7 @@
require 'rails_helper'
describe NotifyEmail::CandidateMagicLink do
- it_should_behave_like "email template", "a06fe38a-5f7f-4c68-8612-6aae9495a8ab",
+ it_behaves_like "email template", "a06fe38a-5f7f-4c68-8612-6aae9495a8ab",
school_name: "Springfield Elementary School",
confirmation_link: "ABCDEFGHIJKLM1234567890"
end
diff --git a/spec/notify/notify_email/candidate_request_cancellation_spec.rb b/spec/notify/notify_email/candidate_request_cancellation_spec.rb
index e7fecab976..24bc23c941 100644
--- a/spec/notify/notify_email/candidate_request_cancellation_spec.rb
+++ b/spec/notify/notify_email/candidate_request_cancellation_spec.rb
@@ -1,7 +1,7 @@
require 'rails_helper'
describe NotifyEmail::CandidateRequestCancellation do
- it_should_behave_like "email template", "86b06712-cb58-4cc7-82a1-3748cc9ad671",
+ it_behaves_like "email template", "86b06712-cb58-4cc7-82a1-3748cc9ad671",
school_name: "Springfield Elementary School",
requested_availability: 'won lottery going on holiday',
school_search_url: 'https://www.springfield.edu/search'
diff --git a/spec/notify/notify_email/candidate_request_confirmation_no_pii_spec.rb b/spec/notify/notify_email/candidate_request_confirmation_no_pii_spec.rb
index 2c3e64d6eb..da21dc3db9 100644
--- a/spec/notify/notify_email/candidate_request_confirmation_no_pii_spec.rb
+++ b/spec/notify/notify_email/candidate_request_confirmation_no_pii_spec.rb
@@ -1,7 +1,7 @@
require 'rails_helper'
describe NotifyEmail::CandidateRequestConfirmationNoPii do
- it_should_behave_like "email template", "8ee470a1-0b94-48ee-9fe7-98b7beb8921c",
+ it_behaves_like "email template", "8ee470a1-0b94-48ee-9fe7-98b7beb8921c",
school_name: "Springfield Elementary School",
candidate_dbs_check_document: "Yes",
candidate_degree_stage: "Postgraduate",
@@ -14,6 +14,8 @@
cancellation_url: 'https://example.com/'
describe ".from_application_preview" do
+ subject { described_class.from_application_preview(to, ap, cancellation_url) }
+
before do
stub_const(
'Notify::API_KEY',
@@ -21,15 +23,13 @@
)
end
- specify { expect(described_class).to respond_to(:from_application_preview) }
-
- let!(:school) { create(:bookings_school, urn: 11_048) }
- let(:rs) { build(:registration_session) }
- let(:to) { "morris.szyslak@moes.net" }
- let(:cancellation_url) { 'https://example.com/placement_request/cancellations' }
let(:ap) { Candidates::Registrations::ApplicationPreview.new(rs) }
+ let(:cancellation_url) { 'https://example.com/placement_request/cancellations' }
+ let(:to) { "morris.szyslak@moes.net" }
+ let(:rs) { build(:registration_session) }
+ let!(:school) { create(:bookings_school, urn: 11_048) }
- subject { described_class.from_application_preview(to, ap, cancellation_url) }
+ specify { expect(described_class).to respond_to(:from_application_preview) }
it { is_expected.to be_a(described_class) }
@@ -77,6 +77,7 @@
let(:school) { create(:bookings_school, :with_fixed_availability_preference) }
let(:rs) { build(:registration_session, :with_school, urn: school.urn) }
+
specify 'bookings_placement_date_id is correctly-assigned' do
expect(subject.placement_availability).to eql(Bookings::PlacementDate.last.to_s)
end
diff --git a/spec/notify/notify_email/candidate_request_rejection_spec.rb b/spec/notify/notify_email/candidate_request_rejection_spec.rb
index 87fa709c7f..1163636fce 100644
--- a/spec/notify/notify_email/candidate_request_rejection_spec.rb
+++ b/spec/notify/notify_email/candidate_request_rejection_spec.rb
@@ -1,7 +1,7 @@
require 'rails_helper'
describe NotifyEmail::CandidateRequestRejection do
- it_should_behave_like "email template", "74f84226-539a-43b0-b887-d8ffc9348965",
+ it_behaves_like "email template", "74f84226-539a-43b0-b887-d8ffc9348965",
school_name: "Springfield Elementary School",
rejection_reasons: ["Failed security checks", "Other reason"],
extra_details: 'HawHaw',
diff --git a/spec/notify/notify_email/candidate_verify_email_link_spec.rb b/spec/notify/notify_email/candidate_verify_email_link_spec.rb
index 308bf4d880..db67ed4683 100644
--- a/spec/notify/notify_email/candidate_verify_email_link_spec.rb
+++ b/spec/notify/notify_email/candidate_verify_email_link_spec.rb
@@ -1,6 +1,6 @@
require 'rails_helper'
describe NotifyEmail::CandidateVerifyEmailLink do
- it_should_behave_like "email template", "0e4b2eaa-ae1f-472a-9293-c2a24f3f8187",
+ it_behaves_like "email template", "0e4b2eaa-ae1f-472a-9293-c2a24f3f8187",
verification_link: "ABCDEFGHIJKLM1234567890"
end
diff --git a/spec/notify/notify_email/candidate_virtual_experience_booking_confirmation_spec.rb b/spec/notify/notify_email/candidate_virtual_experience_booking_confirmation_spec.rb
index 1f2056870d..7faf551af3 100644
--- a/spec/notify/notify_email/candidate_virtual_experience_booking_confirmation_spec.rb
+++ b/spec/notify/notify_email/candidate_virtual_experience_booking_confirmation_spec.rb
@@ -1,7 +1,7 @@
require 'rails_helper'
describe NotifyEmail::CandidateVirtualExperienceBookingConfirmation do
- it_should_behave_like "email template", "1e6d2dff-be25-44f4-ac97-6fe67f131528",
+ it_behaves_like "email template", "1e6d2dff-be25-44f4-ac97-6fe67f131528",
school_name: "Springfield Elementary",
candidate_name: "Kearney Zzyzwicz",
placement_schedule: "2022-03-04 for 3 days",
@@ -17,6 +17,8 @@
cancellation_url: 'https://example.com/candiates/cancel/abc-123'
describe ".from_booking" do
+ subject { described_class.from_booking(to, candidate_name, booking, cancellation_url) }
+
before do
stub_const(
'Notify::API_KEY',
@@ -24,21 +26,17 @@
)
end
- specify { expect(described_class).to respond_to(:from_booking) }
-
- let!(:school) { create(:bookings_school, urn: 11_048) }
- let!(:profile) { create(:bookings_profile, school: school) }
- let(:to) { "bob.gill@example.com" }
- let(:candidate_name) { "bob.gill" }
-
- let!(:pr) { create(:bookings_placement_request, school: school) }
+ let!(:cancellation_url) { "https://example.com/candidates/cancel/#{booking.token}" }
let!(:booking) do
create :bookings_booking, :accepted, bookings_placement_request: pr
end
+ let!(:pr) { create(:bookings_placement_request, school: school) }
+ let(:candidate_name) { "bob.gill" }
+ let(:to) { "bob.gill@example.com" }
+ let!(:profile) { create(:bookings_profile, school: school) }
+ let!(:school) { create(:bookings_school, urn: 11_048) }
- let!(:cancellation_url) { "https://example.com/candidates/cancel/#{booking.token}" }
-
- subject { described_class.from_booking(to, candidate_name, booking, cancellation_url) }
+ specify { expect(described_class).to respond_to(:from_booking) }
it { is_expected.to be_a(described_class) }
diff --git a/spec/notify/notify_email/candidate_virtual_experience_booking_date_changed_spec.rb b/spec/notify/notify_email/candidate_virtual_experience_booking_date_changed_spec.rb
index 29cc80ee6f..b84eb7ad4a 100644
--- a/spec/notify/notify_email/candidate_virtual_experience_booking_date_changed_spec.rb
+++ b/spec/notify/notify_email/candidate_virtual_experience_booking_date_changed_spec.rb
@@ -1,7 +1,7 @@
require 'rails_helper'
describe NotifyEmail::CandidateVirtualExperienceBookingDateChanged do
- it_should_behave_like "email template", "50a32920-fa3a-4294-b013-a6472e230cf8",
+ it_behaves_like "email template", "50a32920-fa3a-4294-b013-a6472e230cf8",
school_name: "Springfield Elementary",
candidate_name: "Kearney Zzyzwicz",
placement_schedule: "2022-03-04 for 3 days",
@@ -18,6 +18,8 @@
new_date: '28 July 2019'
describe ".from_booking" do
+ subject { described_class.from_booking(to, candidate_name, booking, cancellation_url, old_date) }
+
before do
stub_const(
'Notify::API_KEY',
@@ -25,22 +27,18 @@
)
end
- specify { expect(described_class).to respond_to(:from_booking) }
-
- let!(:school) { create(:bookings_school, urn: 11_048) }
- let!(:profile) { create(:bookings_profile, school: school) }
- let(:to) { "morris.szyslak@example.com" }
- let(:candidate_name) { "morris.szyslak" }
- let(:old_date) { '09 October 2019' }
-
- let!(:pr) { create(:bookings_placement_request, school: school) }
+ let!(:cancellation_url) { "https://example.com/candidates/cancel/#{booking.token}" }
let!(:booking) do
create :bookings_booking, :accepted, bookings_placement_request: pr
end
+ let!(:pr) { create(:bookings_placement_request, school: school) }
+ let(:old_date) { '09 October 2019' }
+ let(:candidate_name) { "morris.szyslak" }
+ let(:to) { "morris.szyslak@example.com" }
+ let!(:profile) { create(:bookings_profile, school: school) }
+ let!(:school) { create(:bookings_school, urn: 11_048) }
- let!(:cancellation_url) { "https://example.com/candidates/cancel/#{booking.token}" }
-
- subject { described_class.from_booking(to, candidate_name, booking, cancellation_url, old_date) }
+ specify { expect(described_class).to respond_to(:from_booking) }
it { is_expected.to be_a(described_class) }
diff --git a/spec/notify/notify_email/candidate_virtual_experience_booking_reminder_spec.rb b/spec/notify/notify_email/candidate_virtual_experience_booking_reminder_spec.rb
index 628844faa8..b3e2b2b6b2 100644
--- a/spec/notify/notify_email/candidate_virtual_experience_booking_reminder_spec.rb
+++ b/spec/notify/notify_email/candidate_virtual_experience_booking_reminder_spec.rb
@@ -1,7 +1,7 @@
require 'rails_helper'
describe NotifyEmail::CandidateVirtualExperienceBookingReminder do
- it_should_behave_like "email template", "be4eb8b2-3abd-4882-8719-e6812975110a",
+ it_behaves_like "email template", "be4eb8b2-3abd-4882-8719-e6812975110a",
time_until_booking: "2 weeks",
school_name: "Springfield Elementary",
candidate_name: "Kearney Zzyzwicz",
@@ -18,22 +18,18 @@
cancellation_url: "#{Rails.configuration.x.base_url}/candiates/cancel/abc-123"
describe ".from_booking" do
+ subject { described_class.from_booking(to, time_until_booking, booking, cancellation_url) }
+
before do
stub_const(
'Notify::API_KEY',
["somekey", SecureRandom.uuid, SecureRandom.uuid].join("-")
)
+ allow(booking).to receive(:candidate_name).and_return(candidate_name)
+ allow(booking).to receive(:candidate_name).and_return(candidate_name)
end
- specify { expect(described_class).to respond_to(:from_booking) }
-
- let(:time_until_booking) { "2 weeks" }
- let!(:school) { create(:bookings_school) }
- let!(:profile) { create(:bookings_profile, school: school) }
- let(:to) { "morris.szyslak@moes.net" }
- let(:candidate_name) { "morris.szyslak" }
-
- let!(:pr) { create(:bookings_placement_request, school: school) }
+ let!(:cancellation_url) { "#{Rails.configuration.x.base_url}/candidates/cancel/#{booking.token}" }
let!(:booking) do
create(
:bookings_booking,
@@ -41,14 +37,14 @@
bookings_placement_request: pr
)
end
+ let!(:pr) { create(:bookings_placement_request, school: school) }
+ let(:candidate_name) { "morris.szyslak" }
+ let(:to) { "morris.szyslak@moes.net" }
+ let!(:profile) { create(:bookings_profile, school: school) }
+ let!(:school) { create(:bookings_school) }
+ let(:time_until_booking) { "2 weeks" }
- before do
- allow(booking).to receive(:candidate_name).and_return(candidate_name)
- end
-
- let!(:cancellation_url) { "#{Rails.configuration.x.base_url}/candidates/cancel/#{booking.token}" }
-
- subject { described_class.from_booking(to, time_until_booking, booking, cancellation_url) }
+ specify { expect(described_class).to respond_to(:from_booking) }
it { is_expected.to be_a(described_class) }
diff --git a/spec/notify/notify_email/closed_onboarded_schools_summary_spec.rb b/spec/notify/notify_email/closed_onboarded_schools_summary_spec.rb
index 7f2b6c8047..c1e89c0d47 100644
--- a/spec/notify/notify_email/closed_onboarded_schools_summary_spec.rb
+++ b/spec/notify/notify_email/closed_onboarded_schools_summary_spec.rb
@@ -1,6 +1,6 @@
require 'rails_helper'
describe NotifyEmail::ClosedOnboardedSchoolsSummary do
- it_should_behave_like "email template", "a9547f2d-adb2-4cff-b9df-f2afc1ccbc66",
+ it_behaves_like "email template", "a9547f2d-adb2-4cff-b9df-f2afc1ccbc66",
closed_onboarded_schools: "data"
end
diff --git a/spec/notify/notify_email/school_add_availability_reminder_spec.rb b/spec/notify/notify_email/school_add_availability_reminder_spec.rb
index 671b760b70..89fa45af8c 100644
--- a/spec/notify/notify_email/school_add_availability_reminder_spec.rb
+++ b/spec/notify/notify_email/school_add_availability_reminder_spec.rb
@@ -1,5 +1,5 @@
require 'rails_helper'
describe NotifyEmail::SchoolAddAvailabilityReminder do
- it_should_behave_like "email template", "eee3d861-3365-40ff-a178-80516f771024"
+ it_behaves_like "email template", "eee3d861-3365-40ff-a178-80516f771024"
end
diff --git a/spec/notify/notify_email/school_booking_cancellation_spec.rb b/spec/notify/notify_email/school_booking_cancellation_spec.rb
index ca33a27c86..1f4d691e74 100644
--- a/spec/notify/notify_email/school_booking_cancellation_spec.rb
+++ b/spec/notify/notify_email/school_booking_cancellation_spec.rb
@@ -1,7 +1,7 @@
require 'rails_helper'
describe NotifyEmail::SchoolBookingCancellation do
- it_should_behave_like "email template", "1e0073e2-1334-4a50-a386-acc57f380e14",
+ it_behaves_like "email template", "1e0073e2-1334-4a50-a386-acc57f380e14",
school_name: "Springfield Elementary School",
candidate_name: "Otto Mann",
placement_start_date_with_duration: "2022-04-01 for 1 day"
diff --git a/spec/notify/notify_email/school_registration_confirmation_spec.rb b/spec/notify/notify_email/school_registration_confirmation_spec.rb
index 98cb4639bb..32c9d03846 100644
--- a/spec/notify/notify_email/school_registration_confirmation_spec.rb
+++ b/spec/notify/notify_email/school_registration_confirmation_spec.rb
@@ -1,7 +1,7 @@
require 'rails_helper'
describe NotifyEmail::SchoolRegistrationConfirmation do
- it_should_behave_like "email template", "9b32a2f9-47b7-4069-897b-5ce637c5d5ba",
+ it_behaves_like "email template", "9b32a2f9-47b7-4069-897b-5ce637c5d5ba",
school_experience_profile_link: "https://se.gov.uk/12345",
school_experience_dashboard_link: "https://se.gov.uk/12345/dashboard"
end
diff --git a/spec/notify/notify_email/school_request_cancellation_spec.rb b/spec/notify/notify_email/school_request_cancellation_spec.rb
index 375fd87b10..fcc32b0d83 100644
--- a/spec/notify/notify_email/school_request_cancellation_spec.rb
+++ b/spec/notify/notify_email/school_request_cancellation_spec.rb
@@ -1,7 +1,7 @@
require 'rails_helper'
describe NotifyEmail::SchoolRequestCancellation do
- it_should_behave_like "email template", "1d2b44bc-9d73-4839-b06b-41f35012c14d",
+ it_behaves_like "email template", "1d2b44bc-9d73-4839-b06b-41f35012c14d",
school_name: "Springfield Elementary School",
candidate_name: "Otto Mann",
cancellation_reasons: 'Spinal Tap playing same day',
diff --git a/spec/notify/notify_email/school_request_confirmation_link_only_spec.rb b/spec/notify/notify_email/school_request_confirmation_link_only_spec.rb
index d86c90d2c0..a615b5b3f6 100644
--- a/spec/notify/notify_email/school_request_confirmation_link_only_spec.rb
+++ b/spec/notify/notify_email/school_request_confirmation_link_only_spec.rb
@@ -1,7 +1,7 @@
require 'rails_helper'
describe NotifyEmail::SchoolRequestConfirmationLinkOnly do
- it_should_behave_like "email template", "2a5a54b8-17cb-4da8-94ce-1647d6bf1da3",
+ it_behaves_like "email template", "2a5a54b8-17cb-4da8-94ce-1647d6bf1da3",
school_name: "First School",
placement_request_url: "https://schoolexperience.education.gov.uk/test/request"
end
diff --git a/spec/notify/notify_email/school_user_invite_spec.rb b/spec/notify/notify_email/school_user_invite_spec.rb
index 386e93d2e4..9af09e4544 100644
--- a/spec/notify/notify_email/school_user_invite_spec.rb
+++ b/spec/notify/notify_email/school_user_invite_spec.rb
@@ -1,5 +1,5 @@
require 'rails_helper'
describe NotifyEmail::SchoolUserInvite do
- it_should_behave_like "email template", "8ac4d9f9-f51d-4c3b-9cc7-fd59751ece3d"
+ it_behaves_like "email template", "8ac4d9f9-f51d-4c3b-9cc7-fd59751ece3d"
end
diff --git a/spec/notify/notify_email/teacher_booking_cancellation_spec.rb b/spec/notify/notify_email/teacher_booking_cancellation_spec.rb
index 3c472b4520..50cab7b67f 100644
--- a/spec/notify/notify_email/teacher_booking_cancellation_spec.rb
+++ b/spec/notify/notify_email/teacher_booking_cancellation_spec.rb
@@ -1,7 +1,7 @@
require 'rails_helper'
describe NotifyEmail::TeacherBookingCancellation do
- it_should_behave_like "email template", "7445560b-46da-4c23-9017-e8d45b2a6c84",
+ it_behaves_like "email template", "7445560b-46da-4c23-9017-e8d45b2a6c84",
school_teacher_name: "Edna Krabappel",
school_name: "Springfield Elementary School",
candidate_name: "Dolph Starbeam",
diff --git a/spec/notify/notify_email/teacher_booking_confirmation_spec.rb b/spec/notify/notify_email/teacher_booking_confirmation_spec.rb
index 5b9bf4a7c7..1ab85699ce 100644
--- a/spec/notify/notify_email/teacher_booking_confirmation_spec.rb
+++ b/spec/notify/notify_email/teacher_booking_confirmation_spec.rb
@@ -1,7 +1,7 @@
require 'rails_helper'
describe NotifyEmail::TeacherBookingConfirmation do
- it_should_behave_like "email template", "a9e737f1-198c-4060-b341-b9485527c377",
+ it_behaves_like "email template", "a9e737f1-198c-4060-b341-b9485527c377",
candidate_name: "Dolph Starbeam",
placement_start_date: "2021-04-05",
placement_finish_date: "2021-04-10",
diff --git a/spec/notify/notify_service_spec.rb b/spec/notify/notify_service_spec.rb
index 945915a09a..97b11a8c7b 100644
--- a/spec/notify/notify_service_spec.rb
+++ b/spec/notify/notify_service_spec.rb
@@ -11,11 +11,11 @@
before do
stub_const 'NotifyService::API_KEY', api_key
- allow(described_class.instance).to receive(:notification_class) { Notifications::Client }
+ allow(described_class.instance).to receive(:notification_class).and_return(Notifications::Client)
stub_request(:post, endpoint).with(body: body).to_return(response)
end
- context '#send_email' do
+ describe '#send_email' do
let(:email_address) { 'test@example.com' }
let(:endpoint) { "https://api.notifications.service.gov.uk/v2/notifications/email" }
@@ -39,7 +39,7 @@
end
end
- context '#send_sms' do
+ describe '#send_sms' do
let(:endpoint) { "https://api.notifications.service.gov.uk/v2/notifications/sms" }
let(:phone_number) { '07777777777' }
diff --git a/spec/notify/notify_sms/candidate_booking_confirmation_spec.rb b/spec/notify/notify_sms/candidate_booking_confirmation_spec.rb
index 80acb9601b..c1ce21bd65 100644
--- a/spec/notify/notify_sms/candidate_booking_confirmation_spec.rb
+++ b/spec/notify/notify_sms/candidate_booking_confirmation_spec.rb
@@ -1,7 +1,7 @@
require 'rails_helper'
describe NotifySms::CandidateBookingConfirmation do
- it_should_behave_like "sms template", "c034e972-a9c6-4fae-924a-25ad8bf54031",
+ it_behaves_like "sms template", "c034e972-a9c6-4fae-924a-25ad8bf54031",
school_name: "Springfield Elementary School",
dates_requested: "16th January",
cancellation_url: 'https://example.com/candiates/cancel/abc-123'
diff --git a/spec/notify/notify_sms/candidate_booking_reminder_spec.rb b/spec/notify/notify_sms/candidate_booking_reminder_spec.rb
index 1aaab3b25c..fb0dc3e640 100644
--- a/spec/notify/notify_sms/candidate_booking_reminder_spec.rb
+++ b/spec/notify/notify_sms/candidate_booking_reminder_spec.rb
@@ -1,7 +1,7 @@
require 'rails_helper'
describe NotifySms::CandidateBookingReminder do
- it_should_behave_like "sms template", "10aa6a3b-bbe8-4e98-97b2-4409eef47496",
+ it_behaves_like "sms template", "10aa6a3b-bbe8-4e98-97b2-4409eef47496",
time_until_booking_descriptive: "tomorrow",
dates_requested: "16th January 2022",
cancellation_url: "https://example.com/candiates/cancel/abc-123"
diff --git a/spec/notify/notify_sms/candidate_booking_school_cancels_booking_spec.rb b/spec/notify/notify_sms/candidate_booking_school_cancels_booking_spec.rb
index f60e3fa81d..88d7fd9e67 100644
--- a/spec/notify/notify_sms/candidate_booking_school_cancels_booking_spec.rb
+++ b/spec/notify/notify_sms/candidate_booking_school_cancels_booking_spec.rb
@@ -1,7 +1,7 @@
require 'rails_helper'
describe NotifySms::CandidateBookingSchoolCancelsBooking do
- it_should_behave_like "sms template", "f4bbf2dc-5ebf-4723-8560-1266608e558d",
+ it_behaves_like "sms template", "f4bbf2dc-5ebf-4723-8560-1266608e558d",
school_name: "Springfield Elementary School",
dates_requested: '16th January 2022'
end
diff --git a/spec/presenters/candidates/placement_presenter_spec.rb b/spec/presenters/candidates/placement_presenter_spec.rb
index 4ae50d2cfd..1d0057f648 100644
--- a/spec/presenters/candidates/placement_presenter_spec.rb
+++ b/spec/presenters/candidates/placement_presenter_spec.rb
@@ -1,9 +1,10 @@
require 'rails_helper'
RSpec.describe Candidates::PlacementPresenter do
- let(:placement_request) { create(:placement_request) }
subject { described_class.new(placement_request) }
+ let(:placement_request) { create(:placement_request) }
+
describe '#date' do
context 'when placement is booked' do
let(:placement_request) { create(:placement_request, :booked) }
@@ -88,6 +89,7 @@
context 'when the booking is cancelled by the school' do
let(:placement_request) { create(:placement_request) }
+
before do
create(:bookings_booking, :accepted, :cancelled_by_school, bookings_placement_request: placement_request)
end
@@ -100,6 +102,7 @@
context 'when the booking is cancelled by the candidate' do
let(:placement_request) { create(:placement_request) }
+
before do
create(:bookings_booking, :accepted, :cancelled_by_candidate, bookings_placement_request: placement_request)
end
diff --git a/spec/presenters/candidates/school_presenter_spec.rb b/spec/presenters/candidates/school_presenter_spec.rb
index 8249eb9b4a..f74d5326f0 100644
--- a/spec/presenters/candidates/school_presenter_spec.rb
+++ b/spec/presenters/candidates/school_presenter_spec.rb
@@ -3,9 +3,10 @@
RSpec.describe Candidates::SchoolPresenter do
include ActiveSupport::Testing::TimeHelpers
+ subject { described_class.new(school, profile) }
+
let(:profile) { build(:bookings_profile) }
let(:school) { profile.school }
- subject { described_class.new(school, profile) }
describe ".school" do
it { expect(subject.school).to eql(school) }
@@ -59,11 +60,13 @@
context 'with booleans' do
before { profile.dress_code_business = true }
+
it { is_expected.to be true }
end
context 'with details' do
before { profile.dress_code_other_details = "lorem ipsum" }
+
it { is_expected.to be true }
end
@@ -86,6 +89,7 @@
context 'with content' do
before { profile.dress_code_other_details = 'lorem ipsum' }
+
it { is_expected.to match(/lorem ipsum<\/p>/) }
end
@@ -96,24 +100,27 @@
describe '#dbs_required' do
context 'when legacy profile' do
+ subject { described_class.new(school, legacy_profile).dbs_required }
+
let :legacy_profile do
build :bookings_profile, dbs_policy_conditions: nil, dbs_policy_details: nil
end
- subject { described_class.new(school, legacy_profile).dbs_required }
-
context 'when yes' do
before { legacy_profile.dbs_required = 'always' }
+
it { is_expected.to eql "Yes - Always" }
end
context 'when no' do
before { legacy_profile.dbs_required = 'never' }
+
it { is_expected.to eql "No - Candidates will be accompanied at all times" }
end
context 'when yes' do
before { legacy_profile.dbs_required = 'sometimes' }
+
it { is_expected.to eql "Yes - Sometimes" }
end
end
@@ -143,6 +150,8 @@
describe '#dbs_policy' do
context 'when legacy profile' do
+ subject { described_class.new(school, legacy_profile).dbs_policy }
+
let :legacy_profile do
build :bookings_profile,
dbs_policy_conditions: nil,
@@ -150,8 +159,6 @@
dbs_policy: 'Our DBS policy'
end
- subject { described_class.new(school, legacy_profile).dbs_policy }
-
it { is_expected.to eql 'Our DBS policy' }
end
diff --git a/spec/presenters/facet_tags_presenter_spec.rb b/spec/presenters/facet_tags_presenter_spec.rb
index 7890d65f24..761567d687 100644
--- a/spec/presenters/facet_tags_presenter_spec.rb
+++ b/spec/presenters/facet_tags_presenter_spec.rb
@@ -36,7 +36,7 @@
# Group 2: Three and Four
# Group 3: Five and (Six or Seven)
it do
- is_expected.to eq({
+ expect(subject).to eq({
"Group 1" => [
{ value: 1, text: "One", key: "key-1" },
{ value: 2, text: "Two", preposition: :or, key: "key-1" },
diff --git a/spec/presenters/schools/on_boarding/preview_presenter_spec.rb b/spec/presenters/schools/on_boarding/preview_presenter_spec.rb
index aa2fd2f179..f2ab0bbf79 100644
--- a/spec/presenters/schools/on_boarding/preview_presenter_spec.rb
+++ b/spec/presenters/schools/on_boarding/preview_presenter_spec.rb
@@ -7,7 +7,7 @@
create :bookings_school, :full_address, urn: 123_456
end
- context '#warning' do
+ describe '#warning' do
let :profile do
create :school_profile, bookings_school: school
end
diff --git a/spec/presenters/schools/on_boarding/school_profile_presenter_spec.rb b/spec/presenters/schools/on_boarding/school_profile_presenter_spec.rb
index b839cb1313..91b1e280cd 100644
--- a/spec/presenters/schools/on_boarding/school_profile_presenter_spec.rb
+++ b/spec/presenters/schools/on_boarding/school_profile_presenter_spec.rb
@@ -7,7 +7,7 @@
FactoryBot.create :bookings_school, :full_address, urn: 123_456
end
- context '#school_name' do
+ describe '#school_name' do
let :profile do
FactoryBot.create :school_profile, bookings_school: school
end
@@ -17,7 +17,7 @@
end
end
- context '#school_address' do
+ describe '#school_address' do
let :profile do
FactoryBot.build :school_profile, bookings_school: school
end
@@ -28,7 +28,7 @@
end
end
- context '#school_email' do
+ describe '#school_email' do
let :profile do
FactoryBot.build :school_profile, bookings_school: school
end
@@ -38,7 +38,7 @@
end
end
- context '#fees' do
+ describe '#fees' do
context 'with no fees' do
let :profile do
FactoryBot.build :school_profile
@@ -88,7 +88,7 @@
end
end
- context '#dbs_check' do
+ describe '#dbs_check' do
let :profile do
build :school_profile
end
@@ -141,7 +141,7 @@
end
end
- context '#individual_requirements' do
+ describe '#individual_requirements' do
context 'without requirements' do
let :profile do
FactoryBot.build :school_profile
@@ -172,7 +172,7 @@
end
end
- context '#school_experience_phases' do
+ describe '#school_experience_phases' do
context 'all phases selected' do
let :profile do
FactoryBot.build :school_profile, :with_phases
@@ -195,7 +195,7 @@
end
end
- context '#primary_key_stages_offered?' do
+ describe '#primary_key_stages_offered?' do
context 'when offered' do
let :profile do
FactoryBot.build \
@@ -203,7 +203,7 @@
end
it 'returns true' do
- expect(subject.primary_key_stages_offered?).to eq true
+ expect(subject.primary_key_stages_offered?).to be true
end
end
@@ -214,12 +214,12 @@
end
it 'returns false' do
- expect(subject.primary_key_stages_offered?).to eq false
+ expect(subject.primary_key_stages_offered?).to be false
end
end
end
- context '#primary_key_stages' do
+ describe '#primary_key_stages' do
context 'when primary phase not selected' do
let :profile do
FactoryBot.build \
@@ -244,7 +244,7 @@
end
end
- context '#subjects_offered?' do
+ describe '#subjects_offered?' do
context 'when offered' do
let :profile do
FactoryBot.build \
@@ -252,7 +252,7 @@
end
it 'returns true' do
- expect(subject.subjects_offered?).to eq true
+ expect(subject.subjects_offered?).to be true
end
end
@@ -262,12 +262,12 @@
end
it 'returns false' do
- expect(subject.subjects_offered?).to eq false
+ expect(subject.subjects_offered?).to be false
end
end
end
- context '#subjects' do
+ describe '#subjects' do
context 'when subjects not offered' do
let :profile do
FactoryBot.build :school_profile, :with_only_early_years_phase
@@ -289,7 +289,7 @@
end
end
- context '#descriptions' do
+ describe '#descriptions' do
let :profile do
FactoryBot.build :school_profile, :with_description
end
@@ -299,7 +299,7 @@
end
end
- context '#school_experience_details' do
+ describe '#school_experience_details' do
let :profile do
FactoryBot.build :school_profile, :with_experience_outline
end
@@ -309,7 +309,7 @@
end
end
- context '#dress_code' do
+ describe '#dress_code' do
context "when dress code options are selected" do
let(:profile) { build :school_profile, :with_candidate_dress_code }
@@ -329,7 +329,7 @@
end
end
- context '#parking' do
+ describe '#parking' do
context 'when parking is offered' do
let :profile do
FactoryBot.build :school_profile, :with_candidate_parking_information
@@ -352,7 +352,7 @@
end
end
- context '#start_time' do
+ describe '#start_time' do
let :profile do
FactoryBot.build :school_profile, :with_candidate_experience_schedule
end
@@ -362,7 +362,7 @@
end
end
- context '#end_time' do
+ describe '#end_time' do
let :profile do
FactoryBot.build :school_profile, :with_candidate_experience_schedule
end
@@ -372,7 +372,7 @@
end
end
- context '#flexible_on_times' do
+ describe '#flexible_on_times' do
context 'when flexible_on_times' do
let :profile do
FactoryBot.build :school_profile, \
@@ -396,7 +396,7 @@
end
end
- context '#admin_contact_email' do
+ describe '#admin_contact_email' do
let :profile do
FactoryBot.build :school_profile, :with_admin_contact
end
@@ -406,7 +406,7 @@
end
end
- context '#admin_contact_email_secondary' do
+ describe '#admin_contact_email_secondary' do
let :profile do
FactoryBot.build :school_profile, :with_admin_contact
end
@@ -416,7 +416,7 @@
end
end
- context '#admin_contact_phone' do
+ describe '#admin_contact_phone' do
let :profile do
FactoryBot.build :school_profile, :with_admin_contact
end
diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb
index 89ef72b8ff..b7f51cba4d 100644
--- a/spec/rails_helper.rb
+++ b/spec/rails_helper.rb
@@ -40,7 +40,7 @@
end
RSpec.configure do |config|
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
- config.fixture_path = "#{::Rails.root}/spec/fixtures"
+ config.fixture_path = Rails.root.join("spec", "fixtures").to_s
config.global_fixtures = :all
# If you're not using ActiveRecord, or you'd prefer not to run each of your
@@ -71,7 +71,7 @@
config.include FactoryBot::Syntax::Methods
# Prevent unintended API access from Geocoder
- config.before :each do
+ config.before do
allow(Geocoder).to receive(:search).and_return([
Geocoder::Result::Test.new(name: 'Bury', latitude: 53.4794892, longitude: -2.2451148, address_components: [long_name: "England"])
])
@@ -81,7 +81,7 @@
Feature.instance_variable_set(:@config, nil)
end
- config.before :each do
+ config.before do
Rails.cache.clear
end
diff --git a/spec/requests/basic_auth_spec.rb b/spec/requests/basic_auth_spec.rb
index b487864ca6..59a8bb391e 100644
--- a/spec/requests/basic_auth_spec.rb
+++ b/spec/requests/basic_auth_spec.rb
@@ -3,10 +3,10 @@
describe "Basic authentication", type: :request do
before do
allow(ENV).to receive(:[]).and_call_original
- allow(ENV).to receive(:[]).with("REDIS_URL") { "redis://localhost:6379/1" }
+ allow(ENV).to receive(:[]).with("REDIS_URL").and_return("redis://localhost:6379/1")
- allow(REDIS).to receive(:ping) { "PONG" }
- allow(ApplicationRecord).to receive(:connected?) { true }
+ allow(REDIS).to receive(:ping).and_return("PONG")
+ allow(ApplicationRecord).to receive(:connected?).and_return(true)
allow_any_instance_of(GetIntoTeachingApiClient::OperationsApi).to \
receive(:health_check) { GetIntoTeachingApiClient::HealthCheckResponse.new(status: "healthy") }
@@ -17,8 +17,8 @@
context "when the environment requires basic auth" do
before do
- allow(ENV).to receive(:[]).with("SECURE_USERNAME") { "user" }
- allow(ENV).to receive(:[]).with("SECURE_PASSWORD") { "pass" }
+ allow(ENV).to receive(:[]).with("SECURE_USERNAME").and_return("user")
+ allow(ENV).to receive(:[]).with("SECURE_PASSWORD").and_return("pass")
allow(Rails).to receive(:env) { "staging".inquiry }
end
diff --git a/spec/requests/cookie_banner_spec.rb b/spec/requests/cookie_banner_spec.rb
index 64a473e4f5..29d6f30c0b 100644
--- a/spec/requests/cookie_banner_spec.rb
+++ b/spec/requests/cookie_banner_spec.rb
@@ -12,6 +12,7 @@
context 'on subsequent visits (when the cookie_preference is present)' do
let(:preference) { CookiePreference.new(analytics: true) }
+
before { cookies[preference.cookie_key] = { value: preference.to_json } }
specify 'the page should not display the cookie banner' do
diff --git a/spec/requests/session_expired_spec.rb b/spec/requests/session_expired_spec.rb
index 2b5819377d..eebfe834e9 100644
--- a/spec/requests/session_expired_spec.rb
+++ b/spec/requests/session_expired_spec.rb
@@ -2,17 +2,17 @@
describe "Expired Session", type: :request do
context 'when InvalidAuthenticityToken is raised' do
+ subject(:perform_request) do
+ get candidates_root_path
+ response
+ end
+
before do
allow_any_instance_of(Candidates::HomeController).to receive(:index) do
raise ActionController::InvalidAuthenticityToken
end
end
- subject(:perform_request) do
- get candidates_root_path
- response
- end
-
it { is_expected.to have_http_status(:success) }
it { expect(perform_request.body).to include("Session expired") }
diff --git a/spec/requests/tracking_scripts_spec.rb b/spec/requests/tracking_scripts_spec.rb
index 7391e12348..6771245a81 100644
--- a/spec/requests/tracking_scripts_spec.rb
+++ b/spec/requests/tracking_scripts_spec.rb
@@ -1,15 +1,15 @@
require "rails_helper"
describe "Tracking Scripts", type: :request do
- let(:tracking_id) { "AAAAABBBBBCCCCCDDDDDEEEEE" }
-
- before { allow(ENV).to receive(:[]).and_call_original }
-
subject do
get root_path
response.body
end
+ let(:tracking_id) { "AAAAABBBBBCCCCCDDDDDEEEEE" }
+
+ before { allow(ENV).to receive(:[]).and_call_original }
+
describe "Google Tag Manager" do
let(:tracking_id_key) { "GTM_ID" }
let(:gtm_script) { %r{} }
@@ -27,7 +27,7 @@
context "When GTM_ID is not present in the environment" do
before do
- allow(ENV).to receive(:[]).with("GTM_ID") { "" }
+ allow(ENV).to receive(:[]).with("GTM_ID").and_return("")
end
it { is_expected.not_to match(gtm_script) }
diff --git a/spec/services/bookings/gitis/contact_fetcher_spec.rb b/spec/services/bookings/gitis/contact_fetcher_spec.rb
index 4a09038622..c072c74ad1 100644
--- a/spec/services/bookings/gitis/contact_fetcher_spec.rb
+++ b/spec/services/bookings/gitis/contact_fetcher_spec.rb
@@ -14,21 +14,25 @@
context 'correct merged' do
let(:contact) { build(:api_schools_experience_sign_up_with_name, :merged) }
+
it { is_expected.to be true }
end
context 'correct unmerged' do
let(:contact) { build(:api_schools_experience_sign_up_with_name) }
+
it { is_expected.to be false }
end
context 'merged without master' do
let(:contact) { build(:api_schools_experience_sign_up_with_name, :merged, master_id: nil) }
+
it { expect { subject }.to raise_exception described_class::InconsistentContactState }
end
context 'master but not merged' do
let(:contact) { build(:api_schools_experience_sign_up_with_name, :merged, merged: false) }
+
it { expect { subject }.to raise_exception described_class::InconsistentContactState }
end
end
@@ -76,9 +80,10 @@
end
context 'for single record' do
- let(:candidate) { create :candidate, gitis_uuid: merged.candidate_id }
subject { fetcher.assign_to_model candidate }
+ let(:candidate) { create :candidate, gitis_uuid: merged.candidate_id }
+
before do
allow_any_instance_of(GetIntoTeachingApiClient::SchoolsExperienceApi).to \
receive(:get_schools_experience_sign_up).with(first.candidate_id) { first }
@@ -90,28 +95,33 @@
receive(:get_schools_experience_sign_up).with(chained.candidate_id) { chained }
end
- it 'should locate the master contact record' do
- is_expected.to have_attributes gitis_contact: first
+ it 'locates the master contact record' do
+ expect(subject).to have_attributes gitis_contact: first
end
- it 'should not update the gitis UUID to match the master contact record' do
- is_expected.to have_attributes gitis_uuid: merged.candidate_id
+
+ it 'does not update the gitis UUID to match the master contact record' do
+ expect(subject).to have_attributes gitis_uuid: merged.candidate_id
end
+
it { is_expected.to have_attributes changes: {} }
context 'with chained records' do
let(:candidate) { create :candidate, gitis_uuid: chained.candidate_id }
- it 'should locate the master contact record' do
- is_expected.to have_attributes gitis_contact: first
+ it 'locates the master contact record' do
+ expect(subject).to have_attributes gitis_contact: first
end
- it 'should not update the gitis UUID to match the master contact record' do
- is_expected.to have_attributes gitis_uuid: chained.candidate_id
+
+ it 'does not update the gitis UUID to match the master contact record' do
+ expect(subject).to have_attributes gitis_uuid: chained.candidate_id
end
+
it { is_expected.to have_attributes changes: {} }
end
context 'with max chained records' do
let(:fourth) { build :api_schools_experience_sign_up_with_name, :merged, master_id: chained.candidate_id }
+ let(:candidate) { create :candidate, gitis_uuid: sixth.candidate_id }
let(:fifth) { build :api_schools_experience_sign_up_with_name, :merged, master_id: fourth.candidate_id }
let(:sixth) { build :api_schools_experience_sign_up_with_name, :merged, master_id: fifth.candidate_id }
@@ -124,14 +134,14 @@
receive(:get_schools_experience_sign_up).with(sixth.candidate_id) { sixth }
end
- let(:candidate) { create :candidate, gitis_uuid: sixth.candidate_id }
-
- it 'should locate the master contact record' do
- is_expected.to have_attributes gitis_contact: merged
+ it 'locates the master contact record' do
+ expect(subject).to have_attributes gitis_contact: merged
end
- it 'should not update the gitis UUID to match the master contact record' do
- is_expected.to have_attributes gitis_uuid: sixth.candidate_id
+
+ it 'does not update the gitis UUID to match the master contact record' do
+ expect(subject).to have_attributes gitis_uuid: sixth.candidate_id
end
+
it { is_expected.to have_attributes changes: {} }
end
end
@@ -160,12 +170,12 @@
context 'assigning multiple records' do
subject { fetcher.assign_to_models [candidate, second_candidate] }
- it "will update contact ids" do
+ it "updates contact ids" do
expect(subject.map(&:reload).map(&:gitis_uuid)).to \
eq [chained.candidate_id, second.candidate_id]
end
- it "will return expected contacts" do
+ it "returns expected contacts" do
expect(subject.map(&:gitis_contact)).to eq [first, second]
end
end
diff --git a/spec/services/bookings/gitis/missing_contact_spec.rb b/spec/services/bookings/gitis/missing_contact_spec.rb
index 9c823ac769..447485507b 100644
--- a/spec/services/bookings/gitis/missing_contact_spec.rb
+++ b/spec/services/bookings/gitis/missing_contact_spec.rb
@@ -1,9 +1,10 @@
require 'rails_helper'
describe Bookings::Gitis::MissingContact do
- let(:uuid) { SecureRandom.uuid }
subject { described_class.new uuid }
+ let(:uuid) { SecureRandom.uuid }
+
it { is_expected.to have_attributes contactid: uuid, id: uuid }
it { is_expected.to have_attributes firstname: 'Unavailable' }
it { is_expected.to have_attributes lastname: 'Unavailable' }
diff --git a/spec/services/bookings/gitis/school_experience_spec.rb b/spec/services/bookings/gitis/school_experience_spec.rb
index f2eb4d3834..8b842ca0f0 100644
--- a/spec/services/bookings/gitis/school_experience_spec.rb
+++ b/spec/services/bookings/gitis/school_experience_spec.rb
@@ -1,16 +1,21 @@
require 'rails_helper'
describe Bookings::Gitis::SchoolExperience, type: :model do
+ let(:subject_name) { "Maths" }
+ let(:subject_id) { 275_000_001 }
+ let(:gitis_id) { SecureRandom.uuid }
+
describe "validations" do
+ subject { described_class.from_placement_request(model, status) }
+
let(:model) { create(:placement_request, :booked) }
let(:status) { :requested }
- subject { described_class.from_placement_request(model, status) }
before { allow_any_instance_of(GetIntoTeachingApiClient::SchoolsExperienceApi).to receive(:add_school_experience) }
context "with valid arguments" do
it "does not throw error" do
- expect { subject }.to_not raise_error
+ expect { subject }.not_to raise_error
end
end
@@ -54,10 +59,6 @@
expect { described_class.new(any_args) }.to raise_exception NoMethodError
end
- let(:gitis_id) { SecureRandom.uuid }
- let(:subject_id) { 275_000_001 }
- let(:subject_name) { "Maths" }
-
shared_examples "a successful API post" do
before do
expect_any_instance_of(GetIntoTeachingApiClient::SchoolsExperienceApi)
@@ -75,6 +76,8 @@
end
context 'with a Bookings::PlacementRequest' do
+ subject { described_class.from_placement_request(placement_request, status) }
+
let(:status) { :requested }
let(:placement_request) { create(:placement_request, :with_incomplete_booking) }
@@ -86,8 +89,6 @@
)
end
- subject { described_class.from_placement_request(placement_request, status) }
-
context "with flexible dates" do
it_behaves_like "a successful API post"
end
@@ -95,6 +96,7 @@
context "with fixed dates" do
let(:placement_date) { create(:bookings_placement_date, bookings_school: placement_request.school) }
let(:date) { placement_date.date }
+
before do
expected_school_experience.date_of_school_experience = date
expected_school_experience.duration_of_placement_in_days = 1
@@ -106,6 +108,8 @@
end
context "with a Bookings::Booking" do
+ subject { described_class.from_booking(booking, status) }
+
let(:status) { :confirmed }
let(:booking) { create(:bookings_booking, :accepted) }
@@ -119,8 +123,6 @@
)
end
- subject { described_class.from_booking(booking, status) }
-
context "without existing subject" do
it_behaves_like "a successful API post"
end
@@ -128,6 +130,7 @@
context "with existing subject" do
let(:booking) { create(:bookings_booking, :with_existing_subject, :accepted) }
let(:subject_name) { booking.bookings_subject.name }
+
before do
expected_school_experience.teaching_subject_id = subject_id
end
@@ -137,6 +140,7 @@
context "when attended" do
let(:status) { :completed }
+
before do
booking.update!(attended: true)
expected_school_experience.status = 222_750_005
diff --git a/spec/services/bookings/gitis/subject_fetcher_spec.rb b/spec/services/bookings/gitis/subject_fetcher_spec.rb
index 9488794274..acd4f92555 100644
--- a/spec/services/bookings/gitis/subject_fetcher_spec.rb
+++ b/spec/services/bookings/gitis/subject_fetcher_spec.rb
@@ -2,6 +2,7 @@
describe Bookings::Gitis::SubjectFetcher do
subject { described_class }
+
let(:subject_name) { "Maths" }
let(:subject_id) { 275_000_001 }
let(:teaching_subjects) do
@@ -9,6 +10,7 @@
build(:api_teaching_subject, id: subject_id, value: subject_name),
]
end
+
before do
allow_any_instance_of(GetIntoTeachingApiClient::LookupItemsApi)
.to receive(:get_teaching_subjects).and_return(teaching_subjects)
diff --git a/spec/services/bookings/reminder_spec.rb b/spec/services/bookings/reminder_spec.rb
index edb1b4f190..5124c494c7 100644
--- a/spec/services/bookings/reminder_spec.rb
+++ b/spec/services/bookings/reminder_spec.rb
@@ -3,14 +3,14 @@
describe Bookings::Reminder, type: :request do
include ActiveJob::TestHelper
+ subject { described_class.new(booking, time_until_booking, time_until_booking_descriptive) }
+
let(:time_until_booking) { '3 weeks' }
let(:time_until_booking_descriptive) { 'in 3 weeks' }
let(:school) { create(:bookings_school, :onboarded) }
let(:booking) { create(:bookings_booking, :accepted, bookings_school: school, date: 3.weeks.from_now) }
- subject { Bookings::Reminder.new(booking, time_until_booking, time_until_booking_descriptive) }
-
- before { allow(Feature).to receive(:enabled?).with(:sms) { true } }
+ before { allow(Feature).to receive(:enabled?).with(:sms).and_return(true) }
describe '#deliver' do
it "queues an email and sms per provided booking" do
@@ -19,7 +19,7 @@
expect_any_instance_of(GetIntoTeachingApiClient::SchoolsExperienceApi).to \
receive(:get_schools_experience_sign_up).with(booking.contact_uuid) { sign_up }
- expect { subject.deliver }.to change { enqueued_jobs.size }.by(2)
+ expect { subject.deliver }.to change(enqueued_jobs, :size).by(2)
end
context "when it's an in school experience" do
diff --git a/spec/services/candidates/registrations/application_preview_spec.rb b/spec/services/candidates/registrations/application_preview_spec.rb
index acd9e5dec5..8ca38a5378 100644
--- a/spec/services/candidates/registrations/application_preview_spec.rb
+++ b/spec/services/candidates/registrations/application_preview_spec.rb
@@ -1,6 +1,10 @@
require 'rails_helper'
describe Candidates::Registrations::ApplicationPreview do
+ subject do
+ described_class.new registration_session
+ end
+
let :has_dbs_check do
true
end
@@ -69,86 +73,82 @@
'candidates_registrations_subject_and_date_information' => subject_and_date_information.attributes
end
- subject do
- described_class.new registration_session
- end
-
- context '#full_name' do
+ describe '#full_name' do
it 'returns the correct value' do
expect(subject.full_name).to eq "Testy McTest"
end
end
- context '#full_address' do
+ describe '#full_address' do
it 'returns the correct value' do
expect(subject.full_address).to eq \
"Test building, Test street, Test town, Testshire, TE57 1NG"
end
end
- context '#telephone_number' do
+ describe '#telephone_number' do
it 'returns the correct value' do
expect(subject.telephone_number).to eq "01234567890"
end
end
- context '#email_address' do
+ describe '#email_address' do
it 'returns the correct value' do
expect(subject.email_address).to eq "test@example.com"
end
end
- context '#school' do
+ describe '#school' do
it 'returns the correct value' do
expect(subject.school).to eq school
end
end
- context '#school_name' do
+ describe '#school_name' do
it 'returns the correct value' do
expect(subject.school_name).to eq "Test school"
end
end
- context '#placement_outcome' do
+ describe '#placement_outcome' do
it 'returns the correct value' do
expect(subject.placement_outcome).to eq "test the software"
end
end
- context '#degree_stage' do
+ describe '#degree_stage' do
it 'returns the correct value' do
expect(subject.degree_stage).to eq \
"I don't have a degree and am not studying for one"
end
end
- context '#degree_subject' do
+ describe '#degree_subject' do
it 'returns the correct value' do
expect(subject.degree_subject).to eq "Not applicable"
end
end
- context '#teaching_stage' do
+ describe '#teaching_stage' do
it 'returns the correct value' do
expect(subject.teaching_stage).to eq \
"I'm thinking about teaching and want to find out more"
end
end
- context '#teaching_subject_first_choice' do
+ describe '#teaching_subject_first_choice' do
it 'returns the correct value' do
expect(subject.teaching_subject_first_choice).to eq "Architecture"
end
end
- context '#teaching_subject_second_choice' do
+ describe '#teaching_subject_second_choice' do
it 'returns the correct value' do
expect(subject.teaching_subject_second_choice).to eq "Maths"
end
end
- context '#dbs_check_document' do
+ describe '#dbs_check_document' do
context 'with dbs check document' do
let :has_dbs_check do
true
@@ -183,7 +183,7 @@
availability_preference_fixed: false
end
- context '#has_subject_and_date_information?' do
+ describe '#has_subject_and_date_information?' do
context 'when school has flexible dates' do
let :school do
flexible_date_school
@@ -205,7 +205,7 @@
end
end
- context '#placement_date_subject' do
+ describe '#placement_date_subject' do
context 'when school has flexible dates' do
let :school do
flexible_date_school
@@ -229,7 +229,7 @@
end
end
- context '#placement_availability' do
+ describe '#placement_availability' do
context 'when school has flexible dates' do
let :school do
flexible_date_school
@@ -253,7 +253,7 @@
end
end
- context '#placement_date' do
+ describe '#placement_date' do
context 'when school has flexible dates' do
let :school do
flexible_date_school
@@ -277,7 +277,7 @@
end
end
- context '#placement_availability_description' do
+ describe '#placement_availability_description' do
context 'when school has flexible dates' do
let :school do
flexible_date_school
@@ -324,7 +324,7 @@
bookings_placement_date_id: placement_date.id
end
- context '#placement_availability_description' do
+ describe '#placement_availability_description' do
it 'returns the placement date' do
expect(subject.placement_availability_description).to \
eq placement_date.to_s
diff --git a/spec/services/candidates/registrations/availability_preference_spec.rb b/spec/services/candidates/registrations/availability_preference_spec.rb
index d726a27ef9..23a92f31ee 100644
--- a/spec/services/candidates/registrations/availability_preference_spec.rb
+++ b/spec/services/candidates/registrations/availability_preference_spec.rb
@@ -1,20 +1,20 @@
require 'rails_helper'
describe Candidates::Registrations::AvailabilityPreference, type: :model do
- it_behaves_like 'a registration step'
-
- include_context 'Stubbed candidates school'
-
let! :today do
Time.zone.today
end
+ it_behaves_like 'a registration step'
+
+ include_context 'Stubbed candidates school'
+
context 'attributes' do
it { is_expected.to respond_to :availability }
end
context 'validations' do
- before :each do
+ before do
availability_preference.validate
end
diff --git a/spec/services/candidates/registrations/contact_information_spec.rb b/spec/services/candidates/registrations/contact_information_spec.rb
index e018cd06ce..e90faa168a 100644
--- a/spec/services/candidates/registrations/contact_information_spec.rb
+++ b/spec/services/candidates/registrations/contact_information_spec.rb
@@ -15,9 +15,10 @@
context 'validations' do
context 'building' do
+ let(:too_long_msg) { 'Address line 1 must be 250 characters or fewer' }
+
it { is_expected.to validate_presence_of :building }
- let(:too_long_msg) { 'Address line 1 must be 250 characters or fewer' }
it { is_expected.to validate_length_of(:building).is_at_most(250).with_message(too_long_msg) }
end
@@ -40,16 +41,18 @@
end
context 'postcode' do
+ let(:too_long_msg) { 'Postcode must be 20 characters or fewer' }
+
it { is_expected.to validate_presence_of :postcode }
- 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) }
end
context 'phone' do
+ let(:too_long_msg) { 'Phone number must be 50 digits or fewer' }
+
it { is_expected.to validate_presence_of :phone }
- let(:too_long_msg) { 'Phone number must be 50 digits or fewer' }
it { is_expected.to validate_length_of(:phone).is_at_most(50).with_message(too_long_msg) }
context 'phone is present' do
@@ -60,6 +63,7 @@
context 'valid numbers' do
valid_numbers.each do |number|
subject { described_class.new phone: number }
+
before { subject.validate }
it "permits #{number}" do
@@ -71,6 +75,7 @@
context 'invalid numbers' do
invalid_numbers.each do |number|
subject { described_class.new phone: number }
+
before { subject.validate }
it "doesn't permit #{number}" do
@@ -82,6 +87,7 @@
context 'blank number' do
blank_numbers.each do |number|
subject { described_class.new phone: number }
+
before { subject.validate }
it "doesn't permit #{number}" do
@@ -94,6 +100,7 @@
context 'postcode is present' do
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 = [
@@ -118,6 +125,7 @@
context 'valid postcodes' do
valid_postcodes.each do |postcode|
subject { described_class.new postcode: postcode }
+
before { subject.validate }
it "permits #{postcode}" do
@@ -129,6 +137,7 @@
context 'invalid postcodes' do
invalid_postcodes.each do |postcode|
subject { described_class.new postcode: postcode }
+
before { subject.validate }
it "permits #{postcode}" do
@@ -140,6 +149,7 @@
context 'blank postcodes' do
blank_postcodes.each do |postcode|
subject { described_class.new postcode: postcode }
+
before { subject.validate }
it "permits #{postcode}" do
diff --git a/spec/services/candidates/registrations/education_spec.rb b/spec/services/candidates/registrations/education_spec.rb
index 947250f537..05b629bce9 100644
--- a/spec/services/candidates/registrations/education_spec.rb
+++ b/spec/services/candidates/registrations/education_spec.rb
@@ -14,7 +14,7 @@
it { is_expected.to validate_presence_of :degree_stage }
it do
- is_expected.to validate_inclusion_of(:degree_stage).in_array \
+ expect(subject).to validate_inclusion_of(:degree_stage).in_array \
described_class::OPTIONS_CONFIG.fetch 'DEGREE_STAGES'
end
@@ -37,7 +37,7 @@
end
it do
- is_expected.to validate_absence_of(:degree_subject)
+ expect(subject).to validate_absence_of(:degree_subject)
end
end
@@ -47,12 +47,12 @@
end
it do
- is_expected.to validate_presence_of(:degree_subject)
+ expect(subject).to validate_presence_of(:degree_subject)
end
end
end
- context '#requires_subject_for_degree_stage?' do
+ describe '#requires_subject_for_degree_stage?' do
let :result do
described_class.new.requires_subject_for_degree_stage? stage
end
diff --git a/spec/services/candidates/registrations/gitis_registration_session_spec.rb b/spec/services/candidates/registrations/gitis_registration_session_spec.rb
index 3e8a219b74..ed93c2703d 100644
--- a/spec/services/candidates/registrations/gitis_registration_session_spec.rb
+++ b/spec/services/candidates/registrations/gitis_registration_session_spec.rb
@@ -12,11 +12,13 @@
context 'with overridden data' do
let(:registration) { described_class.new(data_with_urn, contact) }
+
it { is_expected.to include(data) }
end
context 'with only gitis data' do
let(:registration) { described_class.new({}, contact) }
+
it { is_expected.to include(gitis_data) }
end
end
@@ -26,13 +28,14 @@
context 'with overridden data' do
let(:registration) { described_class.new(data_with_urn, contact) }
+
it { is_expected.to have_attributes(data) }
end
context 'with only gitis data' do
let(:registration) { described_class.new({}, contact) }
- it "will raise a missing step error" do
+ it "raises a missing step error" do
expect { registration.public_send(model_name.to_sym) }.to \
raise_exception Candidates::Registrations::RegistrationSession::StepNotFound
end
diff --git a/spec/services/candidates/registrations/personal_information_spec.rb b/spec/services/candidates/registrations/personal_information_spec.rb
index 838041202d..834e24ffaf 100644
--- a/spec/services/candidates/registrations/personal_information_spec.rb
+++ b/spec/services/candidates/registrations/personal_information_spec.rb
@@ -14,26 +14,28 @@
end
context 'validations' do
+ let(:too_long_msg) { 'Email must be 100 characters or fewer' }
+
it { is_expected.to validate_presence_of :first_name }
it { is_expected.to validate_presence_of :last_name }
it do
- is_expected.to validate_length_of(:first_name).is_at_most(50)
+ expect(subject).to validate_length_of(:first_name).is_at_most(50)
.with_message('First name must be 50 characters or fewer')
end
it do
- is_expected.to validate_length_of(:last_name).is_at_most(50)
+ expect(subject).to validate_length_of(:last_name).is_at_most(50)
.with_message('Last name must be 50 characters or fewer')
end
- let(:too_long_msg) { 'Email must be 100 characters or fewer' }
it { is_expected.to validate_presence_of :email }
it { is_expected.to validate_length_of(:email).is_at_most(100).with_message(too_long_msg) }
it { is_expected.to validate_email_format_of(:email) }
context 'when read only' do
subject { described_class.new read_only: true }
+
it { is_expected.not_to validate_presence_of :first_name }
it { is_expected.not_to validate_presence_of :last_name }
it { is_expected.to validate_presence_of :email }
@@ -41,6 +43,8 @@
end
describe "#issue_verification_code" do
+ subject { pinfo.issue_verification_code }
+
let(:pinfo) { build(:personal_information) }
let(:request) do
GetIntoTeachingApiClient::ExistingCandidateRequest.new(
@@ -50,8 +54,6 @@
)
end
- subject { pinfo.issue_verification_code }
-
before do
allow_any_instance_of(GetIntoTeachingApiClient::CandidatesApi).to \
receive(:create_candidate_access_token).with(request)
@@ -70,7 +72,7 @@
end
end
- context '#full_name' do
+ describe '#full_name' do
context 'when first_name last_name attributes are set' do
subject { described_class.new first_name: 'Testy', last_name: 'McTest' }
@@ -84,7 +86,7 @@
subject { described_class.new }
it 'returns nil' do
- expect(subject.full_name).to eq nil
+ expect(subject.full_name).to be_nil
end
end
@@ -99,6 +101,8 @@
end
describe 'with read_only set to true' do
+ subject { pinfo }
+
let(:pinfo) { described_class.new(read_only: true) }
before do
@@ -108,8 +112,6 @@
email: 'test@test.com'
end
- subject { pinfo }
-
it { is_expected.to have_attributes first_name: nil }
it { is_expected.to have_attributes last_name: nil }
it { is_expected.to have_attributes email: nil }
diff --git a/spec/services/candidates/registrations/placement_preference_spec.rb b/spec/services/candidates/registrations/placement_preference_spec.rb
index efdbcbf52d..f82b3666dc 100644
--- a/spec/services/candidates/registrations/placement_preference_spec.rb
+++ b/spec/services/candidates/registrations/placement_preference_spec.rb
@@ -1,21 +1,21 @@
require 'rails_helper'
describe Candidates::Registrations::PlacementPreference, type: :model do
- it_behaves_like 'a registration step'
-
- include_context 'Stubbed candidates school'
-
let! :today do
Time.zone.today
end
+ it_behaves_like 'a registration step'
+
+ include_context 'Stubbed candidates school'
+
context 'attributes' do
it { is_expected.to respond_to :urn }
it { is_expected.to respond_to :objectives }
end
context 'validations' do
- before :each do
+ before do
placement_preference.validate
end
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 25ed240b79..dfba4e2f1a 100644
--- a/spec/services/candidates/registrations/registration_as_placement_request_spec.rb
+++ b/spec/services/candidates/registrations/registration_as_placement_request_spec.rb
@@ -1,9 +1,10 @@
require 'rails_helper'
describe Candidates::Registrations::RegistrationAsPlacementRequest do
- let(:urn) { 11_048 }
subject { described_class.new session }
+ let(:urn) { 11_048 }
+
pii = {
"full_name" => 'Testy McTest',
"email" => 'test@example.com',
@@ -15,7 +16,7 @@
"phone" => "01234567890"
}.freeze
- context '#attributes' do
+ describe '#attributes' do
context 'when flexible dates' do
let(:school) { create(:bookings_school, urn: urn) }
@@ -41,9 +42,9 @@
context 'PII' do
# Redundant given the next spec, but going for clarity!
- pii.each do |k, _|
+ pii.each_key do |k|
it "removes #{k}" do
- expect(subject.attributes[k]).to eq nil
+ expect(subject.attributes[k]).to be_nil
end
end
end
@@ -90,9 +91,9 @@
context 'PII' do
# Redundant given the next spec, but going for clarity!
- pii.each do |k, _|
+ pii.each_key do |k|
it "removes #{k}" do
- expect(subject.attributes[k]).to eq nil
+ expect(subject.attributes[k]).to be_nil
end
end
end
diff --git a/spec/services/candidates/registrations/registration_session_spec.rb b/spec/services/candidates/registrations/registration_session_spec.rb
index aad2aac8b7..2d722d57c4 100644
--- a/spec/services/candidates/registrations/registration_session_spec.rb
+++ b/spec/services/candidates/registrations/registration_session_spec.rb
@@ -9,7 +9,7 @@
allow(DateTime).to receive(:now) { date }
end
- context '#initialize' do
+ describe '#initialize' do
before do
described_class.new session
end
@@ -35,7 +35,7 @@
end
end
- context '#save' do
+ describe '#save' do
let :session do
{ 'some' => 'information' }
end
@@ -63,9 +63,9 @@
end
end
- context '#uuid' do
+ describe '#uuid' do
before do
- allow(SecureRandom).to receive(:urlsafe_base64) { 'sekret' }
+ allow(SecureRandom).to receive(:urlsafe_base64).and_return('sekret')
end
context 'when uuid not already set' do
@@ -81,7 +81,7 @@
end
end
- context '#education_attributes' do
+ describe '#education_attributes' do
context 'when education is not in session' do
subject { described_class.new({}) }
@@ -100,7 +100,7 @@
end
end
- context '#education' do
+ describe '#education' do
context 'when not education in session' do
subject { described_class.new({}) }
@@ -110,13 +110,14 @@
end
context 'when education in session' do
+ subject { session.education }
+
let :session do
FactoryBot.build :registration_session, :with_education
end
- subject { session.education }
-
it { is_expected.to be_a Candidates::Registrations::Education }
+
it do
expect(subject.attributes.except('created_at', 'updated_at')).to \
eq FactoryBot.build(:education).attributes.except('created_at', 'updated_at')
@@ -124,7 +125,7 @@
end
end
- context '#teaching_preference_attributes' do
+ describe '#teaching_preference_attributes' do
context 'when teaching_preference is not in session' do
subject { described_class.new({}) }
@@ -143,7 +144,7 @@
end
end
- context '#teaching_preference' do
+ describe '#teaching_preference' do
context 'when teaching_preference is not in the session' do
subject { described_class.new({}) }
@@ -153,13 +154,13 @@
end
context 'when teaching_preference is in the session' do
+ subject { session.teaching_preference }
+
let :session do
FactoryBot.build \
:registration_session, :with_teaching_preference, :with_school
end
- subject { session.teaching_preference }
-
it { is_expected.to be_a Candidates::Registrations::TeachingPreference }
it do
@@ -173,7 +174,7 @@
end
end
- context '#pending_email_confirmation?' do
+ describe '#pending_email_confirmation?' do
context 'when not pending email confirmation' do
it 'returns false' do
expect(described_class.new({})).not_to be_pending_email_confirmation
@@ -189,14 +190,15 @@
end
end
- context '#flag_as_pending_email_confirmation!' do
+ describe '#flag_as_pending_email_confirmation!' do
context 'when registration is not complete' do
- let(:urn) { 11_048 }
- let!(:school) { create(:bookings_school, urn: 11_048) }
subject do
described_class.new("urn" => urn)
end
+ let(:urn) { 11_048 }
+ let!(:school) { create(:bookings_school, urn: 11_048) }
+
it 'raises an error' do
expect { subject.flag_as_pending_email_confirmation! }.to \
raise_error described_class::NotCompletedError
@@ -220,7 +222,7 @@
end
end
- context '#fetch' do
+ describe '#fetch' do
let :session do
{
'urn' => '11048',
@@ -244,7 +246,7 @@
end
end
- context '#completed?' do
+ describe '#completed?' do
context 'not completed' do
let :session do
{}
@@ -266,7 +268,7 @@
end
end
- context '#flag_as_completed!' do
+ describe '#flag_as_completed!' do
include_context 'Stubbed candidates school'
let :registration_session do
@@ -304,20 +306,20 @@
bookings_placement_date_id: placement_date.id
end
- context '#placement_preference' do
+ describe '#placement_preference' do
it 'returns a valid instance' do
expect(registration_session.placement_preference).to be_valid
end
end
- context '#subject_and_date_information' do
+ describe '#subject_and_date_information' do
let :subject_and_date_information do
registration_session.subject_and_date_information
end
it 'returns an instance with non subject specific date' do
expect(subject_and_date_information.placement_date).to eq placement_date
- expect(subject_and_date_information.placement_date_subject).to be nil
+ expect(subject_and_date_information.placement_date_subject).to be_nil
end
end
end
diff --git a/spec/services/candidates/registrations/registration_state_spec.rb b/spec/services/candidates/registrations/registration_state_spec.rb
index 63661ca43c..92d0ba6d8a 100644
--- a/spec/services/candidates/registrations/registration_state_spec.rb
+++ b/spec/services/candidates/registrations/registration_state_spec.rb
@@ -1,6 +1,8 @@
require 'rails_helper'
describe Candidates::Registrations::RegistrationState do
+ subject { described_class.new registration_session }
+
let :school do
create :bookings_school, urn: 11_048
end
@@ -13,9 +15,7 @@
create :bookings_school, availability_preference_fixed: true
end
- subject { described_class.new registration_session }
-
- context '#steps' do
+ describe '#steps' do
context 'for a school with flexible dates' do
let :registration_session do
build :registration_session, urn: school_with_flexible_dates.urn, with: []
diff --git a/spec/services/candidates/registrations/registration_store_spec.rb b/spec/services/candidates/registrations/registration_store_spec.rb
index bd8f22e3a0..0ca3f0941c 100644
--- a/spec/services/candidates/registrations/registration_store_spec.rb
+++ b/spec/services/candidates/registrations/registration_store_spec.rb
@@ -1,6 +1,8 @@
require 'rails_helper'
describe Candidates::Registrations::RegistrationStore do
+ subject { described_class.instance }
+
let :redis do
REDIS
end
@@ -9,9 +11,7 @@
FactoryBot.build :registration_session, uuid: 'sekret'
end
- subject { described_class.instance }
-
- context '#store!' do
+ describe '#store!' do
let! :returned_uuid do
subject.store! session
end
@@ -26,9 +26,9 @@
end
end
- context '#store! with a blank key' do
+ describe '#store! with a blank key' do
before do
- allow(session).to receive(:uuid) { nil }
+ allow(session).to receive(:uuid).and_return(nil)
end
it 'raises an error' do
@@ -38,7 +38,7 @@
end
end
- context '#get!' do
+ describe '#get!' do
before do
subject.store! session
end
@@ -62,7 +62,7 @@
end
end
- context '#delete!' do
+ describe '#delete!' do
before do
subject.store! session
end
@@ -80,25 +80,25 @@
end
it 'removes the key from redis' do
- expect(redis.get("test:registrations:sekret")).to eq nil
+ expect(redis.get("test:registrations:sekret")).to be_nil
end
end
end
- context '#has_registration?' do
+ describe '#has_registration?' do
let! :returned_uuid do
subject.store! session
end
context 'when registration does not exist' do
it 'returns false' do
- expect(subject.has_registration?('bad-uuid')).to eq false
+ expect(subject.has_registration?('bad-uuid')).to be false
end
end
context 'when registration exists' do
it 'returns true' do
- expect(subject.has_registration?(session.uuid)).to eq true
+ expect(subject.has_registration?(session.uuid)).to be true
end
end
end
diff --git a/spec/services/candidates/registrations/subject_and_date_information_spec.rb b/spec/services/candidates/registrations/subject_and_date_information_spec.rb
index e934a9cff1..903fff5c09 100644
--- a/spec/services/candidates/registrations/subject_and_date_information_spec.rb
+++ b/spec/services/candidates/registrations/subject_and_date_information_spec.rb
@@ -17,38 +17,40 @@
end
describe 'validations' do
- let(:school) { create(:bookings_school, availability_preference_fixed: true) }
subject { described_class.new(urn: school.urn) }
+ let(:school) { create(:bookings_school, availability_preference_fixed: true) }
+
describe 'when the associated school has fixed availability' do
before { subject.urn = create(:bookings_school, :with_fixed_availability_preference).urn }
+
it { is_expected.to validate_presence_of(:bookings_placement_date_id) }
end
describe '#bookings_placement_dates_subject_id' do
context 'when the placement date is not subject-specific' do
- let(:placement_date) { create(:bookings_placement_date, subject_specific: false) }
-
subject do
described_class.new \
urn: school.urn,
bookings_placement_date_id: placement_date.id
end
+ let(:placement_date) { create(:bookings_placement_date, subject_specific: false) }
+
it { is_expected.not_to validate_presence_of :bookings_subject_id }
end
context 'when the placement date is subject-specific' do
let(:maths) { Bookings::Subject.find_by(name: 'Maths') }
- let(:english) { Bookings::Subject.find_by(name: 'English') }
- before { school.subjects << [maths] }
-
let(:placement_date) do
build(:bookings_placement_date, bookings_school: school, subject_specific: true).tap do |bpd|
bpd.subjects << maths
bpd.save
end
end
+ let(:english) { Bookings::Subject.find_by(name: 'English') }
+
+ before { school.subjects << [maths] }
context 'and no date subject specified' do
subject do
@@ -58,7 +60,7 @@
end
specify 'should validate the presence of bookings_subject_id' do
- is_expected.to \
+ expect(subject).to \
validate_presence_of(:bookings_subject_id)
.with_message('Choose a subject')
end
@@ -76,7 +78,7 @@
end
specify 'should validate the presence of bookings_placement_date_subject' do
- is_expected.not_to be_valid
+ expect(subject).not_to be_valid
expect(subject.errors.full_messages).to include('Choose a subject')
end
end
@@ -86,10 +88,12 @@
describe 'methods' do
describe '#placement_date' do
- it { is_expected.to respond_to(:placement_date) }
+ before do
+ allow(Bookings::PlacementDate).to receive(:find_by).and_return('a')
+ allow(subject).to receive(:bookings_placement_date_id).and_return(1)
+ end
- before { allow(subject).to receive(:bookings_placement_date_id).and_return(1) }
- before { allow(Bookings::PlacementDate).to receive(:find_by).and_return('a') }
+ it { is_expected.to respond_to(:placement_date) }
specify 'should find the placement date via its id' do
subject.placement_date
@@ -98,14 +102,13 @@
end
describe '#placement_date_subject' do
- it { is_expected.to respond_to(:placement_date_subject) }
-
before do
+ allow(Bookings::PlacementDateSubject).to receive(:find_by).and_return('a')
subject.bookings_placement_date_id = 1
subject.bookings_subject_id = 2
end
- before { allow(Bookings::PlacementDateSubject).to receive(:find_by).and_return('a') }
+ it { is_expected.to respond_to(:placement_date_subject) }
specify 'should find the placement date via its id' do
subject.placement_date_subject
@@ -117,10 +120,6 @@
end
describe '#date_and_subject_ids' do
- it { is_expected.to respond_to(:placement_date_subject) }
-
- let!(:bookings_placement_date) { create :bookings_placement_date, bookings_school: school }
- let!(:bookings_subject) { create :bookings_subject, schools: [school] }
let!(:bookings_placement_dates_subject) do
create(
:bookings_placement_date_subject,
@@ -128,12 +127,16 @@
bookings_subject: bookings_subject
)
end
+ let!(:bookings_subject) { create :bookings_subject, schools: [school] }
+ let!(:bookings_placement_date) { create :bookings_placement_date, bookings_school: school }
before do
subject.bookings_placement_date_id = bookings_placement_date.id
subject.bookings_subject_id = bookings_subject.id
end
+ it { is_expected.to respond_to(:placement_date_subject) }
+
specify 'should join the placement date and placement date subject ids separated by an underscore' do
expect(subject.date_and_subject_ids).to eql(bookings_placement_dates_subject.date_and_subject_id)
end
@@ -165,6 +168,7 @@
describe '#has_primary_dates?' do
subject { described_class.new }
+
context 'when primary dates are present' do
before { allow(subject).to receive(:primary_placement_dates).and_return(%w[yes]) }
@@ -180,6 +184,7 @@
describe '#has_secondary_dates?' do
subject { described_class.new }
+
context 'when secondary dates are present' do
before { allow(subject).to receive(:secondary_placement_dates_grouped_by_date).and_return(%w[yes]) }
@@ -195,16 +200,19 @@
describe '#has_primary_and_secondary_dates?' do
subject { described_class.new }
+
context 'when secondary dates are present' do
- before { allow(subject).to receive(:primary_placement_dates).and_return(%w[yes]) }
- before { allow(subject).to receive(:secondary_placement_dates_grouped_by_date).and_return(%w[yes]) }
+ before do
+ allow(subject).to receive_messages(primary_placement_dates: %w[yes], secondary_placement_dates_grouped_by_date: %w[yes])
+ end
it { is_expected.to have_primary_and_secondary_dates }
end
context 'when no secondary dates are present' do
- before { allow(subject).to receive(:secondary_placement_dates_grouped_by_date).and_return({}) }
- before { allow(subject).to receive(:primary_placement_dates).and_return([]) }
+ before do
+ allow(subject).to receive_messages(secondary_placement_dates_grouped_by_date: {}, primary_placement_dates: [])
+ end
it { is_expected.not_to have_primary_and_secondary_dates }
end
diff --git a/spec/services/candidates/registrations/teaching_preference_spec.rb b/spec/services/candidates/registrations/teaching_preference_spec.rb
index 29e52e8af2..45a4648e62 100644
--- a/spec/services/candidates/registrations/teaching_preference_spec.rb
+++ b/spec/services/candidates/registrations/teaching_preference_spec.rb
@@ -1,11 +1,11 @@
require 'rails_helper'
describe Candidates::Registrations::TeachingPreference, type: :model do
+ subject { described_class.new school: school }
+
include_context 'Stubbed candidates school'
it_behaves_like 'a registration step'
- subject { described_class.new school: school }
-
context 'attriubtes' do
it { is_expected.to respond_to :school }
it { is_expected.to respond_to :teaching_stage }
@@ -17,21 +17,21 @@
it { is_expected.to validate_presence_of :teaching_stage }
it do
- is_expected.to validate_inclusion_of(:teaching_stage).in_array \
+ expect(subject).to validate_inclusion_of(:teaching_stage).in_array \
described_class::OPTIONS_CONFIG.fetch('TEACHING_STAGES')
end
it { is_expected.to validate_presence_of :subject_first_choice }
it do
- is_expected.to validate_inclusion_of(:subject_first_choice).in_array \
+ expect(subject).to validate_inclusion_of(:subject_first_choice).in_array \
allowed_subject_choices
end
it { is_expected.to validate_presence_of :subject_second_choice }
it do
- is_expected.to validate_inclusion_of(:subject_second_choice).in_array \
+ expect(subject).to validate_inclusion_of(:subject_second_choice).in_array \
second_subject_choices
end
@@ -39,16 +39,16 @@
before { subject.subject_first_choice = "Biology" }
it "allows second choice to be a different value" do
- is_expected.to allow_value("Chemistry").for :subject_second_choice
+ expect(subject).to allow_value("Chemistry").for :subject_second_choice
end
it "returns a validation error when second subject has the same value" do
- is_expected.to_not allow_value("Biology").for :subject_second_choice
+ expect(subject).not_to allow_value("Biology").for :subject_second_choice
end
end
end
- context '#available_subject_choices' do
+ describe '#available_subject_choices' do
context 'when the school has subjects' do
before do
school.subjects << FactoryBot.build_list(:bookings_subject, 8)
@@ -68,7 +68,7 @@
end
end
- context '#second_subject_choices' do
+ describe '#second_subject_choices' do
it "returns the list of subjects from it's school" do
choices = subject.second_subject_choices
no_choice = choices.shift
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 56c35ab326..86e07c8a25 100644
--- a/spec/services/schools/dfe_sign_in_api/client_spec.rb
+++ b/spec/services/schools/dfe_sign_in_api/client_spec.rb
@@ -50,11 +50,13 @@ def endpoint
end
describe '.role_check_enabled?' do
- before { allow(Feature).to receive(:enabled?).with(:rolecheck) { true } }
+ before { allow(Feature).to receive(:enabled?).with(:rolecheck).and_return(true) }
context 'when the client is disabled' do
- before { allow(subject).to receive(:enabled?).and_return(false) }
- before { allow(ENV).to receive(:fetch).and_return(true) }
+ before do
+ allow(subject).to receive(:enabled?).and_return(false)
+ allow(ENV).to receive(:fetch).and_return(true)
+ end
specify 'should be disabled' do
expect(subject).not_to be_role_check_enabled
@@ -63,11 +65,14 @@ def endpoint
context 'when the client is enabled' do
subject { described_class }
- before { allow(subject).to receive(:enabled?).and_return(true) }
- before { allow(Rails.application.config.x).to receive(:dfe_sign_in_api_role_check_enabled).and_return(true) }
+
+ before do
+ allow(subject).to receive(:enabled?).and_return(true)
+ allow(Rails.application.config.x).to receive(:dfe_sign_in_api_role_check_enabled).and_return(true)
+ end
context 'when role check is disabled' do
- before { allow(Feature).to receive(:enabled?).with(:rolecheck) { false } }
+ before { allow(Feature).to receive(:enabled?).with(:rolecheck).and_return(false) }
context 'when the DfE Sign-in role and service environment variables are absent' do
before { allow(ENV).to receive(:fetch).and_return(nil) }
@@ -99,18 +104,18 @@ def endpoint
end
describe 'error handling' do
+ subject { TestAPI.new.data }
+
let(:testdata) { { hello: 'world' } }
let(:apihost) { "https://some-test-api-host.signin.education.gov.uk" }
before do
allow(ENV).to receive(:fetch).and_return('123')
- allow(Schools::DFESignInAPI::Client).to \
+ allow(described_class).to \
receive(:enabled?).and_return true
end
- subject { TestAPI.new.data }
-
{
400 => Faraday::ClientError,
404 => Faraday::ResourceNotFound,
@@ -157,7 +162,7 @@ def endpoint
.to_timeout
end
- it 'will raise an error' do
+ it 'raises an error' do
expect { subject }.to raise_exception Faraday::ConnectionFailed
end
end
diff --git a/spec/services/schools/dfe_sign_in_api/organisation_spec.rb b/spec/services/schools/dfe_sign_in_api/organisation_spec.rb
index 36ed77eb23..8982968f77 100644
--- a/spec/services/schools/dfe_sign_in_api/organisation_spec.rb
+++ b/spec/services/schools/dfe_sign_in_api/organisation_spec.rb
@@ -2,6 +2,8 @@
require Rails.root.join("spec", "controllers", "schools", "session_context")
describe Schools::DFESignInAPI::Organisation do
+ subject { described_class.new(user_uuid, current_school_urn) }
+
include_context "logged in DfE user"
let(:user_uuid) { '123456' }
@@ -15,8 +17,6 @@
end
let(:response) { organisations_data }
- subject { described_class.new(user_uuid, current_school_urn) }
-
before do
allow(subject).to receive(:response).and_return(response)
end
diff --git a/spec/services/schools/dfe_sign_in_api/organisations_spec.rb b/spec/services/schools/dfe_sign_in_api/organisations_spec.rb
index 36d1652fae..b8a09d8101 100644
--- a/spec/services/schools/dfe_sign_in_api/organisations_spec.rb
+++ b/spec/services/schools/dfe_sign_in_api/organisations_spec.rb
@@ -2,6 +2,8 @@
require Rails.root.join("spec", "controllers", "schools", "session_context")
describe Schools::DFESignInAPI::Organisations do
+ subject { described_class.new(user_guid) }
+
include_context "logged in DfE user"
let(:uuid_map) do
@@ -10,8 +12,6 @@
end
end
- subject { Schools::DFESignInAPI::Organisations.new(user_guid) }
-
before do
allow(described_class).to receive(:enabled?).and_return(true)
allow(ENV).to receive(:fetch).and_return('123')
@@ -48,7 +48,7 @@
end
describe 'error_handling' do
- subject { Schools::DFESignInAPI::Organisations.new(user_guid) }
+ subject { described_class.new(user_guid) }
describe 'when an invalid response is returned' do
before do
diff --git a/spec/services/schools/dfe_sign_in_api/role_checked_organisations_spec.rb b/spec/services/schools/dfe_sign_in_api/role_checked_organisations_spec.rb
index 2c64471d7d..94f65aa0c3 100644
--- a/spec/services/schools/dfe_sign_in_api/role_checked_organisations_spec.rb
+++ b/spec/services/schools/dfe_sign_in_api/role_checked_organisations_spec.rb
@@ -1,6 +1,8 @@
require 'rails_helper'
describe Schools::DFESignInAPI::RoleCheckedOrganisations, type: :model do
+ subject { described_class.new(user_uuid) }
+
let(:user_uuid) { SecureRandom.uuid }
let(:org1) { SecureRandom.uuid }
let(:org2) { SecureRandom.uuid }
@@ -25,11 +27,9 @@
{ double(rolecheck, has_school_experience_role?: true) }
end
- subject { described_class.new(user_uuid) }
-
describe '#organisation_uuid_pairs' do
- it "should only include uuids the user has a role over" do
- is_expected.to have_attributes \
+ it "onlies include uuids the user has a role over" do
+ expect(subject).to have_attributes \
organisation_uuid_pairs: { org1 => 1, org3 => 3 }
end
end
@@ -47,7 +47,7 @@
describe '#organisation_uuid_pairs' do
it "includes all uuids" do
- is_expected.to have_attributes \
+ expect(subject).to have_attributes \
organisation_uuid_pairs: { org1 => 1, org2 => 2, org3 => 3, org4 => 4 }
end
end
diff --git a/spec/services/schools/dfe_sign_in_api/roles_spec.rb b/spec/services/schools/dfe_sign_in_api/roles_spec.rb
index 32b950fb25..3fe923a0bb 100644
--- a/spec/services/schools/dfe_sign_in_api/roles_spec.rb
+++ b/spec/services/schools/dfe_sign_in_api/roles_spec.rb
@@ -2,9 +2,10 @@
require Rails.root.join("spec", "controllers", "schools", "session_context")
describe Schools::DFESignInAPI::Roles do
- include_context "logged in DfE user"
subject { described_class.new(user_guid, dfe_signin_school_id) }
+ include_context "logged in DfE user"
+
before do
allow_any_instance_of(Schools::DFESignInAPI::Client).to receive(:enabled?).and_return(true)
allow_any_instance_of(Schools::DFESignInAPI::Client).to receive(:role_check_enabled?).and_return(true)
@@ -14,7 +15,7 @@
expect(subject).to respond_to(:has_school_experience_role?)
end
- context '#has_school_experience_role?' do
+ describe '#has_school_experience_role?' do
context 'when the role is present' do
specify 'should return true when the role is present' do
expect(subject.has_school_experience_role?).to be true
@@ -30,7 +31,10 @@
end
context 'when the user is not associated with the organisation' do
+ subject { described_class.new(user_guid, org_uuid) }
+
let(:org_uuid) { SecureRandom.uuid }
+
before do
stub_request(:get, "https://some-signin-host.signin.education.gov.uk/services/#{dfe_signin_admin_service_id}/organisations/#{org_uuid}/users/#{user_guid}")
.to_return(
@@ -40,17 +44,16 @@
)
end
- subject { described_class.new(user_guid, org_uuid) }
-
specify "should raise an 'no organisation' error" do
expect(subject.has_school_experience_role?).to be false
end
end
context 'when no result is returned' do
- before { allow(subject).to receive(:response).and_return(nil) }
subject { described_class.new(user_guid, dfe_signin_school_urn) }
+ before { allow(subject).to receive(:response).and_return(nil) }
+
specify "should raise an 'invalid response' error" do
expect { subject.has_school_experience_role? }.to raise_error(Schools::DFESignInAPI::APIResponseError, /invalid response from roles API/)
end
diff --git a/spec/support/feedback_shared_examples.rb b/spec/support/feedback_shared_examples.rb
index a8e91ab30a..9133b0207f 100644
--- a/spec/support/feedback_shared_examples.rb
+++ b/spec/support/feedback_shared_examples.rb
@@ -1,13 +1,13 @@
shared_examples 'a feedback' do
context 'attributes' do
it do
- is_expected.to have_db_column(:reason_for_using_service)
+ expect(subject).to have_db_column(:reason_for_using_service)
.of_type(:integer)
.with_options(null: false)
end
it do
- is_expected.to have_db_column(:rating)
+ expect(subject).to have_db_column(:rating)
.of_type(:integer)
.with_options(null: false)
end
@@ -17,7 +17,7 @@
context 'validations' do
it do
- is_expected.to validate_presence_of(:reason_for_using_service)
+ expect(subject).to validate_presence_of(:reason_for_using_service)
end
it { is_expected.to validate_presence_of(:rating) }
@@ -26,14 +26,14 @@
subject { described_class.new(reason_for_using_service: :something_else) }
it do
- is_expected.to \
+ expect(subject).to \
validate_presence_of :reason_for_using_service_explanation
end
end
context 'when reason does not require explanation' do
it do
- is_expected.not_to \
+ expect(subject).not_to \
validate_presence_of :reason_for_using_service_explanation
end
end
diff --git a/spec/support/notify_email_shared_examples.rb b/spec/support/notify_email_shared_examples.rb
index d849e23bfb..e65748375a 100644
--- a/spec/support/notify_email_shared_examples.rb
+++ b/spec/support/notify_email_shared_examples.rb
@@ -12,12 +12,16 @@
let(:to) { "07777777777" }
let(:template_folder) { "notify_sms" }
- before { allow(Feature).to receive(:enabled?).with(:sms) { true } }
+ before { allow(Feature).to receive(:enabled?).with(:sms).and_return(true) }
include_examples "notify template", template_id, personalisation
end
shared_examples_for "notify template" do |template_id, personalisation|
+ subject do
+ described_class.new(to: to, **personalisation || {})
+ end
+
before do
stub_const(
'Notify::API_KEY',
@@ -25,12 +29,8 @@
)
end
- subject do
- described_class.new(to: to, **personalisation || {})
- end
-
before do
- allow(NotifyService.instance).to receive(:notification_class) { NotifyFakeClient }
+ allow(NotifyService.instance).to receive(:notification_class).and_return(NotifyFakeClient)
end
specify 'should inherit from the NotifyDespatchers::Base class' do
@@ -44,7 +44,7 @@
end
describe 'Initialization' do
- personalisation&.each do |k, _|
+ personalisation&.each_key do |k|
specify "should raise an error if supplied without :#{k}" do
{ to: to }.merge(personalisation.except(k)).tap do |args|
expect { described_class.new(args) }.to raise_error(ArgumentError, /required keywords:.*#{k}/)
@@ -54,7 +54,7 @@
end
describe 'Attributes' do
- personalisation&.each do |k, _|
+ personalisation&.each_key do |k|
specify "should respond to #{k}" do
expect(subject).to respond_to(k)
end
@@ -65,10 +65,9 @@
describe '#despatch_later!' do
before do
allow(Notify::BaseJob).to receive(:perform_later).and_return(true)
+ subject.despatch_later!
end
- before { subject.despatch_later! }
-
specify 'it enqueues the email delivery job' do
subject.to.each do |address|
expect(Notify::BaseJob).to have_received(:perform_later).with(
@@ -83,6 +82,7 @@
describe 'Template' do
subject { described_class.new(to: to, **personalisation || {}) }
+
let(:template_path) { [Rails.root, "app", "notify", template_folder] }
let(:template) do
@@ -115,6 +115,14 @@
shared_examples_for "email template from application preview" do |args|
describe ".from_application_preview" do
+ subject do
+ if args
+ described_class.from_application_preview(to, ap, *args)
+ else
+ described_class.from_application_preview(to, ap)
+ end
+ end
+
before do
stub_const(
'Notify::API_KEY',
@@ -122,20 +130,12 @@
)
end
- specify { expect(described_class).to respond_to(:from_application_preview) }
-
- let!(:school) { create(:bookings_school, :with_fixed_availability_preference, urn: 11_048) }
- let(:rs) { build(:registration_session, urn: 11_048) }
- let(:to) { "morris.szyslak@moes.net" }
let(:ap) { Candidates::Registrations::ApplicationPreview.new(rs) }
+ let(:to) { "morris.szyslak@moes.net" }
+ let(:rs) { build(:registration_session, urn: 11_048) }
+ let!(:school) { create(:bookings_school, :with_fixed_availability_preference, urn: 11_048) }
- subject do
- if args
- described_class.from_application_preview(to, ap, *args)
- else
- described_class.from_application_preview(to, ap)
- end
- end
+ specify { expect(described_class).to respond_to(:from_application_preview) }
it { is_expected.to be_a(described_class) }
@@ -195,6 +195,7 @@
context 'when the school has set dates' do
let(:rs) { build(:registration_session, :with_school, urn: 11_048) }
+
specify 'bookings_placement_date_id is correctly-assigned' do
expect(subject.placement_availability).to eql(Bookings::PlacementDate.last.to_s)
end
diff --git a/spec/support/rate_limiting_support.rb b/spec/support/rate_limiting_support.rb
index 8eca127724..d21fc61797 100644
--- a/spec/support/rate_limiting_support.rb
+++ b/spec/support/rate_limiting_support.rb
@@ -2,6 +2,8 @@
include ActiveSupport::Testing::TimeHelpers
describe desc do
+ subject { response.status }
+
let(:memory_store) { ActiveSupport::Cache.lookup_store(:memory_store) }
before do
@@ -9,8 +11,6 @@
request_count.times { perform_request }
end
- subject { response.status }
-
context "when fewer than rate limit" do
let(:request_count) { limit - 1 }
diff --git a/spec/support/registration_step_shared_examples.rb b/spec/support/registration_step_shared_examples.rb
index 1baf2fae81..250533c508 100644
--- a/spec/support/registration_step_shared_examples.rb
+++ b/spec/support/registration_step_shared_examples.rb
@@ -1,4 +1,8 @@
shared_examples 'a registration step' do
+ subject do
+ described_class.new(urn: school.urn)
+ end
+
let! :datetime do
DateTime.now
end
@@ -7,10 +11,6 @@
datetime + 1.day
end
- subject do
- described_class.new(urn: school.urn)
- end
-
context 'methods' do
it { is_expected.to respond_to :persisted? }
it { is_expected.to respond_to :flag_as_persisted! }
@@ -23,25 +23,25 @@
allow(DateTime).to receive(:now) { datetime }
end
- context '#created_at' do
+ describe '#created_at' do
it 'is nil' do
- expect(subject.created_at).to eq nil
+ expect(subject.created_at).to be_nil
end
end
- context '#updated_at' do
+ describe '#updated_at' do
it 'is nil' do
- expect(subject.updated_at).to eq nil
+ expect(subject.updated_at).to be_nil
end
end
- context '#persisted?' do
+ describe '#persisted?' do
it 'is false' do
expect(subject).not_to be_persisted
end
end
- context '#flag_as_persisted!' do
+ describe '#flag_as_persisted!' do
context 'when invalid' do
it 'raises a validation error' do
expect { subject.flag_as_persisted! }.to raise_error \
@@ -51,7 +51,7 @@
context 'when valid' do
before do
- allow(subject).to receive(:valid?) { true }
+ allow(subject).to receive(:valid?).and_return(true)
subject.flag_as_persisted!
end
@@ -73,13 +73,13 @@
allow(DateTime).to receive(:now) { new_datetime }
end
- context '#persisted?' do
+ describe '#persisted?' do
it 'is true' do
expect(subject).to be_persisted
end
end
- context '#persisted!' do
+ describe '#persisted!' do
context 'when invalid' do
# ie a bad update attempt
it 'raises a validation error' do
@@ -90,7 +90,7 @@
context 'when valid' do
before do
- allow(subject).to receive(:valid?) { true }
+ allow(subject).to receive(:valid?).and_return(true)
subject.flag_as_persisted!
end
diff --git a/spec/support/schools/on_boarding/school_fee_shared_examples.rb b/spec/support/schools/on_boarding/school_fee_shared_examples.rb
index 3714289211..0a6791847e 100644
--- a/spec/support/schools/on_boarding/school_fee_shared_examples.rb
+++ b/spec/support/schools/on_boarding/school_fee_shared_examples.rb
@@ -1,12 +1,12 @@
shared_examples 'a school fee' do
- context '#attributes' do
+ describe '#attributes' do
it { is_expected.to respond_to :amount_pounds }
it { is_expected.to respond_to :description }
it { is_expected.to respond_to :interval }
it { is_expected.to respond_to :payment_method }
end
- context '#validations' do
+ describe '#validations' do
it { is_expected.to validate_presence_of(:amount_pounds) }
# Can't do this with shoulda
@@ -54,7 +54,7 @@
it { is_expected.to validate_presence_of(:description) }
it do
- is_expected.to validate_inclusion_of(:interval).in_array %w[Daily One-off]
+ expect(subject).to validate_inclusion_of(:interval).in_array %w[Daily One-off]
end
it { is_expected.to validate_presence_of(:payment_method) }
diff --git a/spec/validators/email_format_validator_spec.rb b/spec/validators/email_format_validator_spec.rb
index 48cb3c699a..476dcc8295 100644
--- a/spec/validators/email_format_validator_spec.rb
+++ b/spec/validators/email_format_validator_spec.rb
@@ -8,9 +8,10 @@ class TestModel
end
describe EmailFormatValidator do
- before { instance.valid? }
subject { instance.errors.to_hash }
+ before { instance.valid? }
+
context 'invalid addresses' do
[
'test.com', 'test@@test.com', 'FFFF', 'test@test', 'test@test.'
@@ -18,7 +19,7 @@ class TestModel
let(:instance) { TestModel.new(email_address: email_address) }
it "#{email_address} should not be valid" do
- is_expected.to include email_address: ['is invalid']
+ expect(subject).to include email_address: ['is invalid']
end
end
end
@@ -30,7 +31,7 @@ class TestModel
let(:instance) { TestModel.new(email_address: email_address) }
it "#{email_address} should be valid" do
- is_expected.not_to include [:email_address]
+ expect(subject).not_to include [:email_address]
end
end
end
diff --git a/spec/validators/number_of_words_validator_spec.rb b/spec/validators/number_of_words_validator_spec.rb
index 6af7b363e5..5ff8a072b0 100644
--- a/spec/validators/number_of_words_validator_spec.rb
+++ b/spec/validators/number_of_words_validator_spec.rb
@@ -13,7 +13,7 @@
described_class.new attributes: :description, less_than: 150
end
- before :each do
+ before do
validator.validate_each model, :description, description
end
diff --git a/spec/validators/website_validator_spec.rb b/spec/validators/website_validator_spec.rb
index 4f44a0b3b0..aeb2d2d1c1 100644
--- a/spec/validators/website_validator_spec.rb
+++ b/spec/validators/website_validator_spec.rb
@@ -9,7 +9,7 @@
end
context 'invalid websites' do
- let(:validator) { WebsiteValidator.new(attributes: { name: 'invalid website' }) }
+ let(:validator) { described_class.new(attributes: { name: 'invalid website' }) }
['www.bbc.co.uk', 'huw.edwards@bbc.co.uk', 'huw@bbc', 'bbc', 'http://bbc'].each do |invalid_website|
it "#{invalid_website} should not be valid" do
@@ -20,7 +20,7 @@
end
context 'valid websites' do
- let(:validator) { WebsiteValidator.new(attributes: { name: 'valid website' }) }
+ let(:validator) { described_class.new(attributes: { name: 'valid website' }) }
['https://www.bbc.co.uk', 'http://bbc.co.uk', 'http://news.bbc.co.uk'].each do |valid_website|
it "#{valid_website} should be valid" do
diff --git a/spec/views/candidates/home/index.html.erb_spec.rb b/spec/views/candidates/home/index.html.erb_spec.rb
index 0bbec84ddf..e1c2b32246 100644
--- a/spec/views/candidates/home/index.html.erb_spec.rb
+++ b/spec/views/candidates/home/index.html.erb_spec.rb
@@ -3,19 +3,23 @@
RSpec.describe "candidates/home/index", type: :view do
describe 'content' do
before { render }
- it "will show the masthead text" do
+
+ it "shows the masthead text" do
expect(rendered).to have_css("p", text: /Use this service if/)
end
- it "will show a button" do
+ it "shows a button" do
expect(rendered).to have_css('a.govuk-button', text: 'Start now')
end
end
context 'when deactivated' do
+ subject { render }
+
let(:msg) { "This is a test\n\non multiple lines" }
+
before { assign :applications_deactivated, msg }
- subject { render }
+
it { is_expected.not_to have_css('a.govuk-button', text: 'Start now') }
it { is_expected.to have_css('#candidate-applications-deactivated') }
it { is_expected.to have_css('p', text: %r{\AThis is a test\z}) }
@@ -23,16 +27,19 @@
end
context 'when application_notification' do
+ subject { render template: 'candidates/home/index', layout: 'layouts/application' }
+
let(:msg) { "This is a test\n\non multiple lines\n\na link" }
+
before do
without_partial_double_verification do
- allow(view).to receive(:show_candidate_alert_notification?) { true }
+ allow(view).to receive(:show_candidate_alert_notification?).and_return(true)
end
allow(Rails.application.config.x.candidates).to \
receive(:alert_notification).and_return msg
end
- subject { render template: 'candidates/home/index', layout: 'layouts/application' }
+
it { is_expected.to have_css('a.govuk-button', text: 'Start now') }
it { is_expected.to have_css('#candidate-alert-notification') }
end
diff --git a/spec/views/candidates/registrations/personal_informations/_form.html.erb_spec.rb b/spec/views/candidates/registrations/personal_informations/_form.html.erb_spec.rb
index 3ef506b332..a46dc49878 100644
--- a/spec/views/candidates/registrations/personal_informations/_form.html.erb_spec.rb
+++ b/spec/views/candidates/registrations/personal_informations/_form.html.erb_spec.rb
@@ -25,25 +25,25 @@
personal_information: Candidates::Registrations::PersonalInformation.new
end
- it "will allow the address to be changed" do
+ it "allows the address to be changed" do
expect(rendered).to have_css(email_selector, count: 1)
expect(rendered).to have_css("#{email_selector}[readonly]", count: 0)
expect(rendered).to have_css("#{email_selector}[disabled]", count: 0)
end
- it "will allow the address to be changed" do
+ it "allows the address to be changed" do
expect(rendered).to have_css(email_selector, count: 1)
expect(rendered).to have_css("#{fname_selector}[readonly]", count: 0)
expect(rendered).to have_css("#{fname_selector}[disabled]", count: 0)
end
- it "will allow the address to be changed" do
+ it "allows the address to be changed" do
expect(rendered).to have_css(email_selector, count: 1)
expect(rendered).to have_css("#{lname_selector}[readonly]", count: 0)
expect(rendered).to have_css("#{lname_selector}[disabled]", count: 0)
end
- it "will allow the address to be changed" do
+ it "allows the address to be changed" do
expect(rendered).to have_css(email_selector, count: 1)
end
end
@@ -63,25 +63,25 @@
personal_information: personal_information
end
- it "will not allow the address to be changed" do
+ it "does not allow the address to be changed" do
expect(rendered).to have_css(email_selector, count: 1)
expect(rendered).to have_css("#{email_selector}[readonly]", count: 1)
expect(rendered).to have_css("#{email_selector}[disabled]", count: 1)
end
- it "will not allow the address to be changed" do
+ it "does not allow the address to be changed" do
expect(rendered).to have_css(email_selector, count: 1)
expect(rendered).to have_css("#{fname_selector}[readonly]", count: 1)
expect(rendered).to have_css("#{fname_selector}[disabled]", count: 1)
end
- it "will not allow the address to be changed" do
+ it "does not allow the address to be changed" do
expect(rendered).to have_css(email_selector, count: 1)
expect(rendered).to have_css("#{lname_selector}[readonly]", count: 1)
expect(rendered).to have_css("#{lname_selector}[disabled]", count: 1)
end
- it "will not allow the address to be changed" do
+ it "does not allow the address to be changed" do
expect(rendered).to have_css(email_selector, count: 1)
end
end
diff --git a/spec/views/candidates/registrations/sign_ins/show.html.erb_spec.rb b/spec/views/candidates/registrations/sign_ins/show.html.erb_spec.rb
index 271590b5a5..fcaa741bd9 100644
--- a/spec/views/candidates/registrations/sign_ins/show.html.erb_spec.rb
+++ b/spec/views/candidates/registrations/sign_ins/show.html.erb_spec.rb
@@ -17,7 +17,7 @@
render
end
- it "will notify the user their message has been sent" do
+ it "notifies the user their message has been sent" do
expect(rendered).to have_css('h1', text: /already registered with us/i)
expect(rendered).to have_css('li', text: 'test@testymctest.com')
expect(rendered).to \
diff --git a/spec/views/candidates/registrations/sign_ins/update.html.erb_spec.rb b/spec/views/candidates/registrations/sign_ins/update.html.erb_spec.rb
index c0d57f7dda..82d5b6aa72 100644
--- a/spec/views/candidates/registrations/sign_ins/update.html.erb_spec.rb
+++ b/spec/views/candidates/registrations/sign_ins/update.html.erb_spec.rb
@@ -10,7 +10,7 @@
render
end
- it "will notify the user their message has been sent" do
+ it "notifies the user their message has been sent" do
expect(rendered).to have_css('h1', text: /Verify/i)
expect(rendered).to \
have_css("form[action=\"/my/resend/link\"] button", text: "Send a new link")
diff --git a/spec/views/candidates/schools/index.html.erb_spec.rb b/spec/views/candidates/schools/index.html.erb_spec.rb
index 711cf91177..e51edd4abe 100644
--- a/spec/views/candidates/schools/index.html.erb_spec.rb
+++ b/spec/views/candidates/schools/index.html.erb_spec.rb
@@ -1,13 +1,6 @@
require 'rails_helper'
RSpec.describe "candidates/schools/index", type: :view do
- context 'with fresh search' do
- before do
- assign(:search, Candidates::SchoolSearch.new)
- render
- end
- end
-
context 'filtering existing search' do
let(:phases) { %w[3] }
let(:max_fee) { '60' }
@@ -17,13 +10,7 @@
let(:parking) { '1' }
before do
- allow(Candidates::School).to receive(:subjects).and_return(
- [[1, 'Computer science'], [2, 'Maths'], [3, 'English']]
- )
-
- allow(Candidates::School).to receive(:phases).and_return(
- [[1, 'Primary'], [2, 'Seconday'], [3, '16 to 18']]
- )
+ allow(Candidates::School).to receive_messages(subjects: [[1, 'Computer science'], [2, 'Maths'], [3, 'English']], phases: [[1, 'Primary'], [2, 'Seconday'], [3, '16 to 18']])
@school = build(:bookings_school)
@search = Candidates::SchoolSearch.new(
@@ -129,7 +116,7 @@
let(:schools) { [build(:bookings_school)] }
it "shows when more than one result" do
- expect(rendered).to_not have_css 'div', text: 'Sorted by distance'
+ expect(rendered).not_to have_css 'div', text: 'Sorted by distance'
end
end
end
diff --git a/spec/views/candidates/schools/show.html.erb_spec.rb b/spec/views/candidates/schools/show.html.erb_spec.rb
index ee49e3be59..28b0ab11aa 100644
--- a/spec/views/candidates/schools/show.html.erb_spec.rb
+++ b/spec/views/candidates/schools/show.html.erb_spec.rb
@@ -14,16 +14,16 @@
render
end
- it "will include the schools name" do
+ it "includes the schools name" do
expect(rendered).to have_css('h1', text: school.name)
end
- it "will provide a link to apply" do
+ it "provides a link to apply" do
link = new_candidates_school_registrations_personal_information_path(school)
expect(rendered).to have_css("a.govuk-button[href=\"#{link}\"]")
end
- it "will include dress code information" do
+ it "includes dress code information" do
expect(rendered).to have_css("#dress-code")
end
@@ -55,7 +55,7 @@
render
end
- it "will include the schools name" do
+ it "includes the schools name" do
expect(rendered).to have_css('h1', text: school.name)
end
diff --git a/spec/views/candidates/sessions/create.html.erb_spec.rb b/spec/views/candidates/sessions/create.html.erb_spec.rb
index 035e64844f..79d1a9618c 100644
--- a/spec/views/candidates/sessions/create.html.erb_spec.rb
+++ b/spec/views/candidates/sessions/create.html.erb_spec.rb
@@ -14,7 +14,7 @@
render
end
- it "should explain the email has been sent" do
+ it "explains the email has been sent" do
expect(rendered).to have_css('h1', text: 'Verify your school experience sign in')
expect(rendered).to have_css('p', text: /enter the verification code/i)
expect(rendered).to have_css('li', text: /testy@mctest.com/)
diff --git a/spec/views/candidates/sessions/new.html.erb_spec.rb b/spec/views/candidates/sessions/new.html.erb_spec.rb
index 816dcfbaa4..2f86edb8d3 100644
--- a/spec/views/candidates/sessions/new.html.erb_spec.rb
+++ b/spec/views/candidates/sessions/new.html.erb_spec.rb
@@ -10,7 +10,7 @@
render
end
- it "will show the sign in form" do
+ it "shows the sign in form" do
expect(rendered).to have_css('h1', text: 'Get school experience sign in')
expect(rendered).to have_css('p', text: /we will send you a code/i)
expect(rendered).to have_css("form")
@@ -27,7 +27,7 @@
render
end
- it "will show the errors in the sign in form" do
+ it "shows the errors in the sign in form" do
expect(rendered).to have_css('h1', text: 'Get school experience sign in')
expect(rendered).to have_css('p', text: /we will send you a code/i)
expect(rendered).to have_css("form")
diff --git a/spec/views/candidates/sessions/update.html.erb_spec.rb b/spec/views/candidates/sessions/update.html.erb_spec.rb
index c98877e794..74f0c5a065 100644
--- a/spec/views/candidates/sessions/update.html.erb_spec.rb
+++ b/spec/views/candidates/sessions/update.html.erb_spec.rb
@@ -3,7 +3,7 @@
RSpec.describe "candidates/sessions/update", type: :view do
before { render }
- it "should explain the session token is invalid" do
+ it "explains the session token is invalid" do
expect(rendered).to have_css('h1', text: 'Sign in link has expired')
expect(rendered).to have_css('p', text: /sign in link has expired/)
expect(rendered).to have_css("a[href=\"#{candidates_signin_path}\"]")
diff --git a/spec/views/schools/change_schools/show.html.erb_spec.rb b/spec/views/schools/change_schools/show.html.erb_spec.rb
index d2b13e7202..784a197809 100644
--- a/spec/views/schools/change_schools/show.html.erb_spec.rb
+++ b/spec/views/schools/change_schools/show.html.erb_spec.rb
@@ -1,34 +1,30 @@
require 'rails_helper'
describe 'schools/change_schools/show', type: :view do
- before { allow(Rails.application.config.x).to receive(:dfe_sign_in_api_enabled).and_return(true) }
+ before do
+ allow(Rails.application.config.x).to receive(:dfe_sign_in_api_enabled).and_return(true)
+ allow(Schools::DFESignInAPI::Client).to receive(:enabled?).and_return(true)
+ allow_any_instance_of(Schools::DFESignInAPI::Organisations).to receive(:urns).and_return(urns)
+ end
let(:school) { create(:bookings_school) }
let(:other_schools) { create_list(:bookings_school, 3) }
let(:all_schools) { other_schools.push(school).compact }
let(:urns) { other_schools.map(&:urn) }
- before do
- allow(Schools::DFESignInAPI::Client).to receive(:enabled?).and_return(true)
- allow_any_instance_of(Schools::DFESignInAPI::Organisations).to receive(:urns).and_return(urns)
- end
-
context 'when the user has access to multiple schools' do
before do
allow(Schools::ChangeSchool).to \
- receive(:allow_school_change_in_app?) { true }
- end
-
- before do
+ receive(:allow_school_change_in_app?).and_return(true)
assign :current_school, school
assign :schools, all_schools
assign :change_school, Schools::ChangeSchool.new(nil, {}, change_to_urn: school&.urn)
without_partial_double_verification do
allow(view).to receive(:current_urn).and_return school&.urn
end
- end
- before { render }
+ render
+ end
specify 'there should be one radio button per school' do
expect(rendered).to have_css("input[type='radio']", count: all_schools.size)
@@ -58,15 +54,11 @@
end
end
- context 'when the user only has access to one school' do
- # should we do something extra here? the form will render with a single
- # already-selected radio button
- end
-
context 'when in app school-changing is disabled' do
- before { allow(Rails.application.config.x).to(receive(:dfe_sign_in_api_school_change_enabled)).and_return(false) }
-
- before { render }
+ before do
+ allow(Rails.application.config.x).to(receive(:dfe_sign_in_api_school_change_enabled)).and_return(false)
+ render
+ end
specify 'should inform the user that changing is disabled' do
expect(rendered).to match(/Changing school is not enabled/)
@@ -85,18 +77,14 @@
assign :change_school, change_school
allow(Schools::ChangeSchool).to \
- receive(:allow_school_change_in_app?).and_return true
-
- allow(Schools::ChangeSchool).to \
- receive(:request_approval_url).and_return 'https://dfesignin.url'
+ receive_messages(allow_school_change_in_app?: true, request_approval_url: 'https://dfesignin.url')
without_partial_double_verification do
allow(view).to receive(:current_urn).and_return nil
end
+ render
end
- before { render }
-
specify 'there should be an request access option' do
expect(rendered).to have_css("input[type='radio'][value='request access']")
end
diff --git a/spec/views/schools/dashboards/show.html.erb_spec.rb b/spec/views/schools/dashboards/show.html.erb_spec.rb
index 746942851d..fb1458ca30 100644
--- a/spec/views/schools/dashboards/show.html.erb_spec.rb
+++ b/spec/views/schools/dashboards/show.html.erb_spec.rb
@@ -2,31 +2,32 @@
describe 'schools/dashboards/show', type: :view do
let(:school) { create(:bookings_school) }
+
before { assign :current_school, school }
context 'when the user has other schools' do
+ subject { render }
+
before do
without_partial_double_verification do
allow(view).to receive(:has_other_schools?).and_return true
end
end
- subject { render }
-
specify 'the page should have a change school link that initiates a DfE Sign-in switch' do
expect(subject).to have_link('Change school', href: '/schools/switch/new')
end
end
context 'when the user has no other schools' do
+ subject { render }
+
before do
without_partial_double_verification do
allow(view).to receive(:has_other_schools?).and_return false
end
end
- subject { render }
-
specify 'the page should have no change school link' do
expect(subject).not_to have_link('Change school')
end
diff --git a/spec/views/schools/switch/show.html.erb_spec.rb b/spec/views/schools/switch/show.html.erb_spec.rb
index 7528545c26..a7d8a1d57c 100644
--- a/spec/views/schools/switch/show.html.erb_spec.rb
+++ b/spec/views/schools/switch/show.html.erb_spec.rb
@@ -2,13 +2,16 @@
describe 'schools/switch/show', type: :view do
let(:school) { create(:bookings_school) }
+
before { assign :current_school, school }
context 'when a URN param is present' do
let(:other_school) { create(:bookings_school) }
- before { assign :other_school, other_school }
- before { render }
+ before do
+ assign :other_school, other_school
+ render
+ end
specify 'should render the page with information about the schools' do
expect(response).to match(school.name)