mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Make category-drop work with lazy_load_categories (#24187)
The category drop was rerendered after every category async change because it updated the categories list. This is not necessary and categories can be referenced indirectly by ID instead.
This commit is contained in:
@@ -1298,6 +1298,8 @@ RSpec.describe Category do
|
||||
let(:guardian) { Guardian.new(admin) }
|
||||
fab!(:category)
|
||||
|
||||
before { Category.clear_parent_ids }
|
||||
|
||||
describe "when category is uncategorized" do
|
||||
it "should return the reason" do
|
||||
category = Category.find(SiteSetting.uncategorized_category_id)
|
||||
|
||||
@@ -79,10 +79,7 @@
|
||||
"items": {}
|
||||
},
|
||||
"has_children": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
"type": "boolean"
|
||||
},
|
||||
"sort_order": {
|
||||
"type": [
|
||||
|
||||
@@ -82,10 +82,7 @@
|
||||
"items": {}
|
||||
},
|
||||
"has_children": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
"type": "boolean"
|
||||
},
|
||||
"sort_order": {
|
||||
"type": [
|
||||
|
||||
@@ -1040,6 +1040,31 @@ RSpec.describe CategoriesController do
|
||||
end
|
||||
end
|
||||
|
||||
describe "#find" do
|
||||
fab!(:category) { Fabricate(:category, name: "Foo") }
|
||||
fab!(:subcategory) { Fabricate(:category, name: "Foobar", parent_category: category) }
|
||||
|
||||
it "returns the category" do
|
||||
get "/categories/find.json",
|
||||
params: {
|
||||
category_slug_path_with_id: "#{category.slug}/#{category.id}",
|
||||
}
|
||||
|
||||
expect(response.parsed_body["category"]["id"]).to eq(category.id)
|
||||
expect(response.parsed_body["ancestors"]).to eq([])
|
||||
end
|
||||
|
||||
it "returns the subcategory and ancestors" do
|
||||
get "/categories/find.json",
|
||||
params: {
|
||||
category_slug_path_with_id: "#{subcategory.slug}/#{subcategory.id}",
|
||||
}
|
||||
|
||||
expect(response.parsed_body["category"]["id"]).to eq(subcategory.id)
|
||||
expect(response.parsed_body["ancestors"].map { |c| c["id"] }).to eq([category.id])
|
||||
end
|
||||
end
|
||||
|
||||
describe "#search" do
|
||||
fab!(:category) { Fabricate(:category, name: "Foo") }
|
||||
fab!(:subcategory) { Fabricate(:category, name: "Foobar", parent_category: category) }
|
||||
@@ -1066,9 +1091,8 @@ RSpec.describe CategoriesController do
|
||||
it "returns categories" do
|
||||
get "/categories/search.json", params: { parent_category_id: category.id }
|
||||
|
||||
expect(response.parsed_body["categories"].size).to eq(2)
|
||||
expect(response.parsed_body["categories"].size).to eq(1)
|
||||
expect(response.parsed_body["categories"].map { |c| c["name"] }).to contain_exactly(
|
||||
"Foo",
|
||||
"Foobar",
|
||||
)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user