This commit is contained in:
r888888888
2013-05-06 12:54:31 -07:00
parent c33a6e376a
commit 1ce7953730
4 changed files with 62 additions and 5 deletions

View File

@@ -25,7 +25,12 @@ class TagImplicationsController < ApplicationController
def destroy
@tag_implication = TagImplication.find(params[:id])
@tag_implication.destroy
respond_with(@tag_implication)
respond_with(@tag_implication) do |format|
format.html do
flash[:notice] = "Tag implication was deleted"
redirect_to(tag_implications_path)
end
end
end
def approve

View File

@@ -4,7 +4,7 @@ require 'mail'
class UploadErrorChecker
def check!
uploads = Upload.where("status like 'error%' and created_at >= ?", 1.hour.ago).all
uploads = Upload.where("status like 'error%' and status not like 'error: RuntimeError - duplicate%' and created_at >= ?", 1.hour.ago).all
if uploads.size > 5
mail = Mail.new do
from "webmaster@danbooru.donmai.us"

View File

@@ -1,6 +1,8 @@
class TagImplication < ActiveRecord::Base
before_save :update_descendant_names
after_save :update_descendant_names_for_parent
after_destroy :update_descendant_names_for_parent
after_destroy :update_posts_for_destroy
belongs_to :creator, :class_name => "User"
before_validation :initialize_creator, :on => :create
before_validation :normalize_names
@@ -90,13 +92,41 @@ class TagImplication < ActiveRecord::Base
q = q.where("antecedent_name = ?", params[:antecedent_name])
end
if params[:consequent_name].present?
q = q.where("consequent_name = ?", params[:consequent_name])
end
q
end
end
module DeletionMethods
extend ActiveSupport::Concern
module ClassMethods
def update_posts_for_destroy(creator_id, creator_ip_addr, tag_name)
Post.tag_match("#{tag_name} status:any").find_each do |post|
escaped_tag_name = Regexp.escape(tag_name)
fixed_tags = post.tag_string.sub(/(?:\A| )#{escaped_tag_name}(?:\Z| )/, " ").strip
CurrentUser.scoped(User.find(creator_id), creator_ip_addr) do
post.disable_versioning = true
post.update_attributes(
:tag_string => fixed_tags
)
end
end
end
end
def update_posts_for_destroy
TagImplication.delay(:queue => "default").update_posts_for_destroy(CurrentUser.user.id, CurrentUser.ip_addr, consequent_name)
end
end
include DescendantMethods
include ParentMethods
extend SearchMethods
include DeletionMethods
def initialize_creator
self.creator_id = CurrentUser.user.id
@@ -105,7 +135,7 @@ class TagImplication < ActiveRecord::Base
def process!
update_column(:status, "processing")
update_posts
update_posts_for_create
update_column(:status, "active")
update_descendant_names_for_parent
rescue Exception => e
@@ -120,7 +150,7 @@ class TagImplication < ActiveRecord::Base
end
end
def update_posts
def update_posts_for_create
Post.tag_match("#{antecedent_name} status:any").find_each do |post|
escaped_antecedent_name = Regexp.escape(antecedent_name)
fixed_tags = post.tag_string.sub(/(?:\A| )#{escaped_antecedent_name}(?:\Z| )/, " #{antecedent_name} #{descendant_names} ").strip

View File

@@ -8,6 +8,7 @@ class TagImplicationTest < ActiveSupport::TestCase
CurrentUser.ip_addr = "127.0.0.1"
@user = FactoryGirl.create(:user)
MEMCACHE.flush_all
Delayed::Worker.delay_jobs = false
end
teardown do
@@ -67,7 +68,18 @@ class TagImplicationTest < ActiveSupport::TestCase
assert_equal("ddd", ti2.descendant_names)
end
should "update the decendants for its parent on create" do
should "update the descendants for its parent on destroy" do
ti1 = FactoryGirl.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
ti2 = FactoryGirl.create(:tag_implication, :antecedent_name => "bbb", :consequent_name => "ccc")
ti3 = FactoryGirl.create(:tag_implication, :antecedent_name => "ccc", :consequent_name => "ddd")
ti2.destroy
ti1.reload
ti3.reload
assert_equal("bbb", ti1.descendant_names)
assert_equal("ddd", ti3.descendant_names)
end
should "update the descendants for its parent on create" do
ti1 = FactoryGirl.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
ti1.reload
assert_equal("active", ti1.status)
@@ -97,7 +109,17 @@ class TagImplicationTest < ActiveSupport::TestCase
assert_equal("ccc ddd eee", ti2.descendant_names)
assert_equal("ddd", ti3.descendant_names)
assert_equal("eee", ti4.descendant_names)
end
should "update any affected post upon destroy" do
ti1 = FactoryGirl.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
ti2 = FactoryGirl.create(:tag_implication, :antecedent_name => "bbb", :consequent_name => "ccc")
ti3 = FactoryGirl.create(:tag_implication, :antecedent_name => "ccc", :consequent_name => "ddd")
p1 = FactoryGirl.create(:post, :tag_string => "aaa")
assert_equal("aaa bbb ccc ddd", p1.tag_string)
ti2.destroy
p1.reload
assert_equal("aaa bbb ddd", p1.tag_string)
end
should "update any affected post upon save" do