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,24 +3,48 @@ require 'test_helper'
class ArtistCommentaryVersionsControllerTest < ActionDispatch::IntegrationTest
context "The artist commentary versions controller" do
setup do
@user = create(:user)
@commentary1 = as(@user) { create(:artist_commentary) }
@commentary2 = as(@user) { create(:artist_commentary) }
@user = create(:member_user, id: 1000, created_at: 2.weeks.ago)
@builder = create(:builder_user, created_at: 2.weeks.ago)
as(@user) do
@commentary = create(:artist_commentary, post: build(:post, id: 999, tag_string: "hakurei_reimu", uploader: @user))
end
as (@builder) { @commentary.update(original_title: "traslated") }
as (@user) { @commentary.update(original_title: "translated") }
end
context "index action" do
setup do
@versions = @commentary.versions
as(@builder) do
@other_commentary = create(:artist_commentary, post: build(:post, uploader: @builder))
end
@other_versions = @other_commentary.versions
end
should "render" do
get artist_commentary_versions_path
assert_response :success
end
should respond_to_search({}).with { @other_versions + @versions.reverse }
should respond_to_search(original_title: "translated").with { @versions[2] }
should respond_to_search(text_matches: "traslated").with { @versions[1] }
context "using includes" do
should respond_to_search(post_id: 999).with { @versions.reverse }
should respond_to_search(post_tags_match: "hakurei_reimu").with { @versions.reverse }
should respond_to_search(post: {uploader: {level: User::Levels::BUILDER}}).with { @other_commentary.versions }
should respond_to_search(updater_id: 1000).with { [@versions[2], @versions[0]] }
should respond_to_search(updater: {level: User::Levels::BUILDER}).with { [@other_versions[0], @versions[1]] }
end
end
context "show action" do
should "work" do
get artist_commentary_version_path(@commentary1.versions.first)
assert_redirected_to artist_commentary_versions_path(search: { post_id: @commentary1.post_id })
get artist_commentary_version_path(@commentary.versions.first)
assert_redirected_to artist_commentary_versions_path(search: { post_id: @commentary.post_id })
get artist_commentary_version_path(@commentary1.versions.first), as: :json
get artist_commentary_version_path(@commentary.versions.first), as: :json
assert_response :success
end
end