disable versioning of posts when creating aliases/implications
This commit is contained in:
@@ -3,7 +3,7 @@ class Post < ActiveRecord::Base
|
||||
class DisapprovalError < Exception ; end
|
||||
class SearchError < Exception ; end
|
||||
|
||||
attr_accessor :old_tag_string, :old_parent_id, :has_constraints
|
||||
attr_accessor :old_tag_string, :old_parent_id, :has_constraints, :disable_versioning
|
||||
after_destroy :delete_files
|
||||
after_destroy :delete_remote_files
|
||||
after_save :create_version
|
||||
@@ -868,6 +868,8 @@ class Post < ActiveRecord::Base
|
||||
|
||||
module VersionMethods
|
||||
def create_version
|
||||
return if disable_versioning
|
||||
|
||||
if created_at == updated_at
|
||||
CurrentUser.increment!(:post_update_count)
|
||||
versions.create(
|
||||
|
||||
@@ -130,6 +130,7 @@ class TagAlias < ActiveRecord::Base
|
||||
escaped_antecedent_name = Regexp.escape(antecedent_name)
|
||||
fixed_tags = post.tag_string.sub(/(?:\A| )#{escaped_antecedent_name}(?:\Z| )/, " #{consequent_name} ").strip
|
||||
CurrentUser.scoped(creator, creator_ip_addr) do
|
||||
post.disable_versioning = true
|
||||
post.update_attributes(
|
||||
:tag_string => fixed_tags
|
||||
)
|
||||
|
||||
@@ -125,6 +125,7 @@ class TagImplication < ActiveRecord::Base
|
||||
escaped_antecedent_name = Regexp.escape(antecedent_name)
|
||||
fixed_tags = post.tag_string.sub(/(?:\A| )#{escaped_antecedent_name}(?:\Z| )/, " #{antecedent_name} #{descendant_names} ").strip
|
||||
CurrentUser.scoped(creator, creator_ip_addr) do
|
||||
post.disable_versioning = true
|
||||
post.update_attributes(
|
||||
:tag_string => fixed_tags
|
||||
)
|
||||
|
||||
@@ -62,18 +62,6 @@ class TagAliasTest < ActiveSupport::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
should "record the alias's creator in the tag history" do
|
||||
uploader = FactoryGirl.create(:user)
|
||||
post = nil
|
||||
CurrentUser.scoped(uploader, "127.0.0.1") do
|
||||
post = FactoryGirl.create(:post, :tag_string => "aaa bbb ccc")
|
||||
end
|
||||
tag_alias = FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "xxx")
|
||||
post.reload
|
||||
assert_not_equal(tag_alias.creator_id, post.uploader_id)
|
||||
assert_equal(tag_alias.creator_id, post.versions.last.updater_id)
|
||||
end
|
||||
|
||||
should "push the antecedent's category to the consequent" do
|
||||
tag1 = FactoryGirl.create(:tag, :name => "aaa", :category => 1)
|
||||
tag2 = FactoryGirl.create(:tag, :name => "bbb")
|
||||
|
||||
@@ -107,17 +107,5 @@ class TagImplicationTest < ActiveSupport::TestCase
|
||||
p1.reload
|
||||
assert_equal("aaa bbb ccc xxx yyy", p1.tag_string)
|
||||
end
|
||||
|
||||
should "record the implication's creator in the tag history" do
|
||||
user = FactoryGirl.create(:user)
|
||||
p1 = nil
|
||||
CurrentUser.scoped(user, "127.0.0.1") do
|
||||
p1 = FactoryGirl.create(:post, :tag_string => "aaa bbb ccc")
|
||||
end
|
||||
ti1 = FactoryGirl.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "xxx")
|
||||
p1.reload
|
||||
assert_not_equal(ti1.creator_id, p1.uploader_id)
|
||||
assert_equal(ti1.creator_id, p1.versions.last.updater_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user