A platform for community discussion. Free, open, simple.
FIX: on edit, ensure community section remains at top of sidebar (#36597)
Kris8dd7ec8d54be
diff --git a/app/controllers/sidebar_sections_controller.rb b/app/controllers/sidebar_sections_controller.rbindex 2cffa13589f..957f1848fea 100644--- a/app/controllers/sidebar_sections_controller.rb+++ b/app/controllers/sidebar_sections_controller.rb@@ -10,7 +10,7 @@ class SidebarSectionsController < ApplicationController.strict_loading.includes(:sidebar_urls).where("public OR user_id = ?", current_user.id)- .order("(public IS TRUE) DESC, title ASC")+ .order("section_type IS NOT NULL DESC, public DESC, title ASC")sections =ActiveModel::ArraySerializer.new(diff --git a/spec/requests/sidebar_sections_controller_spec.rb b/spec/requests/sidebar_sections_controller_spec.rbindex 75d5847e1f3..739c292db16 100644--- a/spec/requests/sidebar_sections_controller_spec.rb+++ b/spec/requests/sidebar_sections_controller_spec.rb@@ -25,6 +25,18 @@ RSpec.describe SidebarSectionsController do["Community", "public section", "private section"],)end++ it "returns Community section first even when public sections are alphabetically before it" do+ sign_in(user)+ Fabricate(:sidebar_section, title: "Apple", public: true)++ get "/sidebar_sections.json"+ expect(response.status).to eq(200)++ titles = response.parsed_body["sidebar_sections"].map { |section| section["title"] }++ expect(titles).to eq(["Community", "Apple", "public section", "private section"])+ endenddescribe "#create" do