bug fix for saved search update on tag batch changes
This commit is contained in:
@@ -22,10 +22,10 @@ module Moderator
|
|||||||
|
|
||||||
tags = Tag.scan_tags(antecedent, :strip_metatags => true)
|
tags = Tag.scan_tags(antecedent, :strip_metatags => true)
|
||||||
conds = tags.map {|x| "tag_query like ?"}.join(" AND ")
|
conds = tags.map {|x| "tag_query like ?"}.join(" AND ")
|
||||||
conds = [conds, *tags.map {|x| "%#{x}%"}]
|
conds = [conds, *tags.map {|x| "%#{x.to_escaped_for_sql_like}%"}]
|
||||||
if SavedSearch.enabled?
|
if SavedSearch.enabled?
|
||||||
SavedSearch.where(*conds).find_each do |ss|
|
SavedSearch.where(*conds).find_each do |ss|
|
||||||
ss.tag_query = (ss.tag_query_array - tags + antecedent).uniq.join(" ")
|
ss.tag_query = (ss.tag_query_array - tags + [consequent]).uniq.join(" ")
|
||||||
ss.save
|
ss.save
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,7 +1,18 @@
|
|||||||
require "test_helper"
|
require "test_helper"
|
||||||
|
require 'helpers/saved_search_test_helper'
|
||||||
|
|
||||||
module Moderator
|
module Moderator
|
||||||
class TagBatchChangeTest < ActiveSupport::TestCase
|
class TagBatchChangeTest < ActiveSupport::TestCase
|
||||||
|
include SavedSearchTestHelper
|
||||||
|
|
||||||
|
def setup
|
||||||
|
super
|
||||||
|
mock_saved_search_service!
|
||||||
|
Danbooru.config.stubs(:listbooru_enabled?).returns(true)
|
||||||
|
Danbooru.config.stubs(:listbooru_auth_key).returns("blahblahblah")
|
||||||
|
Danbooru.config.stubs(:listbooru_server).returns("http://localhost:3001")
|
||||||
|
end
|
||||||
|
|
||||||
context "a tag batch change" do
|
context "a tag batch change" do
|
||||||
setup do
|
setup do
|
||||||
@user = FactoryGirl.create(:moderator_user)
|
@user = FactoryGirl.create(:moderator_user)
|
||||||
@@ -27,7 +38,8 @@ module Moderator
|
|||||||
tag_batch_change = TagBatchChange.new("...", "bbb", @user.id, "127.0.0.1")
|
tag_batch_change = TagBatchChange.new("...", "bbb", @user.id, "127.0.0.1")
|
||||||
tag_batch_change.perform
|
tag_batch_change.perform
|
||||||
ss.reload
|
ss.reload
|
||||||
assert_equal("123 bbb 456", ss.tag_query)
|
assert_equal("123 456 bbb", ss.tag_query)
|
||||||
|
assert_equal(%w(create update), SavedSearch.sqs_service.commands)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "raise an error if there is no predicate" do
|
should "raise an error if there is no predicate" do
|
||||||
|
|||||||
Reference in New Issue
Block a user