fixes #1694
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user