tags: allow tag abbreviations in searches and during tagging.
Expand the tag abbreviation system introduced in b0be8ae45 so that it
works in searches and when tagging posts, not just in autocomplete.
For example, you can tag a post with /evth and it will add the tag
eyebrows_visible_through_hair. You can search for /evth and it will
search for the tag eyebrows_visible_through_hair.
Some more examples:
* /ops is short for one-piece_swimsuit
* /hooe is short for hair_over_one_eye
* /saol is short for standing_on_one_leg
* /tlozbotw is short for the_legend_of_zelda:_breath_of_the_wild
If two tags have the same abbreviation, then the larger tag takes
precedence. For example, /be is short for blue_eyes, not brown_eyes,
because blue_eyes is the bigger tag.
If there is an existing shortcut alias that conflicts with the
abbreviation, then the alias take precedence. For example, /sh is short
for suzumiya_haruhi, not short_hair, because there's an old alias for
/sh -> suzumiya_haruhi.
This commit is contained in:
@@ -598,6 +598,10 @@ class PostTest < ActiveSupport::TestCase
|
||||
context "tagged with a valid tag" do
|
||||
subject { @post }
|
||||
|
||||
setup do
|
||||
create(:tag, name: "hakurei_reimu")
|
||||
end
|
||||
|
||||
should allow_value("touhou 100%").for(:tag_string)
|
||||
should allow_value("touhou FOO").for(:tag_string)
|
||||
should allow_value("touhou -foo").for(:tag_string)
|
||||
@@ -618,6 +622,8 @@ class PostTest < ActiveSupport::TestCase
|
||||
# \u3000 = ideographic space, \u00A0 = no-break space
|
||||
should allow_value("touhou\u3000foo").for(:tag_string)
|
||||
should allow_value("touhou\u00A0foo").for(:tag_string)
|
||||
|
||||
should allow_value("/hr").for(:tag_string)
|
||||
end
|
||||
|
||||
context "tagged with an invalid tag" do
|
||||
@@ -661,6 +667,16 @@ class PostTest < ActiveSupport::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
context "tagged with an abbreviation" do
|
||||
should "expand the abbreviation" do
|
||||
create(:tag, name: "hair_ribbon", post_count: 300_000)
|
||||
create(:tag, name: "hakurei_reimu", post_count: 50_000)
|
||||
|
||||
@post.update!(tag_string: "aaa /hr")
|
||||
assert_equal("aaa hair_ribbon", @post.reload.tag_string)
|
||||
end
|
||||
end
|
||||
|
||||
context "tagged with a metatag" do
|
||||
context "for typing a tag" do
|
||||
setup do
|
||||
@@ -1190,6 +1206,17 @@ class PostTest < ActiveSupport::TestCase
|
||||
|
||||
assert_equal("aaa", @post.tag_string)
|
||||
end
|
||||
|
||||
should "resolve abbreviations" do
|
||||
create(:tag, name: "hair_ribbon", post_count: 300_000)
|
||||
create(:tag, name: "hakurei_reimu", post_count: 50_000)
|
||||
|
||||
@post.update!(tag_string: "aaa hair_ribbon hakurei_reimu")
|
||||
assert_equal("aaa hair_ribbon hakurei_reimu", @post.reload.tag_string)
|
||||
|
||||
@post.update!(tag_string: "aaa hair_ribbon hakurei_reimu -/hr")
|
||||
assert_equal("aaa hakurei_reimu", @post.reload.tag_string)
|
||||
end
|
||||
end
|
||||
|
||||
context "tagged with animated_gif or animated_png" do
|
||||
|
||||
Reference in New Issue
Block a user