Files
danbooru/test/functional/wiki_page_versions_controller_test.rb
evazion 3114ef3daf searchable: standardize the <field>_matches operator for text fields.
Standardize it so that all fields of type `text` are searchable with
`search[<field>_matches]`.

Before, the `<field>_matches` param was handled manually and some fields
were left out or handled inconsistently. Now it applies to all columns
of type `text`.

This does a full-text search on the field, so for example, searching
`/artist_commentaries?search[translated_description_matches]=smiling`
will match translated commentaries containing either the word "smiling",
"smiles", "smiled", or "smile".

Note that this only applies to columns defined as type `text`, not to
columns defined as `character varying`. The difference is that `text` is
used for fields containing free-form natural language, such as comments,
notes, forum posts, wiki pages, pool descriptions, etc, while `character
varying` is used for short strings not containing free-form language,
such as tag names, wiki page titles, urls, status fields, etc.

API changes:

* Add the `search[original_title_matches]`, `search[original_description_matches]`,
  `search[translated_title_matches]`, `search[translated_description_matches]` params
  to /artist_commentaries and /artist_commentary_versions.
* Remove the `search[name_matches]` and `search[group_name_matches]` params from /artist_versions.
* Remove the `search[title_matches]` param from /wiki_page_versions.
* Change the `search[name_matches]` param on /pools, /favorite_groups, and /pool_versions
  to do a full-text search instead of a substring match.
2022-09-22 01:52:13 -05:00

52 lines
1.9 KiB
Ruby

require 'test_helper'
class WikiPageVersionsControllerTest < ActionDispatch::IntegrationTest
context "The wiki page versions controller" do
setup do
@user = create(:user, id: 100)
@builder = create(:builder_user, name: "nitori")
as(@user) { @wiki_page = create(:wiki_page, id: 101) }
as(@builder) { @wiki_page.update(title: "supreme", body: "blah", other_names: ["not_this"]) }
as(@user) { @wiki_page.update(body: "blah blah") }
end
context "index action" do
setup do
@versions = @wiki_page.versions
end
should "render" do
get wiki_page_versions_path
assert_response :success
end
should respond_to_search({}).with { @versions.reverse }
should respond_to_search(title_like: "supreme").with { [@versions[2], @versions[1]] }
should respond_to_search(body_matches: "blah").with { [@versions[2], @versions[1]] }
should respond_to_search(other_names_include_any: "not_this").with { [@versions[2], @versions[1]] }
context "using includes" do
should respond_to_search(wiki_page_id: 101).with { @versions.reverse }
should respond_to_search(wiki_page_id: 102).with { [] }
should respond_to_search(updater_id: 100).with { [@versions[2], @versions[0]] }
should respond_to_search(updater_name: "nitori").with { @versions[1] }
should respond_to_search(updater: {level: User::Levels::BUILDER}).with { @versions[1] }
end
end
context "show action" do
should "render" do
get wiki_page_version_path(@wiki_page.versions.first)
assert_response :success
end
end
context "diff action" do
should "render" do
get diff_wiki_page_versions_path, params: { thispage: @wiki_page.versions.first.id, otherpage: @wiki_page.versions.last.id }
assert_response :success
end
end
end
end