mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: TopicQuery for NULL category.topic_id (#20664)
Our schema allows `category.topic_id` to be NULL. Null values shouldn't actually happen in production, but it is very common in tests because `Fabricate(:category)` skips creating the definition topic to improve performance. Before this commit, a NULL category.topic_id would cause all subcategory topics to be excluded from a TopicQuery result. This is because, in postgres, `NULL <> anything` is falsy. Instead, we can use `IS DISTINCT FROM`, which will return true when NULL is compared to a non-NULL value.
This commit is contained in:
@@ -131,10 +131,17 @@ RSpec.describe CategoriesController do
|
||||
category_list = response.parsed_body["category_list"]
|
||||
|
||||
category_response = category_list["categories"].find { |c| c["id"] == category.id }
|
||||
expect(category_response["topics"].map { |c| c["id"] }).to contain_exactly(topic1.id)
|
||||
expect(category_response["topics"].map { |c| c["id"] }).to contain_exactly(
|
||||
topic1.id,
|
||||
topic2.id,
|
||||
topic3.id,
|
||||
)
|
||||
|
||||
subcategory_response = category_response["subcategory_list"][0]
|
||||
expect(subcategory_response["topics"].map { |c| c["id"] }).to contain_exactly(topic2.id)
|
||||
expect(subcategory_response["topics"].map { |c| c["id"] }).to contain_exactly(
|
||||
topic2.id,
|
||||
topic3.id,
|
||||
)
|
||||
|
||||
subsubcategory_response = subcategory_response["subcategory_list"][0]
|
||||
expect(subsubcategory_response["topics"].map { |c| c["id"] }).to contain_exactly(topic3.id)
|
||||
|
||||
Reference in New Issue
Block a user