diff --git a/app/assets/javascripts/templates/partials/follow.html.haml b/app/assets/javascripts/templates/partials/follow.html.haml index a47054d1f3..847dbac6b9 100644 --- a/app/assets/javascripts/templates/partials/follow.html.haml +++ b/app/assets/javascripts/templates/partials/follow.html.haml @@ -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 diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index c4ba0a401c..89d0088df3 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -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? diff --git a/spec/models/enterprise_spec.rb b/spec/models/enterprise_spec.rb index 044f57d05b..4f1942573d 100644 --- a/spec/models/enterprise_spec.rb +++ b/spec/models/enterprise_spec.rb @@ -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 diff --git a/spec/system/consumer/registration_spec.rb b/spec/system/consumer/registration_spec.rb index 5868ea493a..6aa64dd231 100644 --- a/spec/system/consumer/registration_spec.rb +++ b/spec/system/consumer/registration_spec.rb @@ -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"