diff options
author | Tiago Botelho <tiagonbotelho@hotmail.com> | 2016-12-20 21:52:09 +0300 |
---|---|---|
committer | Tiago Botelho <tiagonbotelho@hotmail.com> | 2016-12-22 02:53:24 +0300 |
commit | 805bbe889328bff55b49290294721405148cc980 (patch) | |
tree | 0beb7c9621db87d5f11928ca8231af8b1de21a6c /app | |
parent | 9b66aa6e04ab66af7ce11e26076ebf431ca938c5 (diff) |
adds specs for respective behaviour
Diffstat (limited to 'app')
5 files changed, 16 insertions, 17 deletions
diff --git a/app/controllers/concerns/kaminari_pagination.rb b/app/controllers/concerns/kaminari_pagination.rb deleted file mode 100644 index b69340cac0e..00000000000 --- a/app/controllers/concerns/kaminari_pagination.rb +++ /dev/null @@ -1,8 +0,0 @@ -module KaminariPagination - extend ActiveSupport::Concern - - def bounded_pagination(items, page_number) - items = items.page(page_number) - items.to_a.empty? ? items.page(items.total_pages) : items - end -end diff --git a/app/controllers/dashboard/todos_controller.rb b/app/controllers/dashboard/todos_controller.rb index b2333a02392..40652129f4c 100644 --- a/app/controllers/dashboard/todos_controller.rb +++ b/app/controllers/dashboard/todos_controller.rb @@ -1,11 +1,12 @@ class Dashboard::TodosController < Dashboard::ApplicationController - include KaminariPagination - before_action :find_todos, only: [:index, :destroy_all] def index @sort = params[:sort] - @todos = bounded_pagination(@todos, params[:page]) + @todos = @todos.page(params[:page]) + if @todos.out_of_range? && @todos.total_pages != 0 + redirect_to dashboard_todos_path(page: @todos.total_pages) + end end def destroy diff --git a/app/controllers/projects/issues_controller.rb b/app/controllers/projects/issues_controller.rb index ec09a5297fc..0efeec98570 100644 --- a/app/controllers/projects/issues_controller.rb +++ b/app/controllers/projects/issues_controller.rb @@ -5,7 +5,6 @@ class Projects::IssuesController < Projects::ApplicationController include ToggleAwardEmoji include IssuableCollections include SpammableActions - include KaminariPagination before_action :redirect_to_external_issue_tracker, only: [:index, :new] before_action :module_enabled @@ -25,7 +24,10 @@ class Projects::IssuesController < Projects::ApplicationController def index @issues = issues_collection - @issues = bounded_pagination(@issues, params[:page]) + @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) + end if params[:label_name].present? @labels = LabelsFinder.new(current_user, project_id: @project.id, title: params[:label_name]).execute diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb index e25eea52723..050d0ca77ae 100644 --- a/app/controllers/projects/merge_requests_controller.rb +++ b/app/controllers/projects/merge_requests_controller.rb @@ -6,7 +6,6 @@ class Projects::MergeRequestsController < Projects::ApplicationController include NotesHelper include ToggleAwardEmoji include IssuableCollections - include KaminariPagination before_action :module_enabled before_action :merge_request, only: [ @@ -38,7 +37,10 @@ class Projects::MergeRequestsController < Projects::ApplicationController def index @merge_requests = merge_requests_collection - @merge_requests = bounded_pagination(@merge_requests, params[:page]) + @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) + end if params[:label_name].present? labels_params = { project_id: @project.id, title: params[:label_name] } diff --git a/app/controllers/projects/snippets_controller.rb b/app/controllers/projects/snippets_controller.rb index 7083b29b6a3..02a97c1c574 100644 --- a/app/controllers/projects/snippets_controller.rb +++ b/app/controllers/projects/snippets_controller.rb @@ -1,6 +1,5 @@ class Projects::SnippetsController < Projects::ApplicationController include ToggleAwardEmoji - include KaminariPagination before_action :module_enabled before_action :snippet, only: [:show, :edit, :destroy, :update, :raw, :toggle_award_emoji] @@ -26,7 +25,10 @@ class Projects::SnippetsController < Projects::ApplicationController project: @project, scope: params[:scope] ) - @snippets = bounded_pagination(@snippets, params[:page]) + @snippets = @snippets.page(params[:page]) + if @snippets.out_of_range? && @snippets.total_pages != 0 + redirect_to namespace_project_snippets_path(page: @snippets.total_pages) + end end def new |