From f79bef2bf7b7d78abc866dfee25ef831dfb1c4c9 Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Tue, 26 Sep 2023 17:00:21 +0100 Subject: [PATCH] Stop using requestable state We're going to remove this field as it's no longer necessary so we need to first stop using it. --- app/controllers/personas_controller.rb | 5 -- app/jobs/expire_requestable_job.rb | 8 ++- app/jobs/expire_requestables_job.rb | 10 ++- app/jobs/update_working_days_job.rb | 20 +++--- app/lib/application_form_status_updater.rb | 2 +- app/models/concerns/expirable.rb | 8 +++ app/models/concerns/requestable.rb | 60 ++++++++-------- app/models/further_information_request.rb | 6 +- app/models/reference_request.rb | 6 +- app/services/send_reminder_email.rb | 1 - .../application_form_show_view_object.rb | 6 ++ ...further_information_request_view_object.rb | 5 +- app/views/personas/index.html.erb | 34 ---------- .../application_forms/show.html.erb | 2 +- config/locales/components.en.yml | 1 + lib/tasks/example_data.rake | 3 +- .../factories/further_information_requests.rb | 16 ++--- .../professional_standing_requests.rb | 5 -- spec/factories/qualification_requests.rb | 5 -- spec/factories/reference_requests.rb | 16 ++--- ...nal_standing_request_location_form_spec.rb | 4 +- .../qualification_request_form_spec.rb | 8 +-- spec/jobs/expire_requestable_job_spec.rb | 4 +- .../application_form_status_updater_spec.rb | 2 +- spec/lib/application_mailer_observer_spec.rb | 2 +- spec/mailers/referee_mailer_spec.rb | 2 +- spec/services/expire_requestable_spec.rb | 6 +- spec/services/rollback_assessment_spec.rb | 8 +-- .../support/autoload/page_objects/personas.rb | 5 -- spec/support/shared_examples/requestable.rb | 68 +++++++------------ .../change_work_history_spec.rb | 2 +- spec/system/personas_spec.rb | 9 --- ...application_forms_show_view_object_spec.rb | 1 - .../application_form_show_view_object_spec.rb | 2 +- 34 files changed, 141 insertions(+), 201 deletions(-) diff --git a/app/controllers/personas_controller.rb b/app/controllers/personas_controller.rb index c42a1e587f..edb76b81ae 100644 --- a/app/controllers/personas_controller.rb +++ b/app/controllers/personas_controller.rb @@ -8,11 +8,6 @@ class PersonasController < ApplicationController def index @staff = Staff.all - - @reference_requests = - ReferenceRequest.states.values.filter_map do |state| - ReferenceRequest.find_by(state:) - end end def eligible_sign_in diff --git a/app/jobs/expire_requestable_job.rb b/app/jobs/expire_requestable_job.rb index 7651c9ca33..08ec97ca1f 100644 --- a/app/jobs/expire_requestable_job.rb +++ b/app/jobs/expire_requestable_job.rb @@ -2,8 +2,12 @@ class ExpireRequestableJob < ApplicationJob def perform(requestable) - if requestable.requested? && requestable.expires_at.present? && - Time.zone.now > requestable.expires_at + if requestable.received? || requestable.expired? || + !requestable.requested? || requestable.expires_at.nil? + return + end + + if Time.zone.now > requestable.expires_at ExpireRequestable.call(requestable:, user: "Expirer") end end diff --git a/app/jobs/expire_requestables_job.rb b/app/jobs/expire_requestables_job.rb index ab675c8a24..482c1d62df 100644 --- a/app/jobs/expire_requestables_job.rb +++ b/app/jobs/expire_requestables_job.rb @@ -2,8 +2,12 @@ class ExpireRequestablesJob < ApplicationJob def perform(requestable_class_name) - requestable_class_name.constantize.requested.find_each do |requestable| - ExpireRequestableJob.perform_later(requestable) - end + requestable_class_name + .constantize + .requested + .where(expired_at: nil, received_at: nil) + .find_each do |requestable| + ExpireRequestableJob.perform_later(requestable) + end end end diff --git a/app/jobs/update_working_days_job.rb b/app/jobs/update_working_days_job.rb index 59b5d4a426..119fbc8a3a 100644 --- a/app/jobs/update_working_days_job.rb +++ b/app/jobs/update_working_days_job.rb @@ -116,23 +116,23 @@ def update_further_information_requests_assessment_started_to_creation def update_further_information_requests_since_received FurtherInformationRequest - .where.not(received_at: nil) + .received .find_each do |further_information_request| - further_information_request.update!( - working_days_since_received: - calendar.business_days_between( - further_information_request.received_at, - today, - ), - ) - end + further_information_request.update!( + working_days_since_received: + calendar.business_days_between( + further_information_request.received_at, + today, + ), + ) + end end def update_further_information_requests_received_to_recommendation FurtherInformationRequest .joins(:assessment) .includes(:assessment) - .where.not(received_at: nil) + .received .where.not(assessment: { recommended_at: nil }) .find_each do |further_information_request| further_information_request.update!( diff --git a/app/lib/application_form_status_updater.rb b/app/lib/application_form_status_updater.rb index 010e38731f..01ac70b745 100644 --- a/app/lib/application_form_status_updater.rb +++ b/app/lib/application_form_status_updater.rb @@ -302,7 +302,7 @@ def overdue?(requestables:) end def waiting_on?(requestables:) - requestables.reject(&:reviewed?).any?(&:requested?) + requestables.reject(&:reviewed?).reject(&:received?).any?(&:requested?) end def received?(requestables:) diff --git a/app/models/concerns/expirable.rb b/app/models/concerns/expirable.rb index 92627eb65c..4676102fc4 100644 --- a/app/models/concerns/expirable.rb +++ b/app/models/concerns/expirable.rb @@ -9,6 +9,14 @@ def expires_at requested_at + expires_after end + def expired! + update!(expired_at: Time.zone.now) + end + + def expired? + expired_at != nil + end + def after_expired(user:) # implement logic after an expiration of this object end diff --git a/app/models/concerns/requestable.rb b/app/models/concerns/requestable.rb index e1618878f6..d9132a8c6e 100644 --- a/app/models/concerns/requestable.rb +++ b/app/models/concerns/requestable.rb @@ -8,32 +8,32 @@ module Requestable included do belongs_to :assessment - enum :state, - { requested: "requested", received: "received", expired: "expired" }, - default: "requested" - - validates :state, presence: true, inclusion: { in: states.values } - - validates :requested_at, presence: true, if: :requested? - validates :received_at, presence: true, if: :received? - validates :expired_at, presence: true, if: :expired? validates :reviewed_at, presence: true, unless: -> { passed.nil? } - scope :respondable, -> { not_received.merge(ApplicationForm.assessable) } + scope :requested, -> { where.not(requested_at: nil) } + scope :received, -> { where.not(received_at: nil) } + scope :respondable, + -> do + requested.where(received_at: nil).merge(ApplicationForm.assessable) + end - define_method :requested! do - update!(state: "requested", requested_at: Time.zone.now) - end + has_one :application_form, through: :assessment + end - define_method :received! do - update!(state: "received", received_at: Time.zone.now) - end + def requested! + update!(requested_at: Time.zone.now) + end - define_method :expired! do - update!(state: "expired", expired_at: Time.zone.now) - end + def requested? + requested_at != nil + end - has_one :application_form, through: :assessment + def received! + update!(received_at: Time.zone.now) + end + + def received? + received_at != nil end def reviewed!(passed) @@ -44,19 +44,25 @@ def reviewed? passed != nil end - def overdue? - expired? || (received? && expires_at.present? && received_at > expires_at) - end - def failed return nil if passed.nil? passed == false end def status - return state if passed.nil? - - passed ? "accepted" : "rejected" + if reviewed_at.present? + passed ? "accepted" : "rejected" + elsif received_at.present? && expired_at.present? + "received_and_overdue" + elsif expired_at.present? + "overdue" + elsif received_at.present? + "received" + elsif requested_at.present? + "waiting_on" + else + "not_started" + end end def after_requested(user:) diff --git a/app/models/further_information_request.rb b/app/models/further_information_request.rb index 28ddce1446..c088cff408 100644 --- a/app/models/further_information_request.rb +++ b/app/models/further_information_request.rb @@ -32,9 +32,9 @@ class FurtherInformationRequest < ApplicationRecord scope :remindable, -> do - requested.joins(assessment: :application_form).merge( - ApplicationForm.assessable, - ) + where(received_at: nil, expired_at: nil).joins( + assessment: :application_form, + ).merge(ApplicationForm.assessable) end FOUR_WEEK_COUNTRY_CODES = %w[AU CA GI NZ US].freeze diff --git a/app/models/reference_request.rb b/app/models/reference_request.rb index 086c99aaac..d4d9034109 100644 --- a/app/models/reference_request.rb +++ b/app/models/reference_request.rb @@ -58,9 +58,9 @@ class ReferenceRequest < ApplicationRecord scope :remindable, -> do - requested.joins(assessment: :application_form).merge( - ApplicationForm.assessable, - ) + where(received_at: nil, expired_at: nil).joins( + assessment: :application_form, + ).merge(ApplicationForm.assessable) end with_options if: :received? do diff --git a/app/services/send_reminder_email.rb b/app/services/send_reminder_email.rb index 2878a84ee5..d6ed99779b 100644 --- a/app/services/send_reminder_email.rb +++ b/app/services/send_reminder_email.rb @@ -19,7 +19,6 @@ def call attr_reader :remindable def send_reminder? - return false if remindable.try(:expired_at).present? return false unless remindable.expires_at remindable.should_send_reminder_email?( diff --git a/app/view_objects/teacher_interface/application_form_show_view_object.rb b/app/view_objects/teacher_interface/application_form_show_view_object.rb index f5e5f69b79..28006d89fa 100644 --- a/app/view_objects/teacher_interface/application_form_show_view_object.rb +++ b/app/view_objects/teacher_interface/application_form_show_view_object.rb @@ -119,6 +119,12 @@ def show_professional_standing_request_expired_content? professional_standing_request&.expired? || false end + def request_further_information? + further_information_request.present? && + further_information_request.requested? && + !further_information_request.received? + end + def request_professional_standing_certificate? teaching_authority_provides_written_statement && professional_standing_request&.requested? && diff --git a/app/view_objects/teacher_interface/further_information_request_view_object.rb b/app/view_objects/teacher_interface/further_information_request_view_object.rb index 43d042b848..3345eaf68d 100644 --- a/app/view_objects/teacher_interface/further_information_request_view_object.rb +++ b/app/view_objects/teacher_interface/further_information_request_view_object.rb @@ -11,8 +11,7 @@ def further_information_request @further_information_request ||= FurtherInformationRequest .joins(:assessment) - .requested - .where(assessments: { application_form: }) + .where(received_at: nil, assessments: { application_form: }) .find(params[:id]) end @@ -74,7 +73,7 @@ def item_value(item) item.document elsif item.work_history_contact? "Contact name: #{item.contact_name}
- Contact job: #{item.contact_job}
+ Contact job: #{item.contact_job}
Contact email: #{item.contact_email}".html_safe end end diff --git a/app/views/personas/index.html.erb b/app/views/personas/index.html.erb index 9447b36282..13ac98e38f 100644 --- a/app/views/personas/index.html.erb +++ b/app/views/personas/index.html.erb @@ -149,37 +149,3 @@ end %> <% end %> - -
-

References

- - <% if @reference_requests.empty? %> -

No reference requests.

- <% else %> - <%= govuk_table do |table| - table.with_head do |head| - head.with_row do |row| - row.with_cell(header: true, text: "Teacher email") - row.with_cell(header: true, text: "State") - row.with_cell(header: true, text: "Actions", numeric: true) - end - end - - table.with_body do |body| - @reference_requests.each do |reference_request| - body.with_row do |row| - row.with_cell(text: reference_request.application_form.teacher.email) - - row.with_cell(width: "one-third") do - render(StatusTag::Component.new(status: reference_request.state)) - end - - row.with_cell(numeric: true) do - govuk_button_link_to "Sign in".html_safe, teacher_interface_reference_request_path(slug: reference_request.slug) - end - end - end - end - end %> - <% end %> -
diff --git a/app/views/teacher_interface/application_forms/show.html.erb b/app/views/teacher_interface/application_forms/show.html.erb index f7d9452e72..94898777ee 100644 --- a/app/views/teacher_interface/application_forms/show.html.erb +++ b/app/views/teacher_interface/application_forms/show.html.erb @@ -8,7 +8,7 @@ <%= render "teacher_interface/application_forms/show/declined", view_object: @view_object %> <% elsif @view_object.application_form.awarded? %> <%= render "teacher_interface/application_forms/show/awarded", view_object: @view_object %> -<% elsif @view_object.further_information_request&.requested? %> +<% elsif @view_object.request_further_information? %> <%= render "teacher_interface/application_forms/show/further_information_requested", view_object: @view_object %> <% elsif @view_object.request_professional_standing_certificate? %> <%= render "teacher_interface/application_forms/show/request_professional_standing_certificate", view_object: @view_object %> diff --git a/config/locales/components.en.yml b/config/locales/components.en.yml index e90c63d706..19820f97de 100644 --- a/config/locales/components.en.yml +++ b/config/locales/components.en.yml @@ -30,6 +30,7 @@ en: received_professional_standing: Received professional standing received_qualification: Received qualification received_reference: Received reference + received_and_overdue: Received (overdue) rejected: Rejected requested: Waiting on review: Review diff --git a/lib/tasks/example_data.rake b/lib/tasks/example_data.rake index 50ce3efc5a..25f839bc72 100644 --- a/lib/tasks/example_data.rake +++ b/lib/tasks/example_data.rake @@ -189,10 +189,9 @@ def create_application_forms end elsif (work_history = application_form.work_histories.first) && rand(2).zero? - reference_request_trait = ReferenceRequest.states.keys.sample FactoryBot.create( :reference_request, - reference_request_trait, + %i[requested received expired].sample, assessment:, work_history:, ) diff --git a/spec/factories/further_information_requests.rb b/spec/factories/further_information_requests.rb index dbe706f02a..c626ca2dbb 100644 --- a/spec/factories/further_information_requests.rb +++ b/spec/factories/further_information_requests.rb @@ -27,34 +27,32 @@ factory :further_information_request do association :assessment - requested - trait :requested do - state { "requested" } requested_at { Faker::Time.between(from: 1.month.ago, to: Time.zone.now) } end trait :received do - state { "received" } received_at { Faker::Time.between(from: 1.month.ago, to: Time.zone.now) } end trait :expired do - state { "expired" } expired_at { Faker::Time.between(from: 1.month.ago, to: Time.zone.now) } end + trait :reviewed do + received + reviewed_at { Faker::Time.between(from: 1.month.ago, to: Time.zone.now) } + end + trait :passed do + reviewed passed { true } - reviewed_at { Faker::Time.between(from: 1.month.ago, to: Time.zone.now) } - received end trait :failed do + reviewed passed { false } - reviewed_at { Faker::Time.between(from: 1.month.ago, to: Time.zone.now) } failure_assessor_note { "Notes." } - received end trait :with_items do diff --git a/spec/factories/professional_standing_requests.rb b/spec/factories/professional_standing_requests.rb index 654cd39d31..2656d89516 100644 --- a/spec/factories/professional_standing_requests.rb +++ b/spec/factories/professional_standing_requests.rb @@ -30,21 +30,16 @@ factory :professional_standing_request do association :assessment - requested - trait :requested do - state { "requested" } requested_at { Faker::Time.between(from: 1.month.ago, to: Time.zone.now) } end trait :received do - state { "received" } received_at { Faker::Time.between(from: 1.month.ago, to: Time.zone.now) } receivable end trait :expired do - state { "expired" } expired_at { Faker::Time.between(from: 1.month.ago, to: Time.zone.now) } end diff --git a/spec/factories/qualification_requests.rb b/spec/factories/qualification_requests.rb index cd3f552fff..b5836caa6c 100644 --- a/spec/factories/qualification_requests.rb +++ b/spec/factories/qualification_requests.rb @@ -33,21 +33,16 @@ association :assessment association :qualification, :completed - requested - trait :requested do - state { "requested" } requested_at { Faker::Time.between(from: 1.month.ago, to: Time.zone.now) } end trait :received do - state { "received" } received_at { Faker::Time.between(from: 1.month.ago, to: Time.zone.now) } receivable end trait :expired do - state { "expired" } expired_at { Faker::Time.between(from: 1.month.ago, to: Time.zone.now) } end diff --git a/spec/factories/reference_requests.rb b/spec/factories/reference_requests.rb index c2ccb6d5d0..d0e2581227 100644 --- a/spec/factories/reference_requests.rb +++ b/spec/factories/reference_requests.rb @@ -61,35 +61,33 @@ ) end - requested - trait :requested do - state { "requested" } requested_at { Faker::Time.between(from: 1.month.ago, to: Time.zone.now) } end trait :received do - state { "received" } received_at { Faker::Time.between(from: 1.month.ago, to: Time.zone.now) } receivable end trait :expired do - state { "expired" } expired_at { Faker::Time.between(from: 1.month.ago, to: Time.zone.now) } end + trait :reviewed do + received + reviewed_at { Faker::Time.between(from: 1.month.ago, to: Time.zone.now) } + end + trait :passed do + reviewed passed { true } - reviewed_at { Faker::Time.between(from: 1.month.ago, to: Time.zone.now) } - received end trait :failed do + reviewed passed { false } failure_assessor_note { "Notes." } - reviewed_at { Faker::Time.between(from: 1.month.ago, to: Time.zone.now) } - received end trait :receivable do diff --git a/spec/forms/assessor_interface/professional_standing_request_location_form_spec.rb b/spec/forms/assessor_interface/professional_standing_request_location_form_spec.rb index 1e95e64d88..e6629574ab 100644 --- a/spec/forms/assessor_interface/professional_standing_request_location_form_spec.rb +++ b/spec/forms/assessor_interface/professional_standing_request_location_form_spec.rb @@ -43,8 +43,8 @@ it { is_expected.to be true } - it "changes the state" do - expect { save }.to change(requestable, :state).to("received") + it "sets the received at date" do + expect { save }.to change(requestable, :received_at).from(nil) end it "sets the location note" do diff --git a/spec/forms/assessor_interface/qualification_request_form_spec.rb b/spec/forms/assessor_interface/qualification_request_form_spec.rb index aa7322264e..7a7dd27ace 100644 --- a/spec/forms/assessor_interface/qualification_request_form_spec.rb +++ b/spec/forms/assessor_interface/qualification_request_form_spec.rb @@ -57,8 +57,8 @@ it { is_expected.to be true } - it "changes the state" do - expect { save }.to change(requestable, :state).to("received") + it "sets the received at date" do + expect { save }.to change(requestable, :received_at).from(nil) end it "sets passed" do @@ -89,8 +89,8 @@ it { is_expected.to be true } - it "changes the state" do - expect { save }.to change(requestable, :state).to("received") + it "sets the received at date" do + expect { save }.to change(requestable, :received_at).from(nil) end it "sets passed" do diff --git a/spec/jobs/expire_requestable_job_spec.rb b/spec/jobs/expire_requestable_job_spec.rb index 1d683ee161..69909ee38f 100644 --- a/spec/jobs/expire_requestable_job_spec.rb +++ b/spec/jobs/expire_requestable_job_spec.rb @@ -36,12 +36,12 @@ end context "when less than six weeks old" do - let(:requested_at) { (6.weeks - 1.hour).ago } + let(:requested_at) { (6.weeks - 2.hours).ago } it_behaves_like "not expired requestable" end context "when it is more than six weeks old" do - let(:requested_at) { (6.weeks + 1.hour).ago } + let(:requested_at) { (6.weeks + 2.hours).ago } it_behaves_like "expired requestable" end diff --git a/spec/lib/application_form_status_updater_spec.rb b/spec/lib/application_form_status_updater_spec.rb index 45b1a6fc34..d5e64460e1 100644 --- a/spec/lib/application_form_status_updater_spec.rb +++ b/spec/lib/application_form_status_updater_spec.rb @@ -504,7 +504,7 @@ application_form.update!( teaching_authority_provides_written_statement: true, ) - create(:professional_standing_request, assessment:) + create(:professional_standing_request, :requested, assessment:) end include_examples "changes action required by", "admin" diff --git a/spec/lib/application_mailer_observer_spec.rb b/spec/lib/application_mailer_observer_spec.rb index 9854d6ae3f..b4ed8d8566 100644 --- a/spec/lib/application_mailer_observer_spec.rb +++ b/spec/lib/application_mailer_observer_spec.rb @@ -22,7 +22,7 @@ end context "with a referee mailer" do - let(:reference_request) { create(:reference_request) } + let(:reference_request) { create(:reference_request, :requested) } let(:application_form) { reference_request.assessment.application_form } let(:message) { RefereeMailer.with(reference_request:).reference_requested } diff --git a/spec/mailers/referee_mailer_spec.rb b/spec/mailers/referee_mailer_spec.rb index dd5d441815..86577f66c0 100644 --- a/spec/mailers/referee_mailer_spec.rb +++ b/spec/mailers/referee_mailer_spec.rb @@ -18,7 +18,7 @@ end let(:reference_request) do - create(:reference_request, assessment:, work_history:) + create(:reference_request, :requested, assessment:, work_history:) end describe "#reference_reminder" do diff --git a/spec/services/expire_requestable_spec.rb b/spec/services/expire_requestable_spec.rb index b4b8da3f3b..1ccb78b8f7 100644 --- a/spec/services/expire_requestable_spec.rb +++ b/spec/services/expire_requestable_spec.rb @@ -41,7 +41,7 @@ end context "with requested FI request" do - let(:requestable) { create(:further_information_request) } + let(:requestable) { create(:further_information_request, :requested) } it_behaves_like "expiring a requestable" it_behaves_like "declining the application" @@ -60,7 +60,7 @@ end context "with a requested professional standing request" do - let(:requestable) { create(:professional_standing_request) } + let(:requestable) { create(:professional_standing_request, :requested) } it_behaves_like "expiring a requestable" @@ -88,7 +88,7 @@ end context "with a requested reference request" do - let(:requestable) { create(:reference_request) } + let(:requestable) { create(:reference_request, :requested) } it_behaves_like "expiring a requestable" end diff --git a/spec/services/rollback_assessment_spec.rb b/spec/services/rollback_assessment_spec.rb index 406958ee3f..3816132598 100644 --- a/spec/services/rollback_assessment_spec.rb +++ b/spec/services/rollback_assessment_spec.rb @@ -12,7 +12,7 @@ let(:assessment) { create(:assessment, :award, application_form:) } context "having requested verification" do - before { create(:reference_request, assessment:) } + before { create(:reference_request, :requested, assessment:) } it "sets the assessment to unknown" do expect { call }.to change(assessment, :verify?).to(true) @@ -31,7 +31,7 @@ end context "having requested further information" do - before { create(:further_information_request, assessment:) } + before { create(:further_information_request, :requested, assessment:) } it "sets the assessment to unknown" do expect { call }.to change(assessment, :request_further_information?).to( @@ -74,7 +74,7 @@ let(:assessment) { create(:assessment, :decline, application_form:) } context "having requested verification" do - before { create(:reference_request, assessment:) } + before { create(:reference_request, :requested, assessment:) } it "sets the assessment to unknown" do expect { call }.to change(assessment, :verify?).to(true) @@ -93,7 +93,7 @@ end context "having requested further information" do - before { create(:further_information_request, assessment:) } + before { create(:further_information_request, :requested, assessment:) } it "sets the assessment to unknown" do expect { call }.to change(assessment, :request_further_information?).to( diff --git a/spec/support/autoload/page_objects/personas.rb b/spec/support/autoload/page_objects/personas.rb index 11aac48667..174d149579 100644 --- a/spec/support/autoload/page_objects/personas.rb +++ b/spec/support/autoload/page_objects/personas.rb @@ -18,10 +18,5 @@ class Personas < SitePrism::Page element :heading, "h2" elements :buttons, ".govuk-button" end - - section :references, "#app-personas-references" do - element :heading, "h2" - elements :buttons, ".govuk-button" - end end end diff --git a/spec/support/shared_examples/requestable.rb b/spec/support/shared_examples/requestable.rb index cf3d6b19ce..5b98d5c800 100644 --- a/spec/support/shared_examples/requestable.rb +++ b/spec/support/shared_examples/requestable.rb @@ -1,42 +1,15 @@ # frozen_string_literal: true RSpec.shared_examples "a requestable" do - it do - is_expected.to define_enum_for(:state).with_values( - requested: "requested", - received: "received", - expired: "expired", - ).backed_by_column_of_type(:string) - end - describe "associations" do it { is_expected.to belong_to(:assessment) } end describe "validations" do - it { is_expected.to validate_presence_of(:state) } - + it { is_expected.to_not validate_presence_of(:requested_at) } it { is_expected.to_not validate_presence_of(:received_at) } it { is_expected.to_not validate_presence_of(:expired_at) } - context "when received" do - before { subject.state = "requested" } - - it { is_expected.to validate_presence_of(:requested_at) } - end - - context "when received" do - before { subject.state = "received" } - - it { is_expected.to validate_presence_of(:received_at) } - end - - context "when expired" do - before { subject.state = "expired" } - - it { is_expected.to validate_presence_of(:expired_at) } - end - context "when reviewed" do before { subject.passed = [true, false].sample } @@ -49,7 +22,9 @@ it "sets the requested at date" do freeze_time do - expect { call }.to change(subject, :requested_at).to(Time.zone.now) + expect { call }.to change(subject, :requested_at).from(nil).to( + Time.zone.now, + ) end end end @@ -57,10 +32,6 @@ describe "#received!" do let(:call) { subject.received! } - it "changes the state" do - expect { call }.to change(subject, :received?).from(false).to(true) - end - it "sets the received at date" do freeze_time do expect { call }.to change(subject, :received_at).from(nil).to( @@ -73,10 +44,6 @@ describe "#expired!" do let(:call) { subject.expired! } - it "changes the state" do - expect { call }.to change(subject, :expired?).from(false).to(true) - end - it "sets the received at date" do freeze_time do expect { call }.to change(subject, :expired_at).from(nil).to( @@ -105,21 +72,36 @@ end describe "#status" do - it "is the same as state when passed is nil and state is defined" do - subject.passed = nil - subject.state = "received" - expect(subject.status).to eq("received") - end - it "is accepted when passed is true" do subject.passed = true + subject.reviewed_at = Time.zone.now expect(subject.status).to eq("accepted") end it "is rejected when passed is false" do subject.passed = false + subject.reviewed_at = Time.zone.now expect(subject.status).to eq("rejected") end + + it "is received when received at is set" do + subject.received_at = Time.zone.now + expect(subject.status).to eq("received") + end + + it "is overdue when expired at is set" do + subject.expired_at = Time.zone.now + expect(subject.status).to eq("overdue") + end + + it "is waiting on when requested at is set" do + subject.requested_at = Time.zone.now + expect(subject.status).to eq("waiting_on") + end + + it "is not started by default" do + expect(subject.status).to eq("not_started") + end end describe "#after_received" do diff --git a/spec/system/assessor_interface/change_work_history_spec.rb b/spec/system/assessor_interface/change_work_history_spec.rb index c901d898e2..cdeac10c7a 100644 --- a/spec/system/assessor_interface/change_work_history_spec.rb +++ b/spec/system/assessor_interface/change_work_history_spec.rb @@ -124,7 +124,7 @@ def assessment_section def reference_request @reference_request ||= - create(:reference_request, assessment:, work_history:) + create(:reference_request, :requested, assessment:, work_history:) end def assessor diff --git a/spec/system/personas_spec.rb b/spec/system/personas_spec.rb index 4b5dc34864..a0caf035b2 100644 --- a/spec/system/personas_spec.rb +++ b/spec/system/personas_spec.rb @@ -35,9 +35,6 @@ then_i_see_the(:teacher_application_page) when_i_visit_the(:personas_page) - - when_i_sign_in_as_a_reference_persona - then_i_see_the(:teacher_reference_requested_page) end end @@ -66,8 +63,6 @@ def given_personas_exist teacher = create(:teacher, email: "teacher@example.com") create(:application_form, teacher:) - - create(:reference_request, :requested) end def when_i_sign_in_as_a_staff_persona @@ -82,10 +77,6 @@ def when_i_sign_in_as_a_teacher_persona personas_page.teachers.buttons.first.click end - def when_i_sign_in_as_a_reference_persona - personas_page.references.buttons.first.click - end - def and_i_see_no_personas expect(personas_page.eligibles).to have_content("No eligible personas.") expect(personas_page.staff).to have_content("No staff personas.") diff --git a/spec/view_objects/assessor_interface/application_forms_show_view_object_spec.rb b/spec/view_objects/assessor_interface/application_forms_show_view_object_spec.rb index a8fcc9ff5e..2788a5c831 100644 --- a/spec/view_objects/assessor_interface/application_forms_show_view_object_spec.rb +++ b/spec/view_objects/assessor_interface/application_forms_show_view_object_spec.rb @@ -119,7 +119,6 @@ context "and professional standing request received" do before do professional_standing_request.update!( - state: "received", received_at: 1.day.ago, location_note: "wat", ) diff --git a/spec/view_objects/teacher_interface/application_form_show_view_object_spec.rb b/spec/view_objects/teacher_interface/application_form_show_view_object_spec.rb index 611ac2e102..571e47e8ae 100644 --- a/spec/view_objects/teacher_interface/application_form_show_view_object_spec.rb +++ b/spec/view_objects/teacher_interface/application_form_show_view_object_spec.rb @@ -356,7 +356,7 @@ ) end - before { create(:professional_standing_request, assessment:) } + before { create(:professional_standing_request, :requested, assessment:) } it { is_expected.to be false }