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,18 +3,36 @@ require 'test_helper'
class ArtistVersionsControllerTest < ActionDispatch::IntegrationTest
context "An artist versions controller" do
setup do
@user = create(:gold_user)
@artist = as(@user) { create(:artist) }
@user = create(:gold_user, id: 100)
@builder = create(:builder_user, name: "danbo")
as(@builder) { @artist = create(:artist, name: "masao") }
as(@user) { @artist.update(name: "masao_(deleted)", is_deleted: true) }
as(@builder) { @artist.update(name: "masao", is_deleted: false, group_name: "the_best") }
end
should "get the index page" do
get_auth artist_versions_path, @user
assert_response :success
end
context "index action" do
setup do
@versions = @artist.versions
end
should "get the index page when searching for something" do
get_auth artist_versions_path(search: {name: @artist.name}), @user
assert_response :success
should "render" do
get artist_versions_path
assert_response :success
end
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(is_deleted: "true").with { @versions[1] }
context "using includes" do
should respond_to_search(updater_id: 100).with { @versions[1] }
should respond_to_search(updater_name: "danbo").with { [@versions[2], @versions[0]] }
should respond_to_search(updater: {level: User::Levels::BUILDER}).with { [@versions[2], @versions[0]] }
should respond_to_search(artist: {name: "masao"}).with { @versions.reverse }
should respond_to_search(artist: {name: "doesntexist"}).with { [] }
end
end
context "show action" do