-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is a form which uses the new UpdateApplicationFormName service to allow assessors to change the name on an application form.
- Loading branch information
1 parent
ddeeb0d
commit 96e1af8
Showing
3 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
app/forms/assessor_interface/application_form_name_form.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
spec/forms/assessor_interface/application_form_name_form_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |