Skip to content

Commit

Permalink
FIX: Look up a url without the query string if it couldn't be found w…
Browse files Browse the repository at this point in the history
…ith it.
  • Loading branch information
eviltrout committed Dec 13, 2013
1 parent 26e75c5 commit 06e9cbc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/controllers/clicks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ def track
if params[:topic_id].present? || params[:post_id].present?
params.merge!({ user_id: current_user.id }) if current_user.present?
@redirect_url = TopicLinkClick.create_from(params)

if @redirect_url.blank? && params[:url].index('?')
# Check the url without query parameters
params[:url].sub!(/\?.*$/, '')
@redirect_url = TopicLinkClick.create_from(params)
end
end

# Sometimes we want to record a link without a 302. Since XHR has to load the redirected
Expand Down
7 changes: 7 additions & 0 deletions spec/controllers/clicks_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@
xhr :get, :track, url: 'http://discourse.org', post_id: 123
response.should_not be_redirect
end
end

context "with a query string" do
it "tries again without the query if it fails" do
TopicLinkClick.expects(:create_from).with(has_entries('url' => 'http://discourse.org/?hello=123')).returns(nil)
TopicLinkClick.expects(:create_from).with(has_entries('url' => 'http://discourse.org/')).returns(nil)
xhr :get, :track, url: 'http://discourse.org/?hello=123', post_id: 123
end
end

context 'with a post_id' do
Expand Down

0 comments on commit 06e9cbc

Please sign in to comment.