pools: switch from search[name_matches] to search[name_contains].
The previous commit changed it so that `/pools?search[name_matches]` does a full-text search. So for example, `search[name_matches]=smiling` will now match pool names containing any of the words "smiling", "smile", "smiles", or "smiled". This commit adds a `/pools?search[name_contains]` param that does what `name_matches` did before, and switches to it in search forms. So for example, `search[name_contains]=smiling` will only match pool names containing the exact substring "smiling". This change is so that `<field>_matches` works consistently across the site, and so that it's possible to search pool names by either an exact substring match, or by a looser natural language match. This is a minor breaking API change. API users can replace `/pools?search[name_matches]` with `/pools?search[name_contains]` to get the same behavior as before. The same applies to /favorite_groups.
This commit is contained in:
@@ -22,8 +22,7 @@ class ArtistVersionsControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
should respond_to_search({}).with { @versions.reverse }
|
||||
should respond_to_search(name: "masao").with { [@versions[2], @versions[0]] }
|
||||
should respond_to_search(name_matches: "(deleted)").with { @versions[1] }
|
||||
should respond_to_search(group_name_matches: "the_best").with { @versions[2] }
|
||||
should respond_to_search(group_name: "the_best").with { @versions[2] }
|
||||
should respond_to_search(urls_include_any: "https://www.deviantart.com/masao").with { [@versions[2], @versions[1], @versions[0]] }
|
||||
should respond_to_search(is_deleted: "true").with { @versions[1] }
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ class FavoriteGroupsControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
context "index action" do
|
||||
setup do
|
||||
@mod_favgroup = create(:favorite_group, name: "monochrome", creator: build(:moderator_user, name: "fumimi"))
|
||||
@mod_favgroup = create(:favorite_group, name: "Beautiful Smile", creator: build(:moderator_user, name: "fumimi"))
|
||||
@private_favgroup = create(:private_favorite_group)
|
||||
end
|
||||
|
||||
@@ -19,7 +19,12 @@ class FavoriteGroupsControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
should respond_to_search({}).with { [@mod_favgroup, @favgroup] }
|
||||
should respond_to_search(name: "monochrome").with { @mod_favgroup }
|
||||
should respond_to_search(name_contains: "eautiful").with { @mod_favgroup }
|
||||
should respond_to_search(name_contains: "beautiful smile").with { @mod_favgroup }
|
||||
should respond_to_search(name_contains: "smiling beauty").with { [] }
|
||||
should respond_to_search(name_matches: "eautiful").with { [] }
|
||||
should respond_to_search(name_matches: "beautiful smile").with { @mod_favgroup }
|
||||
should respond_to_search(name_matches: "smiling beauty").with { @mod_favgroup }
|
||||
|
||||
context "using includes" do
|
||||
should respond_to_search(creator_name: "fumimi").with { @mod_favgroup }
|
||||
|
||||
@@ -9,7 +9,7 @@ class PoolsControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
as(@user) do
|
||||
@post = create(:post)
|
||||
@pool = create(:pool, name: "pool", description: "[[touhou]]")
|
||||
@pool = create(:pool, name: "Beautiful Smile", description: "[[touhou]]")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -25,7 +25,12 @@ class PoolsControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_equal(Pool.count, response.parsed_body.css("urlset url loc").size)
|
||||
end
|
||||
|
||||
should respond_to_search(name_matches: "pool").with { @pool }
|
||||
should respond_to_search(name_contains: "eautiful").with { @pool }
|
||||
should respond_to_search(name_contains: "beautiful smile").with { @pool }
|
||||
should respond_to_search(name_contains: "smiling beauty").with { [] }
|
||||
should respond_to_search(name_matches: "eautiful").with { [] }
|
||||
should respond_to_search(name_matches: "beautiful smile").with { @pool }
|
||||
should respond_to_search(name_matches: "smiling beauty").with { @pool }
|
||||
should respond_to_search(linked_to: "touhou").with { @pool }
|
||||
should respond_to_search(not_linked_to: "touhou").with { [] }
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user