From 074d1260183375d2cc212cdfb516e2408d77276e Mon Sep 17 00:00:00 2001 From: r888888888 Date: Wed, 29 May 2013 17:01:57 -0700 Subject: [PATCH] fixes #1694 --- app/models/tag_implication.rb | 24 ------------------------ test/unit/tag_implication_test.rb | 11 ----------- 2 files changed, 35 deletions(-) diff --git a/app/models/tag_implication.rb b/app/models/tag_implication.rb index d1f1f805e..414d14e34 100644 --- a/app/models/tag_implication.rb +++ b/app/models/tag_implication.rb @@ -2,7 +2,6 @@ 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 @@ -100,32 +99,9 @@ class TagImplication < ActiveRecord::Base end end - module DeletionMethods - extend ActiveSupport::Concern - - module ClassMethods - def update_posts_for_destroy(creator_id, creator_ip_addr, antecedent_name, consequent_name) - CurrentUser.scoped(User.find(creator_id), creator_ip_addr) do - Post.tag_match("#{antecedent_name} #{consequent_name} status:any").find_each do |post| - escaped_tag_name = Regexp.escape(consequent_name) - fixed_tags = post.tag_string.sub(/(?:\A| )#{escaped_tag_name}(?:\Z| )/, " ").strip - 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, antecedent_name, consequent_name) - end - end - include DescendantMethods include ParentMethods extend SearchMethods - include DeletionMethods def initialize_creator self.creator_id = CurrentUser.user.id diff --git a/test/unit/tag_implication_test.rb b/test/unit/tag_implication_test.rb index da202f2a5..4ae1f708e 100644 --- a/test/unit/tag_implication_test.rb +++ b/test/unit/tag_implication_test.rb @@ -111,17 +111,6 @@ class TagImplicationTest < ActiveSupport::TestCase 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 p1 = FactoryGirl.create(:post, :tag_string => "aaa bbb ccc") ti1 = FactoryGirl.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "xxx")