diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 20f0aba26d..771aba8bc9 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -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) diff --git a/spec/models/enterprise_spec.rb b/spec/models/enterprise_spec.rb index 6055360bbd..f6290a8687 100644 --- a/spec/models/enterprise_spec.rb +++ b/spec/models/enterprise_spec.rb @@ -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 diff --git a/spec/system/consumer/registration_spec.rb b/spec/system/consumer/registration_spec.rb index 6d3febe1c7..938f6afda7 100644 --- a/spec/system/consumer/registration_spec.rb +++ b/spec/system/consumer/registration_spec.rb @@ -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"