From 20cceda4e581437fef569f5a9f116ad883c074bb Mon Sep 17 00:00:00 2001 From: Toks Date: Tue, 15 Jul 2014 01:17:15 -0400 Subject: [PATCH] Fix race condition when auto-moving implications --- app/models/tag_alias.rb | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/app/models/tag_alias.rb b/app/models/tag_alias.rb index 1295cbe1f..17f070c56 100644 --- a/app/models/tag_alias.rb +++ b/app/models/tag_alias.rb @@ -145,8 +145,14 @@ class TagAlias < ActiveRecord::Base implications.each do |ti| ti.antecedent_name = self.consequent_name success = ti.save - if !success && ti.errors.full_messages.join("; ") =~ /Cannot implicate a tag to itself/ - ti.destroy + if !success + case ti.errors.full_messages.join("; ") + when /Cannot implicate a tag to itself/ + ti.destroy + when /Consequent tag must not be aliased to another tag/ + ti.consequent_name = TagAlias.to_aliased(ti.consequent_name).first + ti.save + end end end @@ -154,8 +160,14 @@ class TagAlias < ActiveRecord::Base implications.each do |ti| ti.consequent_name = self.consequent_name success = ti.save - if !success && ti.errors.full_messages.join("; ") =~ /Cannot implicate a tag to itself/ - ti.destroy + if !success + case ti.errors.full_messages.join("; ") + when /Cannot implicate a tag to itself/ + ti.destroy + when /Antecedent tag must not be aliased to another tag/ + ti.antecedent_name = TagAlias.to_aliased(ti.antecedent_name).first + ti.save + end end end end