BURs: change default order on index page to newest BURs first.

Change the /bulk_update_requests page to show the newest BURs first
instead of pending BURs first. This is more consistent with index pages
on the rest of the site, which normally default to newest first. Fixes
an issue where failed BURs would be shown first forever unless they were
manually approved or rejected.
This commit is contained in:
evazion
2021-11-02 04:11:09 -05:00
parent 148752d3c4
commit 9a9649bee8
2 changed files with 3 additions and 7 deletions

View File

@@ -18,7 +18,7 @@ class BulkUpdateRequest < ApplicationRecord
before_save :update_tags, if: :script_changed?
after_create :create_forum_topic
scope :pending_first, -> { order(Arel.sql("(case status when 'failed' then 0 when 'processing' then 1 when 'pending' then 2 when 'approved' then 3 when 'rejected' then 4 else 5 end)")) }
scope :pending_first, -> { order(Arel.sql("(case status when 'processing' then 0 when 'pending' then 1 when 'approved' then 2 when 'rejected' then 3 when 'failed' then 4 else 5 end)")) }
scope :pending, -> {where(status: "pending")}
scope :approved, -> { where(status: "approved") }
scope :rejected, -> { where(status: "rejected") }
@@ -27,10 +27,6 @@ class BulkUpdateRequest < ApplicationRecord
scope :has_topic, -> { where.not(forum_topic: nil) }
module SearchMethods
def default_order
pending_first.order(id: :desc)
end
def search(params = {})
q = search_attributes(params, :id, :created_at, :updated_at, :script, :tags, :user, :forum_topic, :forum_post, :approver)
q = q.text_attribute_matches(:script, params[:script_matches])

View File

@@ -85,7 +85,7 @@ class BulkUpdateRequestsControllerTest < ActionDispatch::IntegrationTest
assert_response :success
end
should respond_to_search({}).with { [@other_BUR, @bulk_update_request, @approved_BUR, @rejected_BUR] }
should respond_to_search({}).with { [@approved_BUR, @rejected_BUR, @other_BUR, @bulk_update_request] }
should respond_to_search(order: "id_desc").with { [@approved_BUR, @rejected_BUR, @other_BUR, @bulk_update_request] }
should respond_to_search(status: "pending").with { [@other_BUR, @bulk_update_request] }
should respond_to_search(script_matches: "cirno -> 9").with { @other_BUR }
@@ -97,7 +97,7 @@ class BulkUpdateRequestsControllerTest < ActionDispatch::IntegrationTest
should respond_to_search(user_id: 999).with { @bulk_update_request }
should respond_to_search(user: {level: User::Levels::BUILDER}).with { @other_BUR }
should respond_to_search(has_approver: "true").with { @approved_BUR }
should respond_to_search(has_approver: "false").with { [@other_BUR, @bulk_update_request, @rejected_BUR] }
should respond_to_search(has_approver: "false").with { [@rejected_BUR, @other_BUR, @bulk_update_request] }
end
end