From 5d2a5e63ec04dd91503eaed41c17d5b38addc301 Mon Sep 17 00:00:00 2001 From: SarvarKhalimov Date: Tue, 9 Nov 2021 18:49:53 +0500 Subject: [PATCH 1/5] Fix the issue with 'at' in interprise twitter and insgram --- app/models/enterprise.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 77b49a9110..beffa5ba4c 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -290,6 +290,14 @@ class Enterprise < ApplicationRecord strip_url self[:linkedin] end + def twitter + correct_social_url self[:twitter] + end + + def instagram + correct_social_url self[:instagram] + end + def inventory_variants if prefers_product_selection_from_inventory_only? Spree::Variant.visible_for(self) @@ -420,6 +428,10 @@ class Enterprise < ApplicationRecord url&.sub(%r{(https?://)?}, '') end + def correct_social_url(url) + url&.include?("@") ? url.delete!("@") : url + 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? From 6f9fc9f06c2e2a1ede868e614402b057162801e0 Mon Sep 17 00:00:00 2001 From: SarvarKhalimov Date: Tue, 9 Nov 2021 23:49:30 +0500 Subject: [PATCH 2/5] Add a new rspec test and optimize existing for correct_social_url --- spec/models/enterprise_spec.rb | 9 ++++++++- spec/system/consumer/registration_spec.rb | 8 ++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/spec/models/enterprise_spec.rb b/spec/models/enterprise_spec.rb index 94130fa444..739663b5ce 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: "@insgram_user", + twitter: "@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 @ 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..bfe14482e1 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: 'TwItTeR' + fill_in 'enterprise_instagram', with: '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" From f8c45b3e319de9da44a7fd740706c099c0bbc08b Mon Sep 17 00:00:00 2001 From: SarvarKhalimov Date: Wed, 10 Nov 2021 07:56:04 +0500 Subject: [PATCH 3/5] Update app/models/enterprise.rb - optimise delete @ method Co-authored-by: Maikel --- app/models/enterprise.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index beffa5ba4c..57b69c0e3d 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -429,7 +429,7 @@ class Enterprise < ApplicationRecord end def correct_social_url(url) - url&.include?("@") ? url.delete!("@") : url + url&.delete("@") end def set_unused_address_fields From c202c52d8b471a42180ca6f13519e212d1a7cf82 Mon Sep 17 00:00:00 2001 From: SarvarKhalimov Date: Mon, 22 Nov 2021 23:31:56 +0500 Subject: [PATCH 4/5] Refactor correct_social_url method in enterprise model and its tests --- app/models/enterprise.rb | 12 ++++++++---- spec/models/enterprise_spec.rb | 6 +++--- spec/system/consumer/registration_spec.rb | 4 ++-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 57b69c0e3d..d82e4e2cb5 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -291,11 +291,11 @@ class Enterprise < ApplicationRecord end def twitter - correct_social_url self[:twitter] + correct_twitter_url self[:twitter] end def instagram - correct_social_url self[:instagram] + correct_instagram_url self[:instagram] end def inventory_variants @@ -428,8 +428,12 @@ class Enterprise < ApplicationRecord url&.sub(%r{(https?://)?}, '') end - def correct_social_url(url) - url&.delete("@") + 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 diff --git a/spec/models/enterprise_spec.rb b/spec/models/enterprise_spec.rb index 739663b5ce..4e1462a636 100644 --- a/spec/models/enterprise_spec.rb +++ b/spec/models/enterprise_spec.rb @@ -562,8 +562,8 @@ describe Enterprise do website: "http://www.google.com", facebook: "www.facebook.com/roger", linkedin: "https://linkedin.com", - instagram: "@insgram_user", - twitter: "@twitter_user") + instagram: "https://www.instagram.com/@insgram_user", + twitter: "www.twitter.com/@twitter_user") } it "strips http from url fields" do @@ -572,7 +572,7 @@ describe Enterprise do expect(distributor.linkedin).to eq("linkedin.com") end - it "strips @ from url fields" do + 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 diff --git a/spec/system/consumer/registration_spec.rb b/spec/system/consumer/registration_spec.rb index bfe14482e1..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!' From 5d36c66aff8d97bf7e1e3317f3751158c9073d27 Mon Sep 17 00:00:00 2001 From: SarvarKhalimov Date: Thu, 25 Nov 2021 01:05:45 +0500 Subject: [PATCH 5/5] Update follow partial to reflect social urls correctly --- app/assets/javascripts/templates/partials/follow.html.haml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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