fix tests

This commit is contained in:
albert
2011-12-22 18:22:32 -05:00
parent c1c870294c
commit 5ffd6d552a
6 changed files with 26 additions and 25 deletions

View File

@@ -7,9 +7,8 @@ module Moderator
end
def update
tag_batch_change = TagBatchChange.new(params[:tag][:antecedent], params[:tag][:consequent])
tag_batch_change.execute
redirect_to edit_moderator_tag_path, :notice => "Posts updated"
Delayed::Job.enqueue(TagBatchChange.new(params[:tag][:antecedent], params[:tag][:consequent], CurrentUser.user, CurrentUser.ip_addr))
redirect_to edit_moderator_tag_path, :notice => "Post changes queued"
end
def error

View File

@@ -1,23 +1,20 @@
module Moderator
class TagBatchChange
class TagBatchChange < Struct.new(:antecedent, :consequent, :updater_id, :updater_ip_addr)
class Error < Exception ; end
attr_reader :predicate, :consequent
def initialize(predicate, consequent)
@predicate = predicate
@consequent = consequent
end
def execute
raise Error.new("Predicate is missing") if predicate.blank?
def perform
raise Error.new("antecedent is missing") if antecedent.blank?
normalized_predicate = TagAlias.to_aliased(::Tag.scan_tags(predicate))
normalized_antecedent = TagAlias.to_aliased(::Tag.scan_tags(antecedent))
normalized_consequent = TagAlias.to_aliased(::Tag.scan_tags(consequent))
::Post.tag_match(predicate).each do |post|
tags = (post.tag_array - normalized_predicate + normalized_consequent).join(" ")
post.update_attributes(:tag_string => tags)
updater = User.find(updater_id)
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

View File

@@ -12,8 +12,8 @@ class PostAppeal < ActiveRecord::Base
scope :recent, lambda {where(["created_at >= ?", 1.day.ago])}
def validate_creator_is_not_limited
if appeal_count_for_creator >= 1
errors[:creator] << "can appeal one post a day"
if appeal_count_for_creator >= Danbooru.config.max_appeals_per_day
errors[:creator] << "can appeal at most #{Danbooru.config.max_appeals_per_day} post a day"
false
else
true