Skip to content

Commit

Permalink
Rename remidners form arg reminder
Browse files Browse the repository at this point in the history
The reminders forms work with a reminder not a claim, so we want to
update the arguments to make this clear.
The reminders forms likely shouldn't share the same base class as the
answers forms but changing this is outside of the scope of this rather
large pr!
  • Loading branch information
rjlynch committed Jun 14, 2024
1 parent b52d86c commit 8c9836b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ class RemindersController < BasePublicController

private

# FIXME RL: Remove this once reminders are writing to the session
def load_form_if_exists
@form ||= AdditionalPaymentsForTeaching::FORMS.dig(
"reminders", params[:slug]
)&.new(claim: current_reminder, journey: Journeys::AdditionalPaymentsForTeaching, journey_session:, params:)
)&.new(reminder: current_reminder, journey: Journeys::AdditionalPaymentsForTeaching, journey_session:, params:)
end

def claim_from_session
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class EmailVerificationForm < Form
attribute :sent_one_time_password_at

# Required for shared partial in the view
delegate :email_address, to: :claim
delegate :email_address, to: :answers

validate :sent_one_time_password_must_be_valid
validate :otp_must_be_valid, if: :sent_one_time_password_at?
Expand All @@ -19,26 +19,19 @@ def self.model_name
self.one_time_password = one_time_password.gsub(/\D/, "")
end

# TODO RL: remove this and the initializer once reminders are writing
# to the session
attr_reader :claim
attr_reader :reminder

def initialize(claim:, journey_session:, journey:, params:)
@claim = claim
def initialize(reminder:, journey_session:, journey:, params:)
@reminder = reminder
super(journey_session:, journey:, params:)

assign_attributes(attributes_with_current_value)
end

# TODO RL: remove this once reminders are writing to the session
def update!(attrs)
claim.update!(attrs)
end

def save
return false unless valid?

update!(email_verified: true)
reminder.update!(email_verified: true)
end

private
Expand All @@ -65,19 +58,7 @@ def sent_one_time_password_at?
end

def load_current_value(attribute)
# TODO: re-implement when the underlying claim and eligibility data sources
# are moved to an alternative place e.g. a session hash

# Some, but not all attributes are present directly on the claim record.
return claim.public_send(attribute) if claim.has_attribute?(attribute)

# At the moment, some attributes are unique to a policy eligibility record,
# so we need to loop through all the claims in the wrapper and check each
# eligibility individually; if the search fails, it should return `nil`.
claim.claims.each do |c|
return c.eligibility.public_send(attribute) if c.eligibility.has_attribute?(attribute)
end
nil
reminder.public_send(attribute) if reminder.has_attribute?(attribute)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,19 @@ def self.model_name
ActiveModel::Name.new(Form)
end

# TODO RL: remove this and the initializer once reminders are writing
# to the session
attr_reader :claim
attr_reader :reminder

def initialize(claim:, journey_session:, journey:, params:)
@claim = claim
def initialize(reminder:, journey_session:, journey:, params:)
@reminder = reminder
super(journey_session:, journey:, params:)

assign_attributes(attributes_with_current_value)
end

# TODO RL: remove this once reminders are writing to the session
def update!(attrs)
claim.update!(attrs)
end

def save
return false unless valid?

update!(attributes)
reminder.update!(attributes)
end

private
Expand All @@ -45,19 +38,7 @@ def i18n_form_namespace
end

def load_current_value(attribute)
# TODO: re-implement when the underlying claim and eligibility data sources
# are moved to an alternative place e.g. a session hash

# Some, but not all attributes are present directly on the claim record.
return claim.public_send(attribute) if claim.has_attribute?(attribute)

# At the moment, some attributes are unique to a policy eligibility record,
# so we need to loop through all the claims in the wrapper and check each
# eligibility individually; if the search fails, it should return `nil`.
claim.claims.each do |c|
return c.eligibility.public_send(attribute) if c.eligibility.has_attribute?(attribute)
end
nil
reminder.public_send(attribute) if reminder.has_attribute?(attribute)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

RSpec.describe Journeys::AdditionalPaymentsForTeaching::Reminders::EmailVerificationForm do
subject(:form) do
described_class.new(claim: reminder, journey:, journey_session:, params:)
described_class.new(reminder: reminder, journey:, journey_session:, params:)
end

let(:journey) { Journeys::AdditionalPaymentsForTeaching }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "rails_helper"

RSpec.describe Journeys::AdditionalPaymentsForTeaching::Reminders::PersonalDetailsForm, type: :model do
subject(:form) { described_class.new(claim: form_data_object, journey:, journey_session:, params:) }
subject(:form) { described_class.new(reminder: form_data_object, journey:, journey_session:, params:) }

let(:journey) { Journeys::AdditionalPaymentsForTeaching }
let(:journey_session) { build(:additional_payments_session) }
Expand Down Expand Up @@ -30,16 +30,13 @@
describe "#save" do
subject(:save) { form.save }

before do
allow(form).to receive(:update!).and_return(true)
end

context "valid params" do
let(:form_params) { {"full_name" => "John Doe", "email_address" => "[email protected]"} }

it "saves the attributes" do
expect(save).to eq(true)
expect(form).to have_received(:update!).with(form_params)
expect(form_data_object.full_name).to eq("John Doe")
expect(form_data_object.email_address).to eq("[email protected]")
end
end

Expand All @@ -48,7 +45,8 @@

it "does not save the attributes" do
expect(save).to eq(false)
expect(form).not_to have_received(:update!)
expect(form_data_object.full_name).to be_nil
expect(form_data_object.email_address).to be_nil
end
end
end
Expand Down

0 comments on commit 8c9836b

Please sign in to comment.