post_test.rb: add tag name validation tests.
This commit is contained in:
@@ -558,6 +558,72 @@ class PostTest < ActiveSupport::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
context "tagged with a valid tag" do
|
||||
subject { @post }
|
||||
|
||||
should allow_value("touhou 100%").for(:tag_string)
|
||||
should allow_value("touhou FOO").for(:tag_string)
|
||||
should allow_value("touhou -foo").for(:tag_string)
|
||||
should allow_value("touhou pool:foo").for(:tag_string)
|
||||
should allow_value("touhou -pool:foo").for(:tag_string)
|
||||
should allow_value("touhou newpool:foo").for(:tag_string)
|
||||
should allow_value("touhou fav:self").for(:tag_string)
|
||||
should allow_value("touhou -fav:self").for(:tag_string)
|
||||
should allow_value("touhou upvote:self").for(:tag_string)
|
||||
should allow_value("touhou downvote:self").for(:tag_string)
|
||||
should allow_value("touhou parent:1").for(:tag_string)
|
||||
should allow_value("touhou child:1").for(:tag_string)
|
||||
should allow_value("touhou source:foo").for(:tag_string)
|
||||
should allow_value("touhou rating:z").for(:tag_string)
|
||||
should allow_value("touhou locked:rating").for(:tag_string)
|
||||
should allow_value("touhou -locked:rating").for(:tag_string)
|
||||
|
||||
# \u3000 = ideographic space, \u00A0 = no-break space
|
||||
should allow_value("touhou\u3000foo").for(:tag_string)
|
||||
should allow_value("touhou\u00A0foo").for(:tag_string)
|
||||
end
|
||||
|
||||
context "tagged with an invalid tag" do
|
||||
subject { @post }
|
||||
|
||||
context "that doesn't already exist" do
|
||||
should_not allow_value("touhou user:evazion").for(:tag_string)
|
||||
should_not allow_value("touhou *~foo").for(:tag_string)
|
||||
should_not allow_value("touhou *-foo").for(:tag_string)
|
||||
should_not allow_value("touhou ,-foo").for(:tag_string)
|
||||
|
||||
should_not allow_value("touhou ___").for(:tag_string)
|
||||
should_not allow_value("touhou ~foo").for(:tag_string)
|
||||
should_not allow_value("touhou _foo").for(:tag_string)
|
||||
should_not allow_value("touhou foo_").for(:tag_string)
|
||||
should_not allow_value("touhou foo__bar").for(:tag_string)
|
||||
should_not allow_value("touhou foo*bar").for(:tag_string)
|
||||
should_not allow_value("touhou foo,bar").for(:tag_string)
|
||||
should_not allow_value("touhou foo\abar").for(:tag_string)
|
||||
should_not allow_value("touhou café").for(:tag_string)
|
||||
should_not allow_value("touhou 東方").for(:tag_string)
|
||||
end
|
||||
|
||||
context "that already exists" do
|
||||
setup do
|
||||
%W(___ ~foo _foo foo_ foo__bar foo*bar foo,bar foo\abar café 東方).each do |tag|
|
||||
FactoryGirl.build(:tag, name: tag).save(validate: false)
|
||||
end
|
||||
end
|
||||
|
||||
should allow_value("touhou ___").for(:tag_string)
|
||||
should allow_value("touhou ~foo").for(:tag_string)
|
||||
should allow_value("touhou _foo").for(:tag_string)
|
||||
should allow_value("touhou foo_").for(:tag_string)
|
||||
should allow_value("touhou foo__bar").for(:tag_string)
|
||||
should allow_value("touhou foo*bar").for(:tag_string)
|
||||
should allow_value("touhou foo,bar").for(:tag_string)
|
||||
should allow_value("touhou foo\abar").for(:tag_string)
|
||||
should allow_value("touhou café").for(:tag_string)
|
||||
should allow_value("touhou 東方").for(:tag_string)
|
||||
end
|
||||
end
|
||||
|
||||
context "tagged with a metatag" do
|
||||
context "for a parent" do
|
||||
setup do
|
||||
@@ -674,6 +740,13 @@ class PostTest < ActiveSupport::TestCase
|
||||
assert_equal("pool:#{@pool.id} pool:series", @post.pool_string)
|
||||
end
|
||||
end
|
||||
|
||||
context "with special characters" do
|
||||
should "not strip '%' from the name" do
|
||||
@post.update(tag_string: "aaa newpool:ichigo_100%")
|
||||
assert(Pool.exists?(name: "ichigo_100%"))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -137,9 +137,9 @@ class TagTest < ActiveSupport::TestCase
|
||||
assert_equal(%w(~AAa -BBB* -bbb*), Tag.scan_query("~AAa -BBB* -bbb*"))
|
||||
end
|
||||
|
||||
should "strip out invalid characters when scanning" do
|
||||
should "not strip out valid characters when scanning" do
|
||||
assert_equal(%w(aaa bbb), Tag.scan_tags("aaa bbb"))
|
||||
assert_equal(%w(-BB;B* -b_b_b_), Tag.scan_tags("-B,B;B* -b_b_b_"))
|
||||
assert_equal(%w(favgroup:yondemasu_yo,_azazel-san. pool:ichigo_100%), Tag.scan_tags("favgroup:yondemasu_yo,_azazel-san. pool:ichigo_100%"))
|
||||
end
|
||||
|
||||
should "cast values" do
|
||||
@@ -207,6 +207,32 @@ class TagTest < ActiveSupport::TestCase
|
||||
assert_equal(Tag.categories.artist, tag.category)
|
||||
end
|
||||
end
|
||||
|
||||
context "during name validation" do
|
||||
# tags with spaces or uppercase are allowed because they are normalized
|
||||
# to lowercase with underscores.
|
||||
should allow_value(" foo ").for(:name).on(:create)
|
||||
should allow_value("foo bar").for(:name).on(:create)
|
||||
should allow_value("FOO").for(:name).on(:create)
|
||||
|
||||
should_not allow_value("").for(:name).on(:create)
|
||||
should_not allow_value("___").for(:name).on(:create)
|
||||
should_not allow_value("~foo").for(:name).on(:create)
|
||||
should_not allow_value("-foo").for(:name).on(:create)
|
||||
should_not allow_value("_foo").for(:name).on(:create)
|
||||
should_not allow_value("foo_").for(:name).on(:create)
|
||||
should_not allow_value("foo__bar").for(:name).on(:create)
|
||||
should_not allow_value("foo*bar").for(:name).on(:create)
|
||||
should_not allow_value("foo,bar").for(:name).on(:create)
|
||||
should_not allow_value("foo\abar").for(:name).on(:create)
|
||||
should_not allow_value("café").for(:name).on(:create)
|
||||
should_not allow_value("東方").for(:name).on(:create)
|
||||
|
||||
metatags = Tag::METATAGS.split("|") + Tag::SUBQUERY_METATAGS.split("|") + Danbooru.config.tag_category_mapping.keys
|
||||
metatags.split("|").each do |metatag|
|
||||
should_not allow_value("#{metatag}:foo").for(:name).on(:create)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "A tag with a negative post count" do
|
||||
|
||||
Reference in New Issue
Block a user