Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
slorek committed Sep 12, 2024
1 parent c914bd5 commit a62ddd0
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def build_reminder_from_claim
return unless model_for_reminder_attributes

Reminder.new(
journey:,
journey_class: journey.to_s,
full_name: model_for_reminder_attributes.full_name,
email_address: model_for_reminder_attributes.email_address,
itt_academic_year: next_academic_year,
Expand Down
2 changes: 1 addition & 1 deletion app/forms/reminders/confirmation_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Reminders
class ConfirmationForm < Form
def reminder
@reminder ||= Reminder.find_by(
journey: Journeys.for_routing_name(journey_session.journey).to_s,
journey_class: Journeys.for_routing_name(journey_session.journey).to_s,
full_name: journey_session.answers.reminder_full_name,
email_address: journey_session.answers.reminder_email_address,
email_verified: true,
Expand Down
2 changes: 1 addition & 1 deletion app/forms/reminders/email_verification_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def save!
)
journey_session.save!
reminder = Reminder.find_or_create_by(
journey: Journeys.for_routing_name(journey_session.journey).to_s,
journey_class: Journeys.for_routing_name(journey_session.journey).to_s,
full_name: journey_session.answers.reminder_full_name,
email_address: journey_session.answers.reminder_email_address,
email_verified: true,
Expand Down
2 changes: 1 addition & 1 deletion app/forms/reminders/personal_details_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def save!

def reminder
@reminder ||= Reminder.new(
journey: Journeys.for_routing_name(journey_session.journey).to_s,
journey: Journeys.for_routing_name(journey_session.journey),
full_name: reminder_full_name,
email_address: reminder_email_address
)
Expand Down
8 changes: 6 additions & 2 deletions app/models/reminder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ class Reminder < ApplicationRecord

scope :email_verified, -> { where(email_verified: true) }
scope :not_yet_sent, -> { where(email_sent_at: nil) }
scope :by_journey, ->(journey) { where(journey: journey.to_s) }
scope :by_journey, ->(journey) { where(journey_class: journey.to_s) }
scope :inside_academic_year, -> { where(itt_academic_year: AcademicYear.current.to_s) }
scope :to_be_sent, -> { email_verified.not_yet_sent.inside_academic_year }

def journey
super.constantize
journey_class.constantize
end

def journey=(journey_class)
self[:journey_class] = journey_class.to_s
end

def send_year
Expand Down
2 changes: 1 addition & 1 deletion config/analytics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ shared:
- itt_academic_year
- itt_subject
- sent_one_time_password_at
- journey
- journey_class
:tasks:
- id
- name
Expand Down
12 changes: 6 additions & 6 deletions db/migrate/20240910135453_add_journey_to_reminders.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
class AddJourneyToReminders < ActiveRecord::Migration[7.0]
def up
add_column :reminders, :journey, :string
add_column :reminders, :journey_class, :string

# Additional payments journey was not open when migration created, however
# the FurtherEducationPayments journey was opened for the first time on
# 2024/9/9 and so some reminders may also be set for the
# FurtherEducationPayments journey
Reminder.not_yet_sent.where("created_at < ?", Date.new(2024, 9, 9)).update_all(journey: Journeys::AdditionalPaymentsForTeaching)
Reminder.not_yet_sent.where("created_at >= ?", Date.new(2024, 9, 9)).update_all(journey: Journeys::FurtherEducationPayments)
Reminder.where("created_at < ?", Date.new(2024, 9, 9)).update_all(journey_class: Journeys::AdditionalPaymentsForTeaching.to_s)
Reminder.not_yet_sent.where("created_at >= ?", Date.new(2024, 9, 9)).update_all(journey_class: Journeys::FurtherEducationPayments.to_s)

change_column_null :reminders, :journey, false
add_index :reminders, :journey
change_column_null :reminders, :journey_class, false
add_index :reminders, :journey_class
end

def down
remove_column :reminders, :journey
remove_column :reminders, :journey_class
end
end
4 changes: 2 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,8 @@
t.datetime "email_sent_at", precision: nil
t.string "itt_academic_year", limit: 9
t.string "itt_subject"
t.string "journey", null: false
t.index ["journey"], name: "index_reminders_on_journey"
t.string "journey_class", null: false
t.index ["journey_class"], name: "index_reminders_on_journey_class"
end

create_table "school_workforce_censuses", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/reminders.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
factory :reminder do
full_name { Faker::Name.name }
email_address { Faker::Internet.email }
journey { Journeys::AdditionalPaymentsForTeaching }
journey_class { Journeys::AdditionalPaymentsForTeaching }
end
end

0 comments on commit a62ddd0

Please sign in to comment.