Merge pull request #4158 from mcwumbly/show-website-path-in-website-name
UX: Show website path in website name for all domains
This commit is contained in:
commit
d6b4b990a6
|
@ -144,19 +144,9 @@ class UserSerializer < BasicUserSerializer
|
||||||
end
|
end
|
||||||
|
|
||||||
def website_name
|
def website_name
|
||||||
website_host = URI(website.to_s).host rescue nil
|
uri = URI(website.to_s) rescue nil
|
||||||
discourse_host = Discourse.current_hostname
|
return if uri.nil? || uri.host.nil?
|
||||||
return if website_host.nil?
|
uri.host + uri.path
|
||||||
if website_host == discourse_host
|
|
||||||
# example.com == example.com
|
|
||||||
website_host + URI(website.to_s).path
|
|
||||||
elsif (website_host.split('.').length == discourse_host.split('.').length) && discourse_host.split('.').length > 2
|
|
||||||
# www.example.com == forum.example.com
|
|
||||||
website_host.split('.')[1..-1].join('.') == discourse_host.split('.')[1..-1].join('.') ? website_host + URI(website.to_s).path : website_host
|
|
||||||
else
|
|
||||||
# example.com == forum.example.com
|
|
||||||
discourse_host.ends_with?("." << website_host) ? website_host + URI(website.to_s).path : website_host
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def include_website_name
|
def include_website_name
|
||||||
|
|
|
@ -96,22 +96,37 @@ describe UserSerializer do
|
||||||
expect(json[:website]).to eq 'http://example.com/user'
|
expect(json[:website]).to eq 'http://example.com/user'
|
||||||
end
|
end
|
||||||
|
|
||||||
context "has a website name" do
|
it "returns complete website name with path" do
|
||||||
it "returns website host name when instance domain is not same as website domain" do
|
|
||||||
Discourse.stubs(:current_hostname).returns('discourse.org')
|
|
||||||
expect(json[:website_name]).to eq 'example.com'
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns complete website path when instance domain is same as website domain" do
|
|
||||||
Discourse.stubs(:current_hostname).returns('example.com')
|
|
||||||
expect(json[:website_name]).to eq 'example.com/user'
|
expect(json[:website_name]).to eq 'example.com/user'
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns complete website path when website domain is parent of instance domain" do
|
context "when website includes query parameters" do
|
||||||
Discourse.stubs(:current_hostname).returns('forums.example.com')
|
before do
|
||||||
|
user.user_profile.website = 'http://example.com/user?ref=payme'
|
||||||
|
end
|
||||||
|
|
||||||
|
it "has a website with query params" do
|
||||||
|
expect(json[:website]).to eq 'http://example.com/user?ref=payme'
|
||||||
|
end
|
||||||
|
|
||||||
|
it "has a website name without query params" do
|
||||||
expect(json[:website_name]).to eq 'example.com/user'
|
expect(json[:website_name]).to eq 'example.com/user'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "when website is not a valid url" do
|
||||||
|
before do
|
||||||
|
user.user_profile.website = 'invalid-url'
|
||||||
|
end
|
||||||
|
|
||||||
|
it "has a website with the invalid url" do
|
||||||
|
expect(json[:website]).to eq 'invalid-url'
|
||||||
|
end
|
||||||
|
|
||||||
|
it "has a nil website name" do
|
||||||
|
expect(json[:website_name]).to eq nil
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with filled out bio" do
|
context "with filled out bio" do
|
||||||
|
|
Loading…
Reference in New Issue