diff --git a/app/models/concerns/category_hashtag.rb b/app/models/concerns/category_hashtag.rb index 8e61329b93e..5a8c92f92c7 100644 --- a/app/models/concerns/category_hashtag.rb +++ b/app/models/concerns/category_hashtag.rb @@ -12,7 +12,7 @@ module CategoryHashtag category = Category.where(slug: parent_slug, parent_category_id: nil) if child_slug - Category.where(slug: child_slug, parent_category_id: category.pluck(:id).first).first + Category.where(slug: child_slug, parent_category_id: category.select(:id)).first else category.first end diff --git a/spec/components/concern/category_hashtag_spec.rb b/spec/components/concern/category_hashtag_spec.rb index e446fc27d2f..3d59995babf 100644 --- a/spec/components/concern/category_hashtag_spec.rb +++ b/spec/components/concern/category_hashtag_spec.rb @@ -25,6 +25,10 @@ describe CategoryHashtag do expect(Category.query_from_hashtag_slug("random-slug#{CategoryHashtag::SEPARATOR}random-slug")).to eq(nil) end + it "should return nil for a non-existent root and a parent subcategory" do + expect(Category.query_from_hashtag_slug("non-existent#{CategoryHashtag::SEPARATOR}#{parent_category.slug}")).to eq(nil) + end + it "should be case sensitive" do parent_category.update!(slug: "ApPlE") child_category.update!(slug: "OraNGE")