Skip to content

Commit

Permalink
Add ApplicationFormNameForm
Browse files Browse the repository at this point in the history
This is a form which uses the new UpdateApplicationFormName service to
allow assessors to change the name on an application form.
  • Loading branch information
thomasleese committed Sep 5, 2023
1 parent ddeeb0d commit 96e1af8
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
25 changes: 25 additions & 0 deletions app/forms/assessor_interface/application_form_name_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

class AssessorInterface::ApplicationFormNameForm
include ActiveModel::Model
include ActiveModel::Attributes

attr_accessor :application_form, :user
attribute :given_names, :string
attribute :family_name, :string

validates :application_form, :user, presence: true

def save
return false if invalid?

UpdateApplicationFormName.call(
application_form:,
user:,
given_names:,
family_name:,
)

true
end
end
6 changes: 6 additions & 0 deletions config/locales/helpers.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ en:
helpers:
caption: {}
hint:
assessor_interface_application_form_name_form:
given_names: Type the updated given names in the text box below
family_name: Type the updated family name in the text box below
assessor_interface_assessment_section_form:
selected_failure_reasons: Select all options that are relevant to you.
failure_reason_notes:
Expand Down Expand Up @@ -58,6 +61,9 @@ en:
start_date: For example, 3 2020, If you cannot remember the exact month or year, enter an estimate.
end_date: For example, 3 2020, If you cannot remember the exact month or year, enter an estimate.
label:
assessor_interface_application_form_name_form:
given_names: Change given names
family_name: Change family name
assessor_interface_assessment_recommendation_form:
recommendation_options:
award: Award QTS
Expand Down
34 changes: 34 additions & 0 deletions spec/forms/assessor_interface/application_form_name_form_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe AssessorInterface::ApplicationFormNameForm, type: :model do
let(:application_form) { create(:application_form) }
let(:user) { create(:staff) }

let(:given_names) { "A new given name" }
let(:family_name) { "A new family name" }

subject(:form) do
described_class.new(application_form:, user:, given_names:, family_name:)
end

describe "validations" do
it { is_expected.to validate_presence_of(:application_form) }
it { is_expected.to validate_presence_of(:user) }
end

describe "#save" do
subject(:save) { form.save }

it "calls the UpdateApplicationFormName service" do
expect(UpdateApplicationFormName).to receive(:call).with(
application_form:,
user:,
given_names:,
family_name:,
)
expect(save).to be true
end
end
end

0 comments on commit 96e1af8

Please sign in to comment.