diff --git a/app/models/concerns/requestable.rb b/app/models/concerns/requestable.rb index a97bb95c6c..e1618878f6 100644 --- a/app/models/concerns/requestable.rb +++ b/app/models/concerns/requestable.rb @@ -16,6 +16,7 @@ module Requestable 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) } @@ -28,6 +29,10 @@ module Requestable update!(state: "received", received_at: Time.zone.now) end + define_method :expired! do + update!(state: "expired", expired_at: Time.zone.now) + end + has_one :application_form, through: :assessment end diff --git a/app/services/send_reminder_email.rb b/app/services/send_reminder_email.rb index d6ed99779b..2878a84ee5 100644 --- a/app/services/send_reminder_email.rb +++ b/app/services/send_reminder_email.rb @@ -19,6 +19,7 @@ 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/spec/factories/further_information_requests.rb b/spec/factories/further_information_requests.rb index 8c04ca21e9..4fe84ea880 100644 --- a/spec/factories/further_information_requests.rb +++ b/spec/factories/further_information_requests.rb @@ -41,6 +41,7 @@ trait :expired do state { "expired" } + expired_at { Faker::Time.between(from: 1.month.ago, to: Time.zone.now) } end trait :passed do diff --git a/spec/factories/professional_standing_requests.rb b/spec/factories/professional_standing_requests.rb index 5f23fbc89e..16acf1a0a0 100644 --- a/spec/factories/professional_standing_requests.rb +++ b/spec/factories/professional_standing_requests.rb @@ -43,6 +43,11 @@ receivable end + trait :expired do + state { "expired" } + expired_at { Faker::Time.between(from: 1.month.ago, to: Time.zone.now) } + end + trait :receivable do location_note { Faker::Lorem.sentence } end diff --git a/spec/factories/qualification_requests.rb b/spec/factories/qualification_requests.rb index 0883884e11..609a799af8 100644 --- a/spec/factories/qualification_requests.rb +++ b/spec/factories/qualification_requests.rb @@ -46,6 +46,11 @@ receivable end + trait :expired do + state { "expired" } + expired_at { Faker::Time.between(from: 1.month.ago, to: Time.zone.now) } + end + trait :receivable do location_note { Faker::Lorem.sentence } end diff --git a/spec/factories/reference_requests.rb b/spec/factories/reference_requests.rb index 7e6836a442..45577e3b2a 100644 --- a/spec/factories/reference_requests.rb +++ b/spec/factories/reference_requests.rb @@ -76,6 +76,7 @@ trait :expired do state { "expired" } + expired_at { Faker::Time.between(from: 1.month.ago, to: Time.zone.now) } end trait :passed do diff --git a/spec/support/shared_examples/requestable.rb b/spec/support/shared_examples/requestable.rb index e3a8ef86c2..cf3d6b19ce 100644 --- a/spec/support/shared_examples/requestable.rb +++ b/spec/support/shared_examples/requestable.rb @@ -17,6 +17,7 @@ it { is_expected.to validate_presence_of(:state) } 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" } @@ -30,6 +31,12 @@ 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 } @@ -63,6 +70,22 @@ end end + 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( + Time.zone.now, + ) + end + end + end + [true, false].each do |passed| describe "#reviewed!(#{passed})" do let(:call) { subject.reviewed!(passed) }