fixes #2009
This commit is contained in:
@@ -416,6 +416,7 @@ class Post < ActiveRecord::Base
|
|||||||
normalized_tags = Tag.scan_tags(tag_string)
|
normalized_tags = Tag.scan_tags(tag_string)
|
||||||
normalized_tags = filter_metatags(normalized_tags)
|
normalized_tags = filter_metatags(normalized_tags)
|
||||||
normalized_tags = normalized_tags.map{|tag| tag.downcase}
|
normalized_tags = normalized_tags.map{|tag| tag.downcase}
|
||||||
|
normalized_tags = remove_negated_tags(normalized_tags)
|
||||||
normalized_tags = normalized_tags.map {|x| Tag.find_or_create_by_name(x).name}
|
normalized_tags = normalized_tags.map {|x| Tag.find_or_create_by_name(x).name}
|
||||||
normalized_tags = TagAlias.to_aliased(normalized_tags)
|
normalized_tags = TagAlias.to_aliased(normalized_tags)
|
||||||
normalized_tags = TagImplication.with_descendants(normalized_tags)
|
normalized_tags = TagImplication.with_descendants(normalized_tags)
|
||||||
@@ -424,6 +425,12 @@ class Post < ActiveRecord::Base
|
|||||||
set_tag_string(normalized_tags.uniq.sort.join(" "))
|
set_tag_string(normalized_tags.uniq.sort.join(" "))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def remove_negated_tags(tags)
|
||||||
|
negated_tags, tags = tags.partition {|x| x =~ /\A-/i}
|
||||||
|
negated_tags.map!{|x| x[1..-1]}
|
||||||
|
return tags - negated_tags
|
||||||
|
end
|
||||||
|
|
||||||
def filter_metatags(tags)
|
def filter_metatags(tags)
|
||||||
@pre_metatags, tags = tags.partition {|x| x =~ /\A(?:rating|parent):/i}
|
@pre_metatags, tags = tags.partition {|x| x =~ /\A(?:rating|parent):/i}
|
||||||
@post_metatags, tags = tags.partition {|x| x =~ /\A(?:-pool|pool|newpool|fav):/i}
|
@post_metatags, tags = tags.partition {|x| x =~ /\A(?:-pool|pool|newpool|fav):/i}
|
||||||
|
|||||||
@@ -578,6 +578,15 @@ class PostTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "tagged with a negated tag" do
|
||||||
|
should "remove the tag if present" do
|
||||||
|
@post.update_attributes(:tag_string => "aaa bbb ccc")
|
||||||
|
@post.update_attributes(:tag_string => "aaa bbb ccc -bbb")
|
||||||
|
@post.reload
|
||||||
|
assert_equal("aaa ccc", @post.tag_string)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
should "have an array representation of its tags" do
|
should "have an array representation of its tags" do
|
||||||
post = FactoryGirl.create(:post)
|
post = FactoryGirl.create(:post)
|
||||||
post.set_tag_string("aaa bbb")
|
post.set_tag_string("aaa bbb")
|
||||||
|
|||||||
Reference in New Issue
Block a user