FIX: Support links with google analytics tracking and hashes
This commit is contained in:
parent
e06be6561d
commit
1468616465
|
@ -27,7 +27,12 @@ class TopicLinkClick < ActiveRecord::Base
|
|||
end
|
||||
urls << UrlHelper.absolute_without_cdn(url)
|
||||
urls << uri.path if uri.try(:host) == Discourse.current_hostname
|
||||
urls << url.sub(/\?.*$/, '') if url.include?('?')
|
||||
|
||||
query = url.index('?')
|
||||
unless query.nil?
|
||||
endpos = url.index('#') || url.size
|
||||
urls << url[0..query-1] + url[endpos..-1]
|
||||
end
|
||||
|
||||
# add a cdn link
|
||||
if uri
|
||||
|
|
|
@ -114,6 +114,7 @@ And a link to google: http://google.com
|
|||
And a secure link to google: https://google.com
|
||||
And a markdown link: [forumwarz](http://forumwarz.com)
|
||||
And a markdown link with a period after it [codinghorror](http://www.codinghorror.com/blog).
|
||||
And one with a hash http://discourse.org#faq
|
||||
"
|
||||
end
|
||||
|
||||
|
|
|
@ -177,6 +177,36 @@ describe TopicLinkClick do
|
|||
end
|
||||
end
|
||||
|
||||
context 'with a google analytics tracking code' do
|
||||
before do
|
||||
@url = TopicLinkClick.create_from(url: 'http://twitter.com?_ga=1.16846778.221554446.1071987018',
|
||||
topic_id: @topic.id,
|
||||
ip: '127.0.0.3')
|
||||
@click = TopicLinkClick.last
|
||||
end
|
||||
|
||||
it 'creates a click' do
|
||||
expect(@click).to be_present
|
||||
expect(@click.topic_link).to eq(@topic_link)
|
||||
expect(@url).to eq('http://twitter.com?_ga=1.16846778.221554446.1071987018')
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a google analytics tracking code and a hash' do
|
||||
before do
|
||||
@url = TopicLinkClick.create_from(url: 'http://discourse.org?_ga=1.16846778.221554446.1071987018#faq',
|
||||
topic_id: @topic.id,
|
||||
ip: '127.0.0.3')
|
||||
@click = TopicLinkClick.last
|
||||
end
|
||||
|
||||
it 'creates a click' do
|
||||
expect(@click).to be_present
|
||||
expect(@url).to eq('http://discourse.org?_ga=1.16846778.221554446.1071987018#faq')
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
context 'with a valid url and topic_id' do
|
||||
before do
|
||||
@url = TopicLinkClick.create_from(url: @topic_link.url, topic_id: @topic.id, ip: '127.0.0.3')
|
||||
|
|
|
@ -304,7 +304,7 @@ http://b.com/#{'a'*500}
|
|||
expect(counts_for[post.id].first[:clicks]).to eq(1)
|
||||
|
||||
array = TopicLink.topic_map(Guardian.new, post.topic_id)
|
||||
expect(array.length).to eq(5)
|
||||
expect(array.length).to eq(6)
|
||||
expect(array[0]["clicks"]).to eq("1")
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue