BigW Consortium Gitlab

Commit d7a2e92c by Tiago Botelho

applies url_for so that we dont lose filters when redirecting

parent 805bbe88
......@@ -5,7 +5,7 @@ class Dashboard::TodosController < Dashboard::ApplicationController
@sort = params[:sort]
@todos = @todos.page(params[:page])
if @todos.out_of_range? && @todos.total_pages != 0
redirect_to dashboard_todos_path(page: @todos.total_pages)
redirect_to url_for(params.merge(page: @todos.total_pages))
end
end
......
......@@ -26,7 +26,7 @@ class Projects::IssuesController < Projects::ApplicationController
@issues = issues_collection
@issues = @issues.page(params[:page])
if @issues.out_of_range? && @issues.total_pages != 0
return redirect_to namespace_project_issues_path(page: @issues.total_pages)
return redirect_to url_for(params.merge(page: @issues.total_pages))
end
if params[:label_name].present?
......
......@@ -39,7 +39,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
@merge_requests = merge_requests_collection
@merge_requests = @merge_requests.page(params[:page])
if @merge_requests.out_of_range? && @merge_requests.total_pages != 0
return redirect_to namespace_project_merge_requests_path(page: @merge_requests.total_pages)
return redirect_to url_for(params.merge(page: @merge_requests.total_pages))
end
if params[:label_name].present?
......
......@@ -13,10 +13,11 @@ describe Dashboard::TodosController do
context 'when using pagination' do
let(:last_page) { user.todos.page().total_pages }
let!(:issues) { create_list(:issue, 30, project: project, assignee: user) }
let!(:issues) { create_list(:issue, 2, project: project, assignee: user) }
before do
issues.each { |issue| todo_service.new_issue(issue, user) }
allow(Kaminari.config).to receive(:default_per_page).and_return(1)
end
it 'redirects to last_page if page number is larger than number of pages' do
......
......@@ -55,11 +55,12 @@ describe Projects::IssuesController do
context 'with page param' do
let(:last_page) { project.issues.page().total_pages }
let!(:issue_list) { create_list(:issue, 30, project: project) }
let!(:issue_list) { create_list(:issue, 2, project: project) }
before do
sign_in(user)
project.team << [user, :developer]
allow(Kaminari.config).to receive(:default_per_page).and_return(1)
end
it 'redirects to last_page if page number is larger than number of pages' do
......@@ -68,7 +69,7 @@ describe Projects::IssuesController do
project_id: project.path.to_param,
page: (last_page + 1).to_param
expect(response).to redirect_to(namespace_project_issues_path(page: last_page))
expect(response).to redirect_to(namespace_project_issues_path(page: last_page, state: controller.params[:state], scope: controller.params[:scope]))
end
it 'redirects to specified page' do
......
......@@ -127,9 +127,6 @@ describe Projects::MergeRequestsController do
end
describe 'GET index' do
let(:last_page) { project.merge_requests.page().total_pages }
let!(:merge_request) { create(:merge_request_with_diffs, target_project: project, source_project: project) }
def get_merge_requests(page = nil)
get :index,
namespace_id: project.namespace.to_param,
......@@ -138,10 +135,13 @@ describe Projects::MergeRequestsController do
end
context 'when page param' do
let(:last_page) { project.merge_requests.page().total_pages }
let!(:merge_request) { create(:merge_request_with_diffs, target_project: project, source_project: project) }
it 'redirects to last_page if page number is larger than number of pages' do
get_merge_requests(last_page + 1)
expect(response).to redirect_to(namespace_project_merge_requests_path(page: last_page))
expect(response).to redirect_to(namespace_project_merge_requests_path(page: last_page, state: controller.params[:state], scope: controller.params[:scope]))
end
it 'redirects to specified page' do
......
......@@ -26,7 +26,7 @@ describe Projects::SnippetsController do
it 'redirects to specified page' do
get :index,
namespace_id: project.namespace.path,
project_id: project.path, page: (last_page).to_param
project_id: project.path, page: last_page.to_param
expect(assigns(:snippets).current_page).to eq(last_page)
expect(response).to have_http_status(200)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment