FIX: Account for nil when looking up subcategories

This commit is contained in:
Daniel Waterworth 2019-10-16 20:03:52 +01:00
parent baf8ae604a
commit 7a0c06691c
2 changed files with 5 additions and 1 deletions

View File

@ -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

View File

@ -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")