forked from e621ng/e621ng
[Tags] Fix category for non-existant tags
Regressed in 4cd32c5f87
Caching nil as a category can cause problems in a bunch of places
This commit is contained in:
parent
814b722c95
commit
12e996dc08
@ -129,7 +129,7 @@ class Pool < ApplicationRecord
|
||||
if name =~ /\A\d+\z/
|
||||
name.to_i
|
||||
else
|
||||
Pool.where("lower(name) = ?", name.downcase.tr(" ", "_")).pick(:id)
|
||||
Pool.where("lower(name) = ?", name.downcase.tr(" ", "_")).pick(:id).to_i
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -42,7 +42,7 @@ class PostSet < ApplicationRecord
|
||||
if name =~ /\A\d+\z/
|
||||
name.to_i
|
||||
else
|
||||
PostSet.where("lower(shortname) = ?", name.downcase.tr(" ", "_")).pick(:id)
|
||||
PostSet.where("lower(shortname) = ?", name.downcase.tr(" ", "_")).pick(:id).to_i
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -119,7 +119,7 @@ class Tag < ApplicationRecord
|
||||
|
||||
def category_for(tag_name)
|
||||
Cache.fetch("tc:#{tag_name}") do
|
||||
Tag.where(name: tag_name).pick(:category)
|
||||
Tag.where(name: tag_name).pick(:category).to_i
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -17,6 +17,10 @@ class TagTest < ActiveSupport::TestCase
|
||||
assert_equal(Tag.categories.artist, Tag.category_for("!@ab"))
|
||||
end
|
||||
|
||||
should "return general for a tag that doesn't exist" do
|
||||
assert_equal(Tag.categories.general, Tag.category_for("missing"))
|
||||
end
|
||||
|
||||
should "fetch for multiple tags" do
|
||||
create(:artist_tag, name: "aaa")
|
||||
create(:copyright_tag, name: "bbb")
|
||||
|
Loading…
Reference in New Issue
Block a user