Merge pull request #2733 from evazion/fix-tag-normalization

Fix metatag editing so that rating:s obeys rate locks, source:blah updates pixiv id
This commit is contained in:
Albert Yi
2016-10-24 12:18:41 -07:00
committed by GitHub
2 changed files with 104 additions and 31 deletions

View File

@@ -107,7 +107,7 @@ class PostTest < ActiveSupport::TestCase
end
context "Parenting:" do
context "Assignining a parent to a post" do
context "Assigning a parent to a post" do
should "update the has_children flag on the parent" do
p1 = FactoryGirl.create(:post)
assert(!p1.has_children?, "Parent should not have any children")
@@ -460,7 +460,7 @@ class PostTest < ActiveSupport::TestCase
context "as a new user" do
setup do
@post.update_attribute(:tag_string, "aaa bbb ccc ddd tagme")
@post.update(:tag_string => "aaa bbb ccc ddd tagme")
CurrentUser.user = FactoryGirl.create(:user)
end
@@ -478,8 +478,10 @@ class PostTest < ActiveSupport::TestCase
context "with a banned artist" do
setup do
@artist = FactoryGirl.create(:artist)
@artist.ban!
CurrentUser.scoped(FactoryGirl.create(:admin_user)) do
@artist = FactoryGirl.create(:artist)
@artist.ban!
end
@post = FactoryGirl.create(:post, :tag_string => @artist.name)
end
@@ -493,9 +495,9 @@ class PostTest < ActiveSupport::TestCase
CurrentUser.user = FactoryGirl.create(:builder_user)
Delayed::Worker.delay_jobs = false
@post = Post.find(@post.id)
@post.update_attribute(:tag_string, "art:abc")
@post.update(:tag_string => "art:abc")
@post = Post.find(@post.id)
@post.update_attribute(:tag_string, "copy:abc")
@post.update(:tag_string => "copy:abc")
@post.reload
end
@@ -522,7 +524,7 @@ class PostTest < ActiveSupport::TestCase
setup do
FactoryGirl.create(:tag_alias, :antecedent_name => "abc", :consequent_name => "xyz")
@post = Post.find(@post.id)
@post.update_attribute(:tag_string, "art:abc")
@post.update(:tag_string => "art:abc")
@post.reload
end
@@ -544,6 +546,27 @@ class PostTest < ActiveSupport::TestCase
assert_equal(@parent.id, @post.parent_id)
assert(@parent.has_children?)
end
should "not allow self-parenting" do
@post.update(:tag_string => "parent:#{@post.id}")
assert_nil(@post.parent_id)
end
should "clear the parent with parent:none" do
@post.update(:parent_id => @parent.id)
assert_equal(@parent.id, @post.parent_id)
@post.update(:tag_string => "parent:none")
assert_nil(@post.parent_id)
end
should "clear the parent with -parent:1234" do
@post.update(:parent_id => @parent.id)
assert_equal(@parent.id, @post.parent_id)
@post.update(:tag_string => "-parent:#{@parent.id}")
assert_nil(@post.parent_id)
end
end
context "for a pool" do
@@ -622,7 +645,7 @@ class PostTest < ActiveSupport::TestCase
context "for a rating" do
context "that is valid" do
should "update the rating" do
should "update the rating if the post is unlocked" do
@post.update_attributes(:tag_string => "aaa rating:e")
@post.reload
assert_equal("e", @post.rating)
@@ -636,13 +659,34 @@ class PostTest < ActiveSupport::TestCase
assert_equal("q", @post.rating)
end
end
context "that is locked" do
should "change the rating if locked in the same update" do
@post.update({ :tag_string => "rating:e", :is_rating_locked => true }, :as => :builder)
assert(@post.valid?)
assert_equal("e", @post.reload.rating)
end
should "not change the rating if locked previously" do
@post.is_rating_locked = true
@post.save
@post.update(:tag_string => "rating:e")
assert(@post.invalid?)
assert_not_equal("e", @post.reload.rating)
end
end
end
context "for a fav" do
should "add the current user to the post's favorite listing" do
should "add/remove the current user to the post's favorite listing" do
@post.update_attributes(:tag_string => "aaa fav:self")
@post.reload
assert_equal("fav:#{@user.id}", @post.fav_string)
@post.update_attributes(:tag_string => "aaa -fav:self")
assert_equal("", @post.fav_string)
end
end
@@ -659,6 +703,34 @@ class PostTest < ActiveSupport::TestCase
assert(@post.has_children?)
end
end
context "for a source" do
should "set the source with source:foo_bar_baz" do
@post.update(:tag_string => "source:foo_bar_baz")
assert_equal("foo_bar_baz", @post.source)
end
should 'set the source with source:"foo bar baz"' do
@post.update(:tag_string => 'source:"foo bar baz"')
assert_equal("foo bar baz", @post.source)
end
should 'strip the source with source:" foo bar baz "' do
@post.update(:tag_string => 'source:" foo bar baz "')
assert_equal("foo bar baz", @post.source)
end
should "clear the source with source:none" do
@post.update(:source => "foobar")
@post.update(:tag_string => "source:none")
assert_nil(@post.source)
end
should "set the pixiv id with source:https://img18.pixiv.net/img/evazion/14901720.png" do
@post.update(:tag_string => "source:https://img18.pixiv.net/img/evazion/14901720.png")
assert_equal(14901720, @post.pixiv_id)
end
end
end
context "tagged with a negated tag" do