From eb3363e6f962cc5ae148f70548bbaaa83df4368b Mon Sep 17 00:00:00 2001 From: phil-l-brockwell Date: Tue, 5 Nov 2024 17:14:30 +0000 Subject: [PATCH] Add phone_number validations to PalaceAttendee --- app/models/palace_attendee.rb | 1 + config/locales/en.yml | 4 ++ spec/factories/palace_attendees.rb | 2 +- .../palace_attendees_fulfilling_spec.rb | 53 ++++++++++++++----- spec/features/palace_attendees_spec.rb | 2 +- 5 files changed, 47 insertions(+), 15 deletions(-) diff --git a/app/models/palace_attendee.rb b/app/models/palace_attendee.rb index 3d0a8e99e..05d306a46 100644 --- a/app/models/palace_attendee.rb +++ b/app/models/palace_attendee.rb @@ -11,6 +11,7 @@ class PalaceAttendee < ApplicationRecord :postcode, presence: true + validates :phone_number, phone: { allow_blank: true } validates :disabled_access, inclusion: { in: [true, false], message: "This field cannot be blank" } validates :has_royal_family_connections, inclusion: { in: [true, false], message: "This field cannot be blank" } diff --git a/config/locales/en.yml b/config/locales/en.yml index 6a14fd886..b6c30030f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -77,6 +77,10 @@ en: confirmation: "%{attribute} doesn't match." not_a_number: 'Please enter a number.' models: + palace_attendee: + attributes: + phone_number: + invalid: Enter a phone number, like 01635 960 001, 07701 900 982 or +44 808 157 0192 user: attributes: phone_number: diff --git a/spec/factories/palace_attendees.rb b/spec/factories/palace_attendees.rb index 47c5824e5..6d7d5027b 100644 --- a/spec/factories/palace_attendees.rb +++ b/spec/factories/palace_attendees.rb @@ -10,7 +10,7 @@ address_3 { "MyString" } address_4 { "MyString" } postcode { "MyString" } - phone_number { "MyString" } + sequence(:phone_number) { |n| "020 4551 008#{n.to_s[-1]}" } disabled_access { false } additional_info { "MyText" } has_royal_family_connections { false } diff --git a/spec/features/admin/form_answers/palace_attendees_fulfilling_spec.rb b/spec/features/admin/form_answers/palace_attendees_fulfilling_spec.rb index a7865f23b..784fabd7c 100644 --- a/spec/features/admin/form_answers/palace_attendees_fulfilling_spec.rb +++ b/spec/features/admin/form_answers/palace_attendees_fulfilling_spec.rb @@ -33,9 +33,21 @@ end context "js enabled", js: true do - it "adds the single Palace Attendee" do - field_values = [] + let(:title) { "Mr" } + let(:first_name) { "Bob" } + let(:last_name) { "Buttons" } + let(:job_name) { "Fisherman" } + let(:post_nominals) { "Yeah that" } + let(:royal_family_connection_details) { "Cleaner" } + let(:address_1) { "123 Fake Street" } + let(:address_2) { "Electric Avenue" } + let(:address_3) { "Mordoor" } + let(:address_4) { "The World" } + let(:postcode) { "DA7 4HE" } + let(:phone_number) { "02083015556" } + let(:dietary_requirements) { "Meat eater" } + it "adds the single Palace Attendee" do find("#palace-attendees-heading .panel-title a").click within "#section-palace-attendees" do find(".form-edit-link").click @@ -44,12 +56,19 @@ find("input#palace_attendee_phone_number") find("input#palace_attendee_has_royal_family_connections_true").set(true) find("input#palace_attendee_disabled_access_true").set(true) - fill_in "palace_attendee_royal_family_connection_details", with: "connection details" - all("input.form-control").each_with_index do |input, index| - val = "val-#{index}" - field_values << val - input.set(val) - end + fill_in "palace_attendee_royal_family_connection_details", with: royal_family_connection_details + find("#palace_attendee_title").set(title) + find("#palace_attendee_first_name").set(first_name) + find("#palace_attendee_last_name").set(last_name) + find("#palace_attendee_job_name").set(job_name) + find("#palace_attendee_post_nominals").set(post_nominals) + find("#palace_attendee_address_1").set(address_1) + find("#palace_attendee_address_2").set(address_2) + find("#palace_attendee_address_3").set(address_3) + find("#palace_attendee_address_4").set(address_4) + find("#palace_attendee_postcode").set(postcode) + find("#palace_attendee_phone_number").set(phone_number) + find("#palace_attendee_dietary_requirements").set(dietary_requirements) end click_button "Save" @@ -60,11 +79,19 @@ find("#palace-attendees-heading .panel-title a").click within "#section-palace-attendees" do - field_values.each do |val| - expect(page).to have_content(val) - end - - expect(page).to have_content("connection details") + expect(page).to have_content(title) + expect(page).to have_content(first_name) + expect(page).to have_content(last_name) + expect(page).to have_content(job_name) + expect(page).to have_content(post_nominals) + expect(page).to have_content(address_1) + expect(page).to have_content(address_2) + expect(page).to have_content(address_3) + expect(page).to have_content(address_4) + expect(page).to have_content(postcode) + expect(page).to have_content(phone_number) + expect(page).to have_content(dietary_requirements) + expect(page).to have_content(royal_family_connection_details) end end end diff --git a/spec/features/palace_attendees_spec.rb b/spec/features/palace_attendees_spec.rb index 8ad3621dc..0029422dd 100644 --- a/spec/features/palace_attendees_spec.rb +++ b/spec/features/palace_attendees_spec.rb @@ -138,7 +138,7 @@ fill_in "City or town", with: "Test" fill_in "County", with: "Test" fill_in "Postcode", with: "Test" - fill_in "Telephone number", with: "Test" + fill_in "Telephone number", with: "02083015556" disabled_access = find('input[name="palace_invite[palace_attendees_attributes][0][disabled_access]"]', match: :first) disabled_access.set(true)