-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the chair of governors contact task
This tasks forces users to collect the contact details for the chair of governors of the school converting into an academy so that a copy of the funding agreement letters can be sent to them. This is our second attempt at a task that collects a contacts (we already have 'main contact') and we wanted to try something different. Here we collect the name, email and optionally phone number and the task is only completed one we have these. This creates a contact and populates it with the further information that we can derive from the project: - organisation = school name - role (title) = Chair of governors - establishment urn = Project.urn Because of the way this works, 'deleting' the contact details in the task and saving it WILL NOT delete the contact, this must be done via External contacts > Change > Delete contact. Updating the details of the contact will work, however.
- Loading branch information
Showing
6 changed files
with
174 additions
and
1 deletion.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
app/forms/conversion/task/chair_of_governors_contact_task_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,53 @@ | ||
class Conversion::Task::ChairOfGovernorsContactTaskForm < BaseTaskForm | ||
attribute :name | ||
attribute :email | ||
attribute :phone | ||
|
||
validates :email, | ||
format: {with: URI::MailTo::EMAIL_REGEXP, message: "Enter a valid email address"}, | ||
allow_blank: true | ||
|
||
validate :name_and_email_both_present? | ||
|
||
def initialize(tasks_data, user) | ||
@tasks_data = tasks_data | ||
@user = user | ||
@project = tasks_data.project | ||
super(@tasks_data, @user) | ||
|
||
@contact = @project.chair_of_governors_contact || Contact::Project.new | ||
|
||
assign_attributes( | ||
name: @contact.name, | ||
email: @contact.email, | ||
phone: @contact.phone | ||
) | ||
end | ||
|
||
def save | ||
if valid? && name.present? && email.present? | ||
@contact.assign_attributes( | ||
title: "Chair of governors", | ||
category: :school_or_academy, | ||
organisation_name: @project.establishment.name, | ||
name: name, | ||
email: email, | ||
phone: phone, | ||
project_id: @project.id, | ||
establishment_urn: @project.urn | ||
) | ||
@contact.save! | ||
|
||
@project.update!(chair_of_governors_contact: @contact) | ||
end | ||
end | ||
|
||
def completed? | ||
@project.chair_of_governors_contact.present? | ||
end | ||
|
||
private def name_and_email_both_present? | ||
errors.add(:name, "Enter a name") if name.blank? && email.present? | ||
errors.add(:email, "Enter an email address") if email.blank? && name.present? | ||
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
27 changes: 27 additions & 0 deletions
27
app/views/conversions/tasks/chair_of_governors_contact/edit.html.erb
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,27 @@ | ||
<%= render(TaskList::TaskHeaderComponent.new(project: @project, task: @task)) %> | ||
<% content_for :pre_content_nav do %> | ||
<% render partial: "shared/back_link", locals: {href: project_tasks_path(@project)} %> | ||
<% end %> | ||
<% content_for :page_title do %> | ||
<%= page_title(t("conversion.task.chair_of_governors_contact.title")) %> | ||
<% end %> | ||
|
||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
<%= form_for @task, url: project_edit_task_path(@project, @task.class.identifier), method: :put do |form| %> | ||
<%= form.govuk_error_summary %> | ||
<%= form.govuk_text_field :name, width: 20 %> | ||
<%= form.govuk_email_field :email, width: 20 %> | ||
<%= form.govuk_phone_field :phone, width: 10 %> | ||
<%= form.govuk_submit t("task_list.continue_button.text") if policy(@tasks_data).update? %> | ||
<% end %> | ||
</div> | ||
|
||
<div class="govuk-grid-column-one-third"> | ||
<%= render partial: "shared/tasks/task_notes" %> | ||
</div> | ||
</div> |
14 changes: 14 additions & 0 deletions
14
config/locales/conversion/tasks/chair_of_governors_contact.en.yml
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,14 @@ | ||
en: | ||
conversion: | ||
task: | ||
chair_of_governors_contact: | ||
title: Add chair of governors' contact details | ||
hint: | ||
html: | ||
<p>Enter the chair of governors' name and email address. This is so they can receive their funding agreement letters.</p> | ||
name: | ||
title: Name | ||
email: | ||
title: Email | ||
phone: | ||
title: Phone |
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 |
---|---|---|
|
@@ -35,6 +35,7 @@ | |
receive_grant_payment_certificate | ||
update_esfa | ||
confirm_date_academy_opened | ||
chair_of_governors_contact | ||
] | ||
|
||
it "confirms we are checking all tasks" do | ||
|
@@ -307,6 +308,81 @@ | |
end | ||
end | ||
|
||
describe "the chair of governors contact task" do | ||
let(:project) { create(:conversion_project, assigned_to: user) } | ||
|
||
before do | ||
visit project_tasks_path(project) | ||
click_on "Add chair of governors' contact details" | ||
end | ||
|
||
scenario "can be submitted empty" do | ||
click_on "Save and return" | ||
|
||
expect(page).to have_selector "h2", text: "Task list" | ||
end | ||
|
||
scenario "validates that both name and email are supplied" do | ||
fill_in "Name", with: "Jane Chair" | ||
fill_in "Email", with: "" | ||
click_on "Save and return" | ||
|
||
expect(page).to have_content "Enter an email address" | ||
|
||
fill_in "Name", with: "" | ||
fill_in "Email", with: "[email protected]" | ||
click_on "Save and return" | ||
|
||
expect(page).to have_content "Enter a name" | ||
end | ||
|
||
scenario "validates the email format" do | ||
fill_in "Name", with: "Jane Chair" | ||
fill_in "Email", with: "jane.chair" | ||
click_on "Save and return" | ||
|
||
expect(page).to have_content "Enter a valid email" | ||
end | ||
|
||
scenario "creates a new contact as the chair of governors" do | ||
fill_in "Name", with: "Jane Chair" | ||
fill_in "Email", with: "[email protected]" | ||
fill_in "Phone", with: "01234 567879" | ||
click_on "Save and return" | ||
click_on "External contacts" | ||
|
||
expect(page).to have_content "Chair of governors" | ||
expect(page).to have_content "Jane Chair" | ||
expect(page).to have_content "[email protected]" | ||
expect(page).to have_content "01234 567879" | ||
expect(page).to have_content project.establishment.name | ||
end | ||
|
||
scenario "updates an existing chair of governors contact" do | ||
chair_of_governors = create(:project_contact) | ||
project.update(chair_of_governors_contact: chair_of_governors) | ||
|
||
visit project_tasks_path(project) | ||
click_on "Add chair of governors' contact details" | ||
|
||
expect(page).to have_field "Name", with: chair_of_governors.name | ||
expect(page).to have_field "Email", with: chair_of_governors.email | ||
expect(page).to have_field "Phone", with: chair_of_governors.phone | ||
|
||
fill_in "Name", with: "Jane Chair" | ||
fill_in "Email", with: "[email protected]" | ||
fill_in "Phone", with: "01234 567879" | ||
click_on "Save and return" | ||
click_on "External contacts" | ||
|
||
expect(page).to have_content "Chair of governors" | ||
expect(page).to have_content "Jane Chair" | ||
expect(page).to have_content "[email protected]" | ||
expect(page).to have_content "01234 567879" | ||
expect(page).to have_content project.establishment.name | ||
end | ||
end | ||
|
||
mandatory_tasks.each do |task| | ||
scenario "a user can complete the actions on the mandatory #{I18n.t("conversion.task.#{task}.title")} task" do | ||
click_on I18n.t("conversion.task.#{task}.title") | ||
|
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