FIX: Account for nil when looking up subcategories
This commit is contained in:
parent
baf8ae604a
commit
7a0c06691c
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in New Issue