Accept full URLs

It looks like the intention was there, so I made it work.
I've included a real world example, but added capitalisation to complete the test.
This commit is contained in:
David Cook
2023-03-09 09:47:37 +11:00
parent 6d05d57846
commit 9e7e176cf9
3 changed files with 8 additions and 7 deletions

View File

@@ -450,7 +450,8 @@ class Enterprise < ApplicationRecord
end
def strip_url(url)
url&.sub(%r{(https?://)?}, '')
# Strip protocol and trailing slash
url&.sub(%r{(https?://)?}, '')&.sub(%r{/\z}, '')
end
def correct_whatsapp_url(phone_number)

View File

@@ -171,8 +171,8 @@ describe Enterprise do
expect(e).to_not be_valid
end
it "invalidates the instagram attribute https://instagram.com/user/" do
e = build(:enterprise, instagram: 'https://instagram.com/user/')
it "invalidates the instagram attribute https://www.instagram.com/p/Cpg4McNPyJA/" do
e = build(:enterprise, instagram: 'https://www.instagram.com/p/Cpg4McNPyJA/')
expect(e).to_not be_valid
end

View File

@@ -117,8 +117,8 @@ describe "Registration" do
click_button "Continue"
expect(page).to have_content 'How can people find My Awesome Enterprise online?'
# Filling in social with invalid value for instagram - slash after InStAgRaM
fill_in "enterprise_instagram", with: 'www.instagram.com/InStAgRaM/'
# Filling in social with invalid value for instagram - a link to a post instead of user
fill_in "enterprise_instagram", with: 'https://www.instagram.com/p/Cpg4McNPyJA/'
accept_alert "Failed to update your enterprise." do
click_button "Continue"
end
@@ -129,7 +129,7 @@ describe "Registration" do
fill_in 'enterprise_facebook', with: 'FaCeBoOk'
fill_in 'enterprise_linkedin', with: 'LiNkEdIn'
fill_in 'enterprise_twitter', with: 'https://www.twitter.com/@TwItTeR'
fill_in 'enterprise_instagram', with: 'www.instagram.com/InStAgRaM'
fill_in 'enterprise_instagram', with: 'https://www.instagram.com/OpenFoodNetwork/'
click_button "Continue"
expect(page).to have_content 'Finished!'
@@ -147,7 +147,7 @@ describe "Registration" do
expect(e.facebook).to eq "FaCeBoOk"
expect(e.linkedin).to eq "LiNkEdIn"
expect(e.twitter).to eq "TwItTeR"
expect(e.instagram).to eq "instagram"
expect(e.instagram).to eq "openfoodnetwork"
click_link "Go to Enterprise Dashboard"
expect(page).to have_content "CHOOSE YOUR PACKAGE"