Skip to content

Commit

Permalink
Use expired_at
Browse files Browse the repository at this point in the history
This updates the code to ensure the expired_at field is set in various
places where it's needed.
  • Loading branch information
thomasleese committed Sep 26, 2023
1 parent 0c00378 commit bf6038b
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/models/concerns/requestable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand All @@ -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

Expand Down
1 change: 1 addition & 0 deletions app/services/send_reminder_email.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?(
Expand Down
1 change: 1 addition & 0 deletions spec/factories/further_information_requests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions spec/factories/professional_standing_requests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions spec/factories/qualification_requests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions spec/factories/reference_requests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions spec/support/shared_examples/requestable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand All @@ -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 }

Expand Down Expand Up @@ -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) }
Expand Down

0 comments on commit bf6038b

Please sign in to comment.