Skip to content

Commit

Permalink
Add phone_number validations to PalaceAttendee
Browse files Browse the repository at this point in the history
  • Loading branch information
phil-l-brockwell committed Nov 11, 2024
1 parent e06e85b commit eb3363e
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 15 deletions.
1 change: 1 addition & 0 deletions app/models/palace_attendee.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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" }

Expand Down
4 changes: 4 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/palace_attendees.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/features/palace_attendees_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit eb3363e

Please sign in to comment.