[Posts] Fix pool metatags with capital letters (#769)

This commit is contained in:
Donovan Daniels 2024-10-22 17:41:05 -05:00 committed by GitHub
parent 26c681575e
commit b3d3fbc6a0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 4 deletions

View File

@ -509,7 +509,7 @@ class Post < ApplicationRecord
return unless tag_string_diff.present? return unless tag_string_diff.present?
current_tags = tag_array current_tags = tag_array
diff = TagQuery.scan(tag_string_diff.downcase) diff = TagQuery.scan(tag_string_diff)
to_remove, to_add = diff.partition {|x| x =~ /\A-/i} to_remove, to_add = diff.partition {|x| x =~ /\A-/i}
to_remove = to_remove.map {|x| x[1..-1]} to_remove = to_remove.map {|x| x[1..-1]}
to_remove = TagAlias.to_aliased(to_remove) to_remove = TagAlias.to_aliased(to_remove)
@ -696,7 +696,7 @@ class Post < ApplicationRecord
when /^newpool:(.+)$/i when /^newpool:(.+)$/i
pool = Pool.find_by_name($1) pool = Pool.find_by_name($1)
if pool.nil? if pool.nil?
pool = Pool.create(:name => $1, :description => "This pool was automatically generated") pool = Pool.create(name: $1, description: "")
end end
end end
end end
@ -741,7 +741,7 @@ class Post < ApplicationRecord
end end
when /^-pool:(.+)$/i when /^-pool:(.+)$/i
pool = Pool.find_by(name: $1) pool = Pool.find_by_name($1)
if pool if pool
pool.remove!(self) pool.remove!(self)
if pool.errors.any? if pool.errors.any?
@ -759,7 +759,7 @@ class Post < ApplicationRecord
end end
when /^(?:new)?pool:(.+)$/i when /^(?:new)?pool:(.+)$/i
pool = Pool.find_by(name: $1) pool = Pool.find_by_name($1)
if pool if pool
pool.add!(self) pool.add!(self)
if pool.errors.any? if pool.errors.any?

View File

@ -2331,6 +2331,7 @@ class PostTest < ActiveSupport::TestCase
context "pool:" do context "pool:" do
setup do setup do
@pool = create(:pool) @pool = create(:pool)
@pool2 = create(:pool, name: "Test_Pool")
@post = create(:post) @post = create(:post)
end end
@ -2357,6 +2358,12 @@ class PostTest < ActiveSupport::TestCase
assert_equal("pool:#{@pool.id}", @post.pool_string) assert_equal("pool:#{@pool.id}", @post.pool_string)
end end
should "work with capital letters" do
@post.update(tag_string_diff: "pool:#{@pool2.name}")
assert_equal([@post.id], @pool2.reload.post_ids)
assert_equal("pool:#{@pool2.id}", @post.pool_string)
end
should "gracefully fail if the pool is full" do should "gracefully fail if the pool is full" do
Danbooru.config.stubs(:pool_post_limit).returns(0) Danbooru.config.stubs(:pool_post_limit).returns(0)
@post.update(tag_string_diff: "pool:#{@pool.name}") @post.update(tag_string_diff: "pool:#{@pool.name}")
@ -2379,6 +2386,17 @@ class PostTest < ActiveSupport::TestCase
@pool = Pool.last @pool = Pool.last
assert_equal([@post.id], @pool.reload.post_ids) assert_equal([@post.id], @pool.reload.post_ids)
assert_equal("pool:#{@pool.id}", @post.pool_string) assert_equal("pool:#{@pool.id}", @post.pool_string)
assert_equal("test", @pool.name)
end
should "work with capital letters" do
assert_difference("Pool.count", 1) do
@post.update(tag_string_diff: "newpool:Test2_Pool")
end
@pool = Pool.last
assert_equal([@post.id], @pool.reload.post_ids)
assert_equal("pool:#{@pool.id}", @post.pool_string)
assert_equal("Test2_Pool", @pool.name)
end end
end end
end end