add post count estimates for bulk update requests

This commit is contained in:
Albert Yi
2019-01-09 15:54:55 -08:00
parent 844b1a81ba
commit f33b23d035
11 changed files with 112 additions and 17 deletions

View File

@@ -1,21 +1,5 @@
module SavedSearchTestHelper
def mock_saved_search_service!
mock_sqs_service = Class.new do
def initialize
@commands = []
end
def commands
@commands
end
def send_message(msg)
@commands << msg.split(/\n/).first
end
end
service = mock_sqs_service.new
SavedSearch.stubs(:sqs_service).returns(service)
Danbooru.config.stubs(:aws_sqs_saved_search_url).returns("http://localhost:3002")
SavedSearch.stubs(:enabled?).returns(true)
end
end

View File

@@ -26,6 +26,28 @@ class AliasAndImplicationImporterTest < ActiveSupport::TestCase
end
end
context "#estimate_update_count" do
setup do
FactoryBot.create(:post, tag_string: "aaa")
FactoryBot.create(:post, tag_string: "bbb")
FactoryBot.create(:post, tag_string: "ccc")
FactoryBot.create(:post, tag_string: "ddd")
FactoryBot.create(:post, tag_string: "eee")
@script = "create alias aaa -> 000\n" +
"create implication bbb -> 111\n" +
"remove alias ccc -> 222\n" +
"remove implication ddd -> 333\n" +
"mass update eee -> 444\n"
end
subject { AliasAndImplicationImporter.new(@script, nil) }
should "return the correct count" do
assert_equal(3, subject.estimate_update_count)
end
end
context "given a valid list" do
setup do
@list = "create alias abc -> def\ncreate implication aaa -> bbb\n"

View File

@@ -13,6 +13,28 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
CurrentUser.ip_addr = nil
end
context "#estimate_update_count" do
setup do
FactoryBot.create(:post, tag_string: "aaa")
FactoryBot.create(:post, tag_string: "bbb")
FactoryBot.create(:post, tag_string: "ccc")
FactoryBot.create(:post, tag_string: "ddd")
FactoryBot.create(:post, tag_string: "eee")
@script = "create alias aaa -> 000\n" +
"create implication bbb -> 111\n" +
"remove alias ccc -> 222\n" +
"remove implication ddd -> 333\n" +
"mass update eee -> 444\n"
end
subject { BulkUpdateRequest.new(script: @script) }
should "return the correct count" do
assert_equal(3, subject.estimate_update_count)
end
end
context "on approval" do
setup do
@script = %q(

View File

@@ -20,6 +20,16 @@ module Moderator
CurrentUser.ip_addr = nil
end
context "#estimate_update_count" do
setup do
@change = TagBatchChange.new("aaa", "bbb", @user.id, "127.0.0.1")
end
should "find the correct count" do
assert_equal(1, @change.estimate_update_count)
end
end
should "execute" do
tag_batch_change = TagBatchChange.new("aaa", "bbb", @user.id, "127.0.0.1")
tag_batch_change.perform

View File

@@ -58,6 +58,17 @@ class TagAliasTest < ActiveSupport::TestCase
end
end
context "#estimate_update_count" do
setup do
FactoryBot.create(:post, tag_string: "aaa bbb ccc")
@alias = FactoryBot.create(:tag_alias, antecedent_name: "aaa", consequent_name: "bbb", status: "pending")
end
should "get the right count" do
assert_equal(1, @alias.estimate_update_count)
end
end
context "on secondary validation" do
should "warn about missing wiki pages" do
ti = FactoryBot.build(:tag_alias, antecedent_name: "aaa", consequent_name: "bbb", skip_secondary_validations: false)

View File

@@ -54,6 +54,17 @@ class TagImplicationTest < ActiveSupport::TestCase
end
end
context "#estimate_update_count" do
setup do
FactoryBot.create(:post, tag_string: "aaa bbb ccc")
@implication = FactoryBot.create(:tag_implication, antecedent_name: "aaa", consequent_name: "bbb", status: "pending")
end
should "get the right count" do
assert_equal(1, @implication.estimate_update_count)
end
end
context "on secondary validation" do
should "warn if either tag is missing a wiki" do
ti = FactoryBot.build(:tag_implication, antecedent_name: "aaa", consequent_name: "bbb", skip_secondary_validations: false)