mirror of
https://github.com/discourse/discourse.git
synced 2025-05-25 09:57:25 +08:00
Fix all the errors to get our tests green on Rails 5.1.
This commit is contained in:
@ -6,12 +6,12 @@ describe ClicksController do
|
||||
|
||||
context 'missing params' do
|
||||
it 'raises a 404 without the url param' do
|
||||
xhr :get, :track, post_id: 123
|
||||
get :track, params: { post_id: 123 }, format: :json
|
||||
expect(response).to be_not_found
|
||||
end
|
||||
|
||||
it "redirects to the url even without the topic_id or post_id params" do
|
||||
xhr :get, :track, url: 'http://google.com'
|
||||
get :track, params: { url: 'http://google.com' }, format: :json
|
||||
expect(response).not_to be_redirect
|
||||
end
|
||||
end
|
||||
@ -19,12 +19,18 @@ describe ClicksController do
|
||||
context 'correct params' do
|
||||
let(:url) { "http://discourse.org" }
|
||||
|
||||
before { request.stubs(:remote_ip).returns('192.168.0.1') }
|
||||
before do
|
||||
request.headers.merge!('REMOTE_ADDR' => '192.168.0.1')
|
||||
end
|
||||
|
||||
context "with a made up url" do
|
||||
it "doesn't redirect" do
|
||||
TopicLinkClick.expects(:create_from).returns(nil)
|
||||
xhr :get, :track, url: 'http://discourse.org', post_id: 123
|
||||
|
||||
get :track,
|
||||
params: { url: 'http://discourse.org', post_id: 123 },
|
||||
format: :json
|
||||
|
||||
expect(response).not_to be_redirect
|
||||
end
|
||||
end
|
||||
@ -32,7 +38,11 @@ describe ClicksController do
|
||||
context "with a query string" do
|
||||
it "redirects" do
|
||||
TopicLinkClick.expects(:create_from).with(has_entries('url' => 'http://discourse.org/?hello=123')).returns(url)
|
||||
xhr :get, :track, url: 'http://discourse.org/?hello=123', post_id: 123
|
||||
|
||||
get :track, params: {
|
||||
url: 'http://discourse.org/?hello=123', post_id: 123, format: :json
|
||||
}
|
||||
|
||||
expect(response).to redirect_to(url)
|
||||
end
|
||||
end
|
||||
@ -40,13 +50,17 @@ describe ClicksController do
|
||||
context 'with a post_id' do
|
||||
it 'redirects' do
|
||||
TopicLinkClick.expects(:create_from).with('url' => url, 'post_id' => '123', 'ip' => '192.168.0.1').returns(url)
|
||||
xhr :get, :track, url: url, post_id: 123
|
||||
get :track, params: { url: url, post_id: 123, format: :json }
|
||||
expect(response).to redirect_to(url)
|
||||
end
|
||||
|
||||
it "doesn't redirect with the redirect=false param" do
|
||||
TopicLinkClick.expects(:create_from).with('url' => url, 'post_id' => '123', 'ip' => '192.168.0.1', 'redirect' => 'false').returns(url)
|
||||
xhr :get, :track, url: url, post_id: 123, redirect: 'false'
|
||||
|
||||
get :track, params: {
|
||||
url: url, post_id: 123, redirect: 'false', format: :json
|
||||
}
|
||||
|
||||
expect(response).not_to be_redirect
|
||||
end
|
||||
|
||||
@ -55,7 +69,7 @@ describe ClicksController do
|
||||
context 'with a topic_id' do
|
||||
it 'redirects' do
|
||||
TopicLinkClick.expects(:create_from).with('url' => url, 'topic_id' => '789', 'ip' => '192.168.0.1').returns(url)
|
||||
xhr :get, :track, url: url, topic_id: 789
|
||||
get :track, params: { url: url, topic_id: 789, format: :json }
|
||||
expect(response).to redirect_to(url)
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user