Fix all the errors to get our tests green on Rails 5.1.

This commit is contained in:
Guo Xiang Tan
2017-08-31 12:06:56 +08:00
parent 898ee93547
commit 77d4c4d8dc
989 changed files with 5114 additions and 3117 deletions

View File

@ -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