diff --git a/app/controllers/admin/candidate_controller.rb b/app/controllers/admin/candidate_controller.rb index 8a289b1..079ecea 100644 --- a/app/controllers/admin/candidate_controller.rb +++ b/app/controllers/admin/candidate_controller.rb @@ -3,8 +3,6 @@ module Admin class CandidateController < AdminController before_action :collect_quizzes, except: [:login, :auth] - helper_method :sort_column - def index @candidates = policy_scope Candidate.order("#{sort_column} #{sort_direction}") .page(params[:page]) diff --git a/app/controllers/admin/result_controller.rb b/app/controllers/admin/result_controller.rb index 0c18024..48bb2b5 100644 --- a/app/controllers/admin/result_controller.rb +++ b/app/controllers/admin/result_controller.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true module Admin class ResultController < AdminController - helper_method :sort_column - # TODO: change context from Candidate to Quiz # bypass pundit lockdowns until completed after_action :skip_policy_scope @@ -32,5 +30,9 @@ module Admin def sort_column @sort_col ||= Candidate.column_names.include?(params[:sort]) ? params[:sort] : 'completed_at' end + + def sort_direction + %w(asc desc).include?(params[:direction]) ? params[:direction] : 'desc' + end end end diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index f71567b..327e1f7 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -10,6 +10,7 @@ class AdminController < ApplicationController after_action :verify_policy_scoped, only: :index helper_method :sort_direction + helper_method :sort_column def current_user @current_user ||= User.find_by(id: session[:user]) if session[:user] @@ -18,8 +19,12 @@ class AdminController < ApplicationController private + def sort_column + :completed_at + end + def sort_direction - %w(asc desc).include?(params[:direction]) ? params[:direction] : 'desc' + %w(asc desc).include?(params[:direction]) ? params[:direction] : 'asc' end def authorize_user diff --git a/test/controllers/admin_controller_test.rb b/test/controllers/admin_controller_test.rb index 6666e23..6084334 100644 --- a/test/controllers/admin_controller_test.rb +++ b/test/controllers/admin_controller_test.rb @@ -9,4 +9,11 @@ class AdminControllerTest < ActionDispatch::IntegrationTest assert_redirected_to admin_login_path assert_match 'not authorized', flash[:error] end + + test 'sort_column present' do + # a stupid coverage report thing. + admin_controller = AdminController.new + + assert_equal :completed_at, admin_controller.send(:sort_column) + end end