fix tests
This commit is contained in:
@@ -7,9 +7,8 @@ module Moderator
|
|||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
tag_batch_change = TagBatchChange.new(params[:tag][:antecedent], params[:tag][:consequent])
|
Delayed::Job.enqueue(TagBatchChange.new(params[:tag][:antecedent], params[:tag][:consequent], CurrentUser.user, CurrentUser.ip_addr))
|
||||||
tag_batch_change.execute
|
redirect_to edit_moderator_tag_path, :notice => "Post changes queued"
|
||||||
redirect_to edit_moderator_tag_path, :notice => "Posts updated"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def error
|
def error
|
||||||
|
|||||||
@@ -1,23 +1,20 @@
|
|||||||
module Moderator
|
module Moderator
|
||||||
class TagBatchChange
|
class TagBatchChange < Struct.new(:antecedent, :consequent, :updater_id, :updater_ip_addr)
|
||||||
class Error < Exception ; end
|
class Error < Exception ; end
|
||||||
|
|
||||||
attr_reader :predicate, :consequent
|
def perform
|
||||||
|
raise Error.new("antecedent is missing") if antecedent.blank?
|
||||||
|
|
||||||
def initialize(predicate, consequent)
|
normalized_antecedent = TagAlias.to_aliased(::Tag.scan_tags(antecedent))
|
||||||
@predicate = predicate
|
|
||||||
@consequent = consequent
|
|
||||||
end
|
|
||||||
|
|
||||||
def execute
|
|
||||||
raise Error.new("Predicate is missing") if predicate.blank?
|
|
||||||
|
|
||||||
normalized_predicate = TagAlias.to_aliased(::Tag.scan_tags(predicate))
|
|
||||||
normalized_consequent = TagAlias.to_aliased(::Tag.scan_tags(consequent))
|
normalized_consequent = TagAlias.to_aliased(::Tag.scan_tags(consequent))
|
||||||
|
|
||||||
::Post.tag_match(predicate).each do |post|
|
updater = User.find(updater_id)
|
||||||
tags = (post.tag_array - normalized_predicate + normalized_consequent).join(" ")
|
|
||||||
post.update_attributes(:tag_string => tags)
|
CurrentUser.scoped(updater, updater_ip_addr) do
|
||||||
|
::Post.tag_match(antecedent).each do |post|
|
||||||
|
tags = (post.tag_array - normalized_antecedent + normalized_consequent).join(" ")
|
||||||
|
post.update_attributes(:tag_string => tags)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ class PostAppeal < ActiveRecord::Base
|
|||||||
scope :recent, lambda {where(["created_at >= ?", 1.day.ago])}
|
scope :recent, lambda {where(["created_at >= ?", 1.day.ago])}
|
||||||
|
|
||||||
def validate_creator_is_not_limited
|
def validate_creator_is_not_limited
|
||||||
if appeal_count_for_creator >= 1
|
if appeal_count_for_creator >= Danbooru.config.max_appeals_per_day
|
||||||
errors[:creator] << "can appeal one post a day"
|
errors[:creator] << "can appeal at most #{Danbooru.config.max_appeals_per_day} post a day"
|
||||||
false
|
false
|
||||||
else
|
else
|
||||||
true
|
true
|
||||||
|
|||||||
@@ -243,6 +243,10 @@ module Danbooru
|
|||||||
posts.select {|x| can_user_see_post?(user, x)}
|
posts.select {|x| can_user_see_post?(user, x)}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def max_appeals_per_day
|
||||||
|
1
|
||||||
|
end
|
||||||
|
|
||||||
def pixiv_login
|
def pixiv_login
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -16,16 +16,16 @@ module Moderator
|
|||||||
end
|
end
|
||||||
|
|
||||||
should "execute" do
|
should "execute" do
|
||||||
tag_batch_change = TagBatchChange.new("aaa", "bbb")
|
tag_batch_change = TagBatchChange.new("aaa", "bbb", @user, "127.0.0.1")
|
||||||
tag_batch_change.execute
|
tag_batch_change.perform
|
||||||
@post.reload
|
@post.reload
|
||||||
assert_equal("bbb", @post.tag_string)
|
assert_equal("bbb", @post.tag_string)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "raise an error if there is no predicate" do
|
should "raise an error if there is no predicate" do
|
||||||
tag_batch_change = TagBatchChange.new("", "bbb")
|
tag_batch_change = TagBatchChange.new("", "bbb", @user, "127.0.0.1")
|
||||||
assert_raises(TagBatchChange::Error) do
|
assert_raises(TagBatchChange::Error) do
|
||||||
tag_batch_change.execute
|
tag_batch_change.perform
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ class PostAppealTest < ActiveSupport::TestCase
|
|||||||
CurrentUser.user = @alice
|
CurrentUser.user = @alice
|
||||||
CurrentUser.ip_addr = "127.0.0.1"
|
CurrentUser.ip_addr = "127.0.0.1"
|
||||||
MEMCACHE.flush_all
|
MEMCACHE.flush_all
|
||||||
|
Danbooru.config.stubs(:max_appeals_per_day).returns(5)
|
||||||
end
|
end
|
||||||
|
|
||||||
teardown do
|
teardown do
|
||||||
@@ -37,7 +38,7 @@ class PostAppealTest < ActiveSupport::TestCase
|
|||||||
assert_difference("PostAppeal.count", 0) do
|
assert_difference("PostAppeal.count", 0) do
|
||||||
@post_appeal.save
|
@post_appeal.save
|
||||||
end
|
end
|
||||||
assert_equal(["You can appeal 5 posts a day"], @post_appeal.errors.full_messages)
|
assert_equal(["You can appeal at most 5 post a day"], @post_appeal.errors.full_messages)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "not be able to appeal an active post" do
|
should "not be able to appeal an active post" do
|
||||||
|
|||||||
Reference in New Issue
Block a user