Add tests for all models with includes searches

This commit is contained in:
BrokenEagle
2020-07-19 04:06:51 +00:00
parent 34ca33e22f
commit a903bd95f9
34 changed files with 893 additions and 360 deletions

View File

@@ -3,23 +3,34 @@ require 'test_helper'
class WikiPageVersionsControllerTest < ActionDispatch::IntegrationTest
context "The wiki page versions controller" do
setup do
@user = create(:user)
as(@user) do
@wiki_page = create(:wiki_page)
@wiki_page.update(:body => "1 2")
@wiki_page.update(:body => "2 3")
end
@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
should "list all versions" do
setup do
@versions = @wiki_page.versions
end
should "render" do
get wiki_page_versions_path
assert_response :success
end
should "list all versions that match the search criteria" do
get wiki_page_versions_path, params: {:search => {:wiki_page_id => @wiki_page.id}}
assert_response :success
should respond_to_search({}).with { @versions.reverse }
should respond_to_search(title_matches: "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