mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-28 01:53:25 +00:00
Merge pull request #8467 from SarvarKh/validate-social-links
Fix the issue with 'at' in enterprise twitter and instagram
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
%p.modal-header {{'follow' | t}}
|
||||
.follow-icons
|
||||
%span{"ng-if" => "::enterprise.twitter"}
|
||||
%a{"ng-href" => "http://twitter.com/{{::enterprise.twitter}}", target: "_blank"}
|
||||
%a{"ng-href" => "http://www.twitter.com/{{::enterprise.twitter}}", target: "_blank"}
|
||||
%i.ofn-i_041-twitter
|
||||
|
||||
%span{"ng-if" => "::enterprise.facebook"}
|
||||
@@ -14,5 +14,5 @@
|
||||
%i.ofn-i_042-linkedin
|
||||
|
||||
%span{"ng-if" => "::enterprise.instagram"}
|
||||
%a{"ng-href" => "http://instagram.com/{{::enterprise.instagram}}", target: "_blank"}
|
||||
%a{"ng-href" => "http://www.instagram.com/{{::enterprise.instagram}}", target: "_blank"}
|
||||
%i.ofn-i_043-instagram
|
||||
|
||||
@@ -291,6 +291,14 @@ class Enterprise < ApplicationRecord
|
||||
strip_url self[:linkedin]
|
||||
end
|
||||
|
||||
def twitter
|
||||
correct_twitter_url self[:twitter]
|
||||
end
|
||||
|
||||
def instagram
|
||||
correct_instagram_url self[:instagram]
|
||||
end
|
||||
|
||||
def inventory_variants
|
||||
if prefers_product_selection_from_inventory_only?
|
||||
Spree::Variant.visible_for(self)
|
||||
@@ -421,6 +429,14 @@ class Enterprise < ApplicationRecord
|
||||
url&.sub(%r{(https?://)?}, '')
|
||||
end
|
||||
|
||||
def correct_instagram_url(url)
|
||||
url && strip_url(url).sub(%r{www.instagram.com/}, '').delete("@")
|
||||
end
|
||||
|
||||
def correct_twitter_url(url)
|
||||
url && strip_url(url).sub(%r{www.twitter.com/}, '').delete("@")
|
||||
end
|
||||
|
||||
def set_unused_address_fields
|
||||
address.firstname = address.lastname = address.phone = address.company = 'unused' if address.present?
|
||||
business_address.first_name = business_address.last_name = 'unused' if business_address.present?
|
||||
|
||||
@@ -561,7 +561,9 @@ describe Enterprise do
|
||||
build_stubbed(:distributor_enterprise,
|
||||
website: "http://www.google.com",
|
||||
facebook: "www.facebook.com/roger",
|
||||
linkedin: "https://linkedin.com")
|
||||
linkedin: "https://linkedin.com",
|
||||
instagram: "https://www.instagram.com/@insgram_user",
|
||||
twitter: "www.twitter.com/@twitter_user")
|
||||
}
|
||||
|
||||
it "strips http from url fields" do
|
||||
@@ -569,6 +571,11 @@ describe Enterprise do
|
||||
expect(distributor.facebook).to eq("www.facebook.com/roger")
|
||||
expect(distributor.linkedin).to eq("linkedin.com")
|
||||
end
|
||||
|
||||
it "strips @, http and domain address from url fields" do
|
||||
expect(distributor.instagram).to eq("insgram_user")
|
||||
expect(distributor.twitter).to eq("twitter_user")
|
||||
end
|
||||
end
|
||||
|
||||
describe "producer properties" do
|
||||
|
||||
@@ -125,8 +125,8 @@ describe "Registration", js: true do
|
||||
fill_in 'enterprise_website', with: 'www.shop.com'
|
||||
fill_in 'enterprise_facebook', with: 'FaCeBoOk'
|
||||
fill_in 'enterprise_linkedin', with: 'LiNkEdIn'
|
||||
fill_in 'enterprise_twitter', with: '@TwItTeR'
|
||||
fill_in 'enterprise_instagram', with: '@InStAgRaM'
|
||||
fill_in 'enterprise_twitter', with: 'https://www.twitter.com/@TwItTeR'
|
||||
fill_in 'enterprise_instagram', with: 'www.instagram.com/InStAgRaM'
|
||||
click_button "Continue"
|
||||
expect(page).to have_content 'Finished!'
|
||||
|
||||
@@ -135,8 +135,8 @@ describe "Registration", js: true do
|
||||
expect(e.website).to eq "www.shop.com"
|
||||
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.twitter).to eq "TwItTeR"
|
||||
expect(e.instagram).to eq "InStAgRaM"
|
||||
|
||||
click_link "Go to Enterprise Dashboard"
|
||||
expect(page).to have_content "CHOOSE YOUR PACKAGE"
|
||||
|
||||
Reference in New Issue
Block a user