From 2cbd87c08cc9a437a40a5b6af90543b7e55f76b5 Mon Sep 17 00:00:00 2001 From: David McClure Date: Mon, 11 Apr 2016 07:13:33 -0700 Subject: [PATCH] Remove www. from website name --- app/serializers/user_serializer.rb | 2 +- spec/serializers/user_serializer_spec.rb | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/app/serializers/user_serializer.rb b/app/serializers/user_serializer.rb index ff498b7b372..d06899f269e 100644 --- a/app/serializers/user_serializer.rb +++ b/app/serializers/user_serializer.rb @@ -146,7 +146,7 @@ class UserSerializer < BasicUserSerializer def website_name uri = URI(website.to_s) rescue nil return if uri.nil? || uri.host.nil? - uri.host + uri.path + uri.host.sub(/^www\./,'') + uri.path end def include_website_name diff --git a/spec/serializers/user_serializer_spec.rb b/spec/serializers/user_serializer_spec.rb index 0dd8ab16f95..84a588b0d25 100644 --- a/spec/serializers/user_serializer_spec.rb +++ b/spec/serializers/user_serializer_spec.rb @@ -104,15 +104,29 @@ describe UserSerializer do context "when website has a subdomain" do before do - user.user_profile.website = 'http://www.example.com/user' + user.user_profile.website = 'http://subdomain.example.com/user' end it "has a website with a subdomain" do - expect(json[:website]).to eq 'http://www.example.com/user' + expect(json[:website]).to eq 'http://subdomain.example.com/user' end it "returns website name with the subdomain" do - expect(json[:website_name]).to eq 'www.example.com/user' + expect(json[:website_name]).to eq 'subdomain.example.com/user' + end + end + + context "when website has www" do + before do + user.user_profile.website = 'http://www.example.com/user' + end + + it "has a website with the www" do + expect(json[:website]).to eq 'http://www.example.com/user' + end + + it "returns website name without the www" do + expect(json[:website_name]).to eq 'example.com/user' end end