From a903bd95f9113eeb70d536d37a820768e0d79197 Mon Sep 17 00:00:00 2001 From: BrokenEagle Date: Sun, 19 Jul 2020 04:06:51 +0000 Subject: [PATCH] Add tests for all models with includes searches --- .../artist_commentaries_controller_test.rb | 62 ++++++------- ...ist_commentary_versions_controller_test.rb | 36 ++++++-- .../functional/artist_urls_controller_test.rb | 26 +++--- .../artist_versions_controller_test.rb | 36 ++++++-- test/functional/artists_controller_test.rb | 40 ++++++--- test/functional/bans_controller_test.rb | 32 ++++--- .../bulk_update_requests_controller_test.rb | 26 +++++- .../comment_votes_controller_test.rb | 38 ++++++-- test/functional/comments_controller_test.rb | 33 +++++-- test/functional/dmails_controller_test.rb | 49 ++++++---- .../functional/dtext_links_controller_test.rb | 24 ++++- .../favorite_groups_controller_test.rb | 21 +++++ .../forum_post_votes_controller_test.rb | 21 ++++- .../functional/forum_posts_controller_test.rb | 90 +++++++++---------- .../forum_topics_controller_test.rb | 75 ++++++++++------ test/functional/ip_bans_controller_test.rb | 29 ++++-- .../functional/mod_actions_controller_test.rb | 18 +++- .../moderation_reports_controller_test.rb | 38 +++++--- .../note_versions_controller_test.rb | 29 ++++-- test/functional/notes_controller_test.rb | 27 +++--- .../post_appeals_controller_test.rb | 29 +++--- .../post_approvals_controller_test.rb | 18 +++- .../post_disapprovals_controller_test.rb | 29 ++++-- test/functional/post_flags_controller_test.rb | 58 ++++++++---- .../post_replacements_controller_test.rb | 19 +++- test/functional/post_votes_controller_test.rb | 38 ++++++-- .../functional/tag_aliases_controller_test.rb | 36 +++++++- .../tag_implications_controller_test.rb | 38 ++++++++ test/functional/tags_controller_test.rb | 32 +++++-- test/functional/uploads_controller_test.rb | 46 ++++++---- .../user_feedbacks_controller_test.rb | 44 ++++++--- test/functional/users_controller_test.rb | 63 +++++++++++-- .../wiki_page_versions_controller_test.rb | 31 ++++--- test/functional/wiki_pages_controller_test.rb | 22 +++-- 34 files changed, 893 insertions(+), 360 deletions(-) diff --git a/test/functional/artist_commentaries_controller_test.rb b/test/functional/artist_commentaries_controller_test.rb index beea52479..9698a00bd 100644 --- a/test/functional/artist_commentaries_controller_test.rb +++ b/test/functional/artist_commentaries_controller_test.rb @@ -3,43 +3,43 @@ require 'test_helper' class ArtistCommentariesControllerTest < ActionDispatch::IntegrationTest context "The artist commentaries controller" do setup do - @user = create(:user) - + @user = create(:user, id: 1000, name: "danbo", created_at: 2.weeks.ago) as(@user) do - @commentary1 = create(:artist_commentary) - @commentary2 = create(:artist_commentary) + @commentary = create(:artist_commentary, post: build(:post, id: 999, tag_string: "hakurei_reimu", uploader: @user), original_title: "ot1", translated_title: "tt1") + @other_commentary = create(:artist_commentary, translated_title: "", translated_description: "") end end context "index action" do + setup do + @deleted_commentary = create(:artist_commentary, original_title: "", original_description: "", translated_title: "", translated_description: "") + end + should "render" do get artist_commentaries_path assert_response :success end - should "render with search params" do - params = { - search: { - text_matches: @commentary1.original_title, - post_id: @commentary1.post_id, - original_present: "yes", - translated_present: "yes", - post_tags_match: @commentary1.post.tag_array.first - } - } + should respond_to_search({}).with { [@deleted_commentary, @other_commentary, @commentary] } + should respond_to_search(text_matches: "ot1").with { @commentary } + should respond_to_search(original_present: "true").with { [@other_commentary, @commentary] } + should respond_to_search(translated_present: "true").with { @commentary } + should respond_to_search(is_deleted: "yes").with { @deleted_commentary } - get artist_commentaries_path(params) - assert_response :success + context "using includes" do + should respond_to_search(post_id: 999).with { @commentary } + should respond_to_search(post_tags_match: "hakurei_reimu").with { @commentary } + should respond_to_search(post: {uploader_name: "danbo"}).with { @commentary } end end context "show action" do should "render" do - get artist_commentary_path(@commentary1.id) - assert_redirected_to(@commentary1.post) + get artist_commentary_path(@commentary.id) + assert_redirected_to(@commentary.post) - get artist_commentary_path(post_id: @commentary1.post_id) - assert_redirected_to(@commentary1.post) + get artist_commentary_path(post_id: @commentary.post_id) + assert_redirected_to(@commentary.post) end end @@ -62,27 +62,27 @@ class ArtistCommentariesControllerTest < ActionDispatch::IntegrationTest should "render for update" do params = { artist_commentary: { - post_id: @commentary1.post_id, + post_id: @commentary.post_id, original_title: "foo" }, format: "js" } put_auth create_or_update_artist_commentaries_path(params), @user - @commentary1.reload + @commentary.reload assert_response :success - assert_equal("foo", @commentary1.reload.original_title) + assert_equal("foo", @commentary.reload.original_title) end end context "revert action" do should "work" do - original_title = @commentary1.original_title - @commentary1.update(original_title: "foo") - @commentary1.reload - put_auth revert_artist_commentary_path(@commentary1.post_id, version_id: @commentary1.versions.first.id, format: "js"), @user + original_title = @commentary.original_title + @commentary.update(original_title: "foo") + @commentary.reload + put_auth revert_artist_commentary_path(@commentary.post_id, version_id: @commentary.versions.first.id, format: "js"), @user assert_response :success - assert_equal(original_title, @commentary1.reload.original_title) + assert_equal(original_title, @commentary.reload.original_title) end should "return 404 when trying to revert a nonexistent commentary" do @@ -91,9 +91,9 @@ class ArtistCommentariesControllerTest < ActionDispatch::IntegrationTest end should "not allow reverting to a previous version of another artist commentary" do - put_auth revert_artist_commentary_path(@commentary1.post_id, version_id: @commentary2.versions.first.id, format: "js"), @user - @commentary1.reload - assert_not_equal(@commentary1.original_title, @commentary2.original_title) + put_auth revert_artist_commentary_path(@commentary.post_id, version_id: @other_commentary.versions.first.id, format: "js"), @user + @commentary.reload + assert_not_equal(@commentary.original_title, @other_commentary.original_title) assert_response :missing end end diff --git a/test/functional/artist_commentary_versions_controller_test.rb b/test/functional/artist_commentary_versions_controller_test.rb index 246fda590..9c5f79f2d 100644 --- a/test/functional/artist_commentary_versions_controller_test.rb +++ b/test/functional/artist_commentary_versions_controller_test.rb @@ -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 diff --git a/test/functional/artist_urls_controller_test.rb b/test/functional/artist_urls_controller_test.rb index 8a0f15707..1cbe927db 100644 --- a/test/functional/artist_urls_controller_test.rb +++ b/test/functional/artist_urls_controller_test.rb @@ -2,28 +2,24 @@ require 'test_helper' class ArtistUrlsControllerTest < ActionDispatch::IntegrationTest context "The artist urls controller" do + setup do + @artist = create(:artist, name: "bkub", url_string: "-http://bkub.com") + @banned = create(:artist, name: "danbo", is_banned: true, url_string: "https://danbooru.donmai.us") + end + context "index page" do should "render" do get artist_urls_path assert_response :success end - should "render for a json request" do - get artist_urls_path, as: :json - assert_response :success - end + should respond_to_search({}).with { @banned.urls + @artist.urls } + should respond_to_search(url_matches: "*bkub*").with { @artist.urls } + should respond_to_search(is_active: "false").with { @artist.urls } - should "render for a complex search" do - @artist = FactoryBot.create(:artist, name: "bkub", url_string: "-http://bkub.com") - - get artist_urls_path(search: { - artist: { name: "bkub" }, - url_matches: "*bkub*", - is_active: "false", - order: "created_at" - }) - - assert_response :success + context "using includes" do + should respond_to_search(artist: {name: "bkub"}).with { @artist.urls } + should respond_to_search(artist: {is_banned: "true"}).with { @banned.urls } end end end diff --git a/test/functional/artist_versions_controller_test.rb b/test/functional/artist_versions_controller_test.rb index 143b8d196..30985d386 100644 --- a/test/functional/artist_versions_controller_test.rb +++ b/test/functional/artist_versions_controller_test.rb @@ -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 diff --git a/test/functional/artists_controller_test.rb b/test/functional/artists_controller_test.rb index 076d8fd41..11ebae670 100644 --- a/test/functional/artists_controller_test.rb +++ b/test/functional/artists_controller_test.rb @@ -28,6 +28,8 @@ class ArtistsControllerTest < ActionDispatch::IntegrationTest @artist = create(:artist) @masao = create(:artist, name: "masao", url_string: "http://www.pixiv.net/member.php?id=32777") @artgerm = create(:artist, name: "artgerm", url_string: "http://artgerm.deviantart.com/") + @wiki = create(:wiki_page, title: "artgerm") + @post = create(:post, tag_string: "masao") end end @@ -130,7 +132,7 @@ class ArtistsControllerTest < ActionDispatch::IntegrationTest end context "index action" do - should "get the index page" do + should "render" do get artists_path assert_response :success end @@ -142,26 +144,36 @@ class ArtistsControllerTest < ActionDispatch::IntegrationTest end context "when searching the index page" do + setup do + @deleted = create(:artist, is_deleted: true) + @banned = create(:artist, is_banned: true) + end + should "find artists by name" do get artists_path(name: "masao", format: "json") assert_artist_found("masao") end - should "find artists by image URL" do - get artists_path(search: { url_matches: "http://i2.pixiv.net/img04/img/syounen_no_uta/46170939_m.jpg" }, format: "json") - assert_artist_found("masao") + should respond_to_search({}).with { [@banned, @deleted, @artgerm, @masao, @artist] } + should respond_to_search(name: "masao").with { @masao } + should respond_to_search(is_banned: "true").with { @banned } + should respond_to_search(is_deleted: "true").with { @deleted } + should respond_to_search(url_matches: "http://i2.pixiv.net/img04/img/syounen_no_uta/46170939_m.jpg").with { @masao } + should respond_to_search(url_matches: "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46170939").with { @masao } + + context "ignoring whitespace" do + should respond_to_search(url_matches: " http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46170939 ").with { @masao } end - should "find artists by page URL" do - url = "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46170939" - get artists_path(search: { url_matches: url }, format: "json") - assert_artist_found("masao") - end - - should "ignore whitespace when searching by URL" do - url = " http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46170939 " - get artists_path(search: { url_matches: url }, format: "json") - assert_artist_found("masao") + context "using includes" do + should respond_to_search(has_wiki_page: "true").with { @artgerm } + should respond_to_search(has_wiki_page: "false").with { [@banned, @deleted, @masao, @artist] } + should respond_to_search(has_tag: "true").with { @masao } + should respond_to_search(has_tag: "false").with { [@banned, @deleted, @artgerm, @artist] } + should respond_to_search(has_urls: "true").with { [@artgerm, @masao] } + should respond_to_search(has_urls: "false").with { [@banned, @deleted, @artist] } + should respond_to_search(urls: {url: "http://www.pixiv.net/member.php?id=32777"}).with { @masao } + should respond_to_search(urls: {normalized_url: "http://www.deviantart.com/artgerm/"}).with { @artgerm } end end end diff --git a/test/functional/bans_controller_test.rb b/test/functional/bans_controller_test.rb index f42f6194b..14806fc54 100644 --- a/test/functional/bans_controller_test.rb +++ b/test/functional/bans_controller_test.rb @@ -3,11 +3,11 @@ require 'test_helper' class BansControllerTest < ActionDispatch::IntegrationTest context "A bans controller" do setup do - @mod = create(:moderator_user) - @user = create(:user) - as(@mod) do - @ban = create(:ban, user: @user) - end + @mod = create(:moderator_user, name: "danbo") + @admin = create(:admin_user) + @user = create(:member_user, id: 999, name: "cirno") + + as(@mod) { @ban = create(:ban, reason: "blah", user: @user, banner: @mod) } end context "new action" do @@ -32,16 +32,25 @@ class BansControllerTest < ActionDispatch::IntegrationTest end context "index action" do + setup do + as(@admin) { @admin_ban = create(:ban, user: build(:builder_user), banner: @admin, expires_at: 1.day.ago ) } + end + should "render" do - get_auth bans_path, @mod + get bans_path assert_response :success end - end - context "search action" do - should "render" do - get_auth bans_path(search: {user_name: @user.name}), @mod - assert_response :success + should respond_to_search({}).with { [@admin_ban, @ban] } + should respond_to_search(reason_matches: "blah").with { @ban } + should respond_to_search(expired: "true").with { @admin_ban } + + context "using includes" do + should respond_to_search(banner_name: "danbo").with { @ban } + should respond_to_search(banner: {level: User::Levels::ADMIN}).with { @admin_ban } + should respond_to_search(user_id: 999).with { @ban } + should respond_to_search(user: {name: "cirno"}).with { @ban } + should respond_to_search(user: {level: User::Levels::BUILDER}).with { @admin_ban } end end @@ -57,7 +66,6 @@ class BansControllerTest < ActionDispatch::IntegrationTest should "not allow mods to ban admins" do assert_difference("Ban.count", 0) do - @admin = create(:admin_user) post_auth bans_path, @mod, params: { ban: { duration: 60, reason: "xxx", user_id: @admin.id }} assert_response 403 diff --git a/test/functional/bulk_update_requests_controller_test.rb b/test/functional/bulk_update_requests_controller_test.rb index b91a8e04c..5b91dd92f 100644 --- a/test/functional/bulk_update_requests_controller_test.rb +++ b/test/functional/bulk_update_requests_controller_test.rb @@ -3,10 +3,11 @@ require 'test_helper' class BulkUpdateRequestsControllerTest < ActionDispatch::IntegrationTest context "BulkUpdateRequestsController" do setup do - @user = create(:user) + @user = create(:user, id: 999) @builder = create(:builder_user) @admin = create(:admin_user) - @bulk_update_request = create(:bulk_update_request, user: @user) + as(@admin) { @forum_topic = create(:forum_topic, id: 100, category_id: 0) } + as(@user) { @bulk_update_request = create(:bulk_update_request, user: @user, forum_topic: @forum_topic) } end context "#new" do @@ -73,10 +74,31 @@ class BulkUpdateRequestsControllerTest < ActionDispatch::IntegrationTest end context "#index" do + setup do + @other_BUR = create(:bulk_update_request, user: @builder, script: "create alias cirno -> 9") + @rejected_BUR = create(:bulk_update_request, status: "rejected") + @approved_BUR = create(:bulk_update_request, status: "approved", approver: @admin) + end + should "render" do get bulk_update_requests_path assert_response :success end + + should respond_to_search({}).with { [@other_BUR, @bulk_update_request, @approved_BUR, @rejected_BUR] } + should respond_to_search(order: "id_desc").with { [@approved_BUR, @rejected_BUR, @other_BUR, @bulk_update_request] } + should respond_to_search(status: "pending").with { [@other_BUR, @bulk_update_request] } + should respond_to_search(script_matches: "cirno -> 9").with { @other_BUR } + should respond_to_search(tags_include_any: "cirno").with { @other_BUR } + + context "using includes" do + should respond_to_search(forum_topic_id: 100).with { @bulk_update_request } + should respond_to_search(forum_topic: {category_id: 0}).with { @bulk_update_request } + should respond_to_search(user_id: 999).with { @bulk_update_request } + should respond_to_search(user: {level: User::Levels::BUILDER}).with { @other_BUR } + should respond_to_search(has_approver: "true").with { @approved_BUR } + should respond_to_search(has_approver: "false").with { [@other_BUR, @bulk_update_request, @rejected_BUR] } + end end context "#show" do diff --git a/test/functional/comment_votes_controller_test.rb b/test/functional/comment_votes_controller_test.rb index 5d2b713d8..20cf11ce3 100644 --- a/test/functional/comment_votes_controller_test.rb +++ b/test/functional/comment_votes_controller_test.rb @@ -3,9 +3,9 @@ require 'test_helper' class CommentVotesControllerTest < ActionDispatch::IntegrationTest context "A comment votes controller" do setup do - CurrentUser.user = @user = create(:user) + CurrentUser.user = @user = create(:user, name: "cirno") CurrentUser.ip_addr = "127.0.0.1" - @comment = create(:comment) + @comment = create(:comment, creator: @user) end teardown do @@ -13,12 +13,36 @@ class CommentVotesControllerTest < ActionDispatch::IntegrationTest CurrentUser.ip_addr = nil end - context "#index" do - should "work" do - create(:comment_vote, user: @user) - get_auth comment_votes_path, @user + context "index action" do + setup do + @voter = create(:gold_user, name: "rumia") + @vote = as (@voter) { create(:comment_vote, comment: @comment, user: @voter) } + @negative_vote = create(:comment_vote, comment: @comment, score: -1) + @unrelated_vote = create(:comment_vote) + end - assert_response :success + context "as a user" do + should "render" do + get_auth comment_votes_path, @user + assert_response :success + end + + should respond_to_search({}).with { [] } + end + + context "as a moderator" do + setup do + CurrentUser.user = create(:mod_user) + end + + should respond_to_search({}).with { [@unrelated_vote, @negative_vote, @vote] } + should respond_to_search(score: -1).with { @negative_vote } + + context "using includes" do + should respond_to_search(comment: {creator_name: "cirno"}).with { [@negative_vote, @vote] } + should respond_to_search(user_name: "rumia").with { @vote } + should respond_to_search(user: {level: User::Levels::GOLD}).with { @vote } + end end end diff --git a/test/functional/comments_controller_test.rb b/test/functional/comments_controller_test.rb index b0c74dbe5..048726ed0 100644 --- a/test/functional/comments_controller_test.rb +++ b/test/functional/comments_controller_test.rb @@ -4,8 +4,8 @@ class CommentsControllerTest < ActionDispatch::IntegrationTest context "A comments controller" do setup do @mod = FactoryBot.create(:moderator_user) - @user = FactoryBot.create(:member_user) - @post = create(:post) + @user = FactoryBot.create(:member_user, name: "cirno") + @post = create(:post, id: 100) CurrentUser.user = @user CurrentUser.ip_addr = "127.0.0.1" @@ -87,10 +87,31 @@ class CommentsControllerTest < ActionDispatch::IntegrationTest end end - should "render by comment" do - @comment = as(@user) { create(:comment, post: @post) } - get comments_path(group_by: "comment") - assert_response :success + context "grouped by comment" do + setup do + @user_comment = create(:comment, post: @post, score: 10, do_not_bump_post: true, creator: @user) + @mod_comment = create(:comment, post: build(:post, tag_string: "touhou"), body: "blah", is_sticky: true, creator: @mod) + @deleted_comment = create(:comment, is_deleted: true) + end + + should "render" do + get comments_path(group_by: "comment") + assert_response :success + end + + should respond_to_search({}, other_params: {group_by: "comment"}).with { [@deleted_comment, @mod_comment, @user_comment] } + should respond_to_search(body_matches: "blah").with { @mod_comment } + should respond_to_search(score: 10).with { @user_comment } + should respond_to_search(is_sticky: "true").with { @mod_comment } + should respond_to_search(do_not_bump_post: "true").with { @user_comment } + should respond_to_search(is_deleted: "true").with { @deleted_comment } + + context "using includes" do + should respond_to_search(post_id: 100).with { @user_comment } + should respond_to_search(post_tags_match: "touhou").with { @mod_comment } + should respond_to_search(creator_name: "cirno").with { @user_comment } + should respond_to_search(creator: {level: User::Levels::MODERATOR}).with { @mod_comment } + end end context "for atom feeds" do diff --git a/test/functional/dmails_controller_test.rb b/test/functional/dmails_controller_test.rb index 5c27628a7..963868a64 100644 --- a/test/functional/dmails_controller_test.rb +++ b/test/functional/dmails_controller_test.rb @@ -3,9 +3,9 @@ require 'test_helper' class DmailsControllerTest < ActionDispatch::IntegrationTest context "The dmails controller" do setup do - @user = create(:user, unread_dmail_count: 1) - @unrelated_user = create(:user) - @dmail = create(:dmail, owner: @user) + @user = create(:user, id: 999, unread_dmail_count: 1) + @unrelated_user = create(:moderator_user, id: 1000, name: "reimu") + @dmail = create(:dmail, owner: @user, from: @user) end teardown do @@ -40,28 +40,41 @@ class DmailsControllerTest < ActionDispatch::IntegrationTest end context "index action" do - should "show dmails owned by the current user by sent" do - get_auth dmails_path, @user, params: {:search => {:owner_id => @dmail.owner_id, :folder => "sent"}} + setup do + CurrentUser.user = @user + @received_dmail = create(:dmail, owner: @user, body: "blah", to: @user, from: @unrelated_user, is_read: true) + @deleted_dmail = create(:dmail, owner: @user, title: "UMAD", to: @unrelated_user, from: @user, is_deleted: true) + @unrelated_dmail = create(:dmail, owner: @unrelated_user, from: @unrelated_user) + end + + should "render" do + get_auth dmails_path, @user assert_response :success end - should "show dmails owned by the current user by received" do - get_auth dmails_path, @user, params: {:search => {:owner_id => @dmail.owner_id, :folder => "received"}} - assert_response :success + should respond_to_search({}).with { [@deleted_dmail, @received_dmail, @dmail] } + should respond_to_search(folder: "sent").with { @dmail } + should respond_to_search(folder: "received").with { @received_dmail } + should respond_to_search(title_matches: "UMAD").with { @deleted_dmail } + should respond_to_search(message_matches: "blah").with { @received_dmail } + should respond_to_search(is_read: "true").with { @received_dmail } + should respond_to_search(is_deleted: "true").with { @deleted_dmail } + + context "using includes" do + should respond_to_search(to_id: 1000).with { @deleted_dmail } + should respond_to_search(from_id: 999).with { [@deleted_dmail, @dmail] } + should respond_to_search(from_name: "reimu").with { @received_dmail } + should respond_to_search(from: {level: User::Levels::MODERATOR}).with { @received_dmail } end - should "not show dmails not owned by the current user" do - get_auth dmails_path, @user, params: {:search => {:owner_id => @dmail.owner_id}} - assert_response :success - end + context "as a banned user" do + setup do + as(create(:admin_user)) do + create(:ban, user: @user) + end - should "work for banned users" do - as(create(:admin_user)) do - create(:ban, :user => @user) + should respond_to_search({}).with { [@received_dmail, @dmail] } end - get_auth dmails_path, @dmail.owner, params: {:search => {:owner_id => @dmail.owner_id, :folder => "sent"}} - - assert_response :success end end diff --git a/test/functional/dtext_links_controller_test.rb b/test/functional/dtext_links_controller_test.rb index 17f6f274a..366a1b510 100644 --- a/test/functional/dtext_links_controller_test.rb +++ b/test/functional/dtext_links_controller_test.rb @@ -1,12 +1,30 @@ require "test_helper" class DtextLinksControllerTest < ActionDispatch::IntegrationTest + setup do + @user = create(:user) + as(@user) do + @wiki = create(:wiki_page, title: "case", body: "[[test]]") + @forum = create(:forum_post, topic: build(:forum_topic, title: "blah"), body: "[[case]]") + create(:tag, name: "test") + end + end + context "index action" do - should "work" do - @user = create(:user) - @wiki = as(@user) { create(:wiki_page, body: "[[test]]") } + should "render" do get dtext_links_path assert_response :success end + + should respond_to_search({}).with { @forum.dtext_links + @wiki.dtext_links } + + context "using includes" do + should respond_to_search(model_type: "WikiPage").with { @wiki.dtext_links } + should respond_to_search(model_type: "ForumPost").with { @forum.dtext_links } + should respond_to_search(has_linked_tag: "true").with { @wiki.dtext_links } + should respond_to_search(has_linked_wiki: "true").with { @forum.dtext_links } + should respond_to_search(ForumPost: {topic: {title_matches: "blah"}}).with { @forum.dtext_links } + should respond_to_search(ForumPost: {topic: {title_matches: "nah"}}).with { [] } + end end end diff --git a/test/functional/favorite_groups_controller_test.rb b/test/functional/favorite_groups_controller_test.rb index 1b853dd0e..f9d0d32bb 100644 --- a/test/functional/favorite_groups_controller_test.rb +++ b/test/functional/favorite_groups_controller_test.rb @@ -8,10 +8,31 @@ class FavoriteGroupsControllerTest < ActionDispatch::IntegrationTest end context "index action" do + setup do + @mod_favgroup = create(:favorite_group, name: "monochrome", creator: build(:moderator_user, name: "fumimi")) + @private_favgroup = create(:favorite_group, creator: @user, is_public: false) + end + should "render" do get favorite_groups_path assert_response :success end + + should respond_to_search({}).with { [@mod_favgroup, @favgroup] } + should respond_to_search(name: "monochrome").with { @mod_favgroup } + + context "using includes" do + should respond_to_search(creator_name: "fumimi").with { @mod_favgroup } + should respond_to_search(creator: {level: User::Levels::MEMBER}).with { @favgroup } + end + + context "for private favorite groups as the creator" do + setup do + CurrentUser.user = @user + end + + should respond_to_search(is_public: "false").with { @private_favgroup } + end end context "show action" do diff --git a/test/functional/forum_post_votes_controller_test.rb b/test/functional/forum_post_votes_controller_test.rb index 5d693d26b..952551cb4 100644 --- a/test/functional/forum_post_votes_controller_test.rb +++ b/test/functional/forum_post_votes_controller_test.rb @@ -3,22 +3,35 @@ require 'test_helper' class ForumPostVotesControllerTest < ActionDispatch::IntegrationTest context "The forum post votes controller" do setup do - @user = create(:user) + @user = create(:user, name: "cirno") @other_user = create(:user) as(@user) do - @forum_topic = create(:forum_topic) - @forum_post = create(:forum_post, topic: @forum_topic) + @forum_post = create(:forum_post, body: "blah", creator: @user) @bulk_update_request = create(:bulk_update_request, forum_post: @forum_post) end end context "index action" do + setup do + @vote = create(:forum_post_vote, forum_post: @forum_post, creator: build(:user, name: "rumia"), score: 1) + @negative_vote = create(:forum_post_vote, forum_post: @forum_post, score: -1) + @unrelated_vote = as (@user) { create(:forum_post_vote, score: 0) } + end + should "render" do - @forum_post_vote = create(:forum_post_vote, creator: @user, forum_post: @forum_post) get forum_post_votes_path assert_response :success end + + should respond_to_search({}).with { [@unrelated_vote, @negative_vote, @vote] } + should respond_to_search(score: -1).with { @negative_vote } + + context "using includes" do + should respond_to_search(creator_name: "rumia").with { @vote } + should respond_to_search(forum_post: {creator_name: "cirno"}).with { [@negative_vote, @vote] } + should respond_to_search(forum_post: {body_matches: "blah"}).with { [@negative_vote, @vote] } + end end context "create action" do diff --git a/test/functional/forum_posts_controller_test.rb b/test/functional/forum_posts_controller_test.rb index d6c643e52..41cde00d0 100644 --- a/test/functional/forum_posts_controller_test.rb +++ b/test/functional/forum_posts_controller_test.rb @@ -3,9 +3,9 @@ require 'test_helper' class ForumPostsControllerTest < ActionDispatch::IntegrationTest context "The forum posts controller" do setup do - @user = create(:user) + @user = create(:user, id: 999) @other_user = create(:user) - @mod = create(:moderator_user) + @mod = create(:moderator_user, name: "okuu") @forum_topic = as(@user) { create(:forum_topic, title: "my forum topic", creator: @user) } @forum_post = as(@user) { create(:forum_post, creator: @user, topic: @forum_topic, body: "alias xxx -> yyy") } end @@ -52,65 +52,61 @@ class ForumPostsControllerTest < ActionDispatch::IntegrationTest end context "index action" do - should "list all forum posts" do - get forum_posts_path - assert_response :success + setup do + @admin = create(:admin_user) + @other_forum = as(@user) { create(:forum_post, body: "[[test]]", topic: build(:forum_topic, title: "my topic", category_id: 1)) } + @mod_forum = as(@mod) { create(:forum_post, creator: @mod, topic: build(:forum_topic, min_level: User::Levels::MODERATOR)) } + @admin_forum = as(@admin) { create(:forum_post, creator: @admin, topic: build(:forum_topic, min_level: User::Levels::ADMIN)) } + @unrelated_forum = as (@user) { create(:forum_post, is_deleted: true) } + as (@user) { create(:forum_post_vote, forum_post: @forum_post) } + create(:bulk_update_request, forum_post: @other_forum) end - context "with search conditions" do - should "list all matching forum posts" do - get forum_posts_path, params: { search: { body_matches: "xxx", topic_title_matches: "my forum topic" }} - assert_response :success - assert_select "#forum-post-#{@forum_post.id}" - end - - should "list nothing for when the search matches nothing" do - get forum_posts_path, params: {:search => {:body_matches => "bababa"}} - assert_response :success - assert_select "#forum-post-#{@forum_post.id}", false - end - - should "list by creator id" do - get forum_posts_path, params: {:search => {:creator_id => @user.id}} - assert_response :success - assert_select "#forum-post-#{@forum_post.id}" - end - end - - context "for posts in private topics" do + context "as a user" do setup do - @admin = create(:admin_user) - @mod_post = as(@mod) { create(:forum_post, creator: @mod, topic: build(:forum_topic, min_level: User::Levels::MODERATOR)) } - @admin_post = as(@admin) { create(:forum_post, creator: @admin, topic: build(:forum_topic, min_level: User::Levels::ADMIN)) } + CurrentUser.user = @user end - should "list only permitted posts for anons" do - get forum_posts_path - + should "render" do + get_auth comment_votes_path, @user assert_response :success - assert_select "#forum-post-#{@forum_post.id}" - assert_select "#forum-post-#{@mod_post.id}", false - assert_select "#forum-post-#{@admin_post.id}", false end - should "list only permitted posts for mods" do - get_auth forum_posts_path, @mod + should respond_to_search({}).with { [@unrelated_forum, @other_forum, @forum_post] } + should respond_to_search(body_matches: "xxx").with { @forum_post } + should respond_to_search(body_matches: "bababa").with { [] } + should respond_to_search(is_deleted: "true").with { @unrelated_forum } - assert_response :success - assert_select "#forum-post-#{@forum_post.id}" - assert_select "#forum-post-#{@mod_post.id}" - assert_select "#forum-post-#{@admin_post.id}", false + context "using includes" do + should respond_to_search(topic: {title_matches: "my forum topic"}).with { @forum_post } + should respond_to_search(topic: {category_id: 1}).with { @other_forum } + should respond_to_search(has_bulk_update_request: "true").with { @other_forum } + should respond_to_search(has_votes: "true").with { @forum_post } + should respond_to_search(has_dtext_links: "true").with { @other_forum } + should respond_to_search(creator_id: 999).with { @forum_post } + should respond_to_search(creator: {name: "okuu"}).with { [] } + end + end + + context "as a moderator" do + setup do + CurrentUser.user = @mod end - should "list only permitted posts for admins" do - get_auth forum_posts_path, @admin + should respond_to_search({}).with { [@unrelated_forum, @mod_forum, @other_forum, @forum_post] } - assert_response :success - assert_select "#forum-post-#{@forum_post.id}" - assert_select "#forum-post-#{@mod_post.id}" - assert_select "#forum-post-#{@admin_post.id}" + context "using includes" do + should respond_to_search(creator: {name: "okuu"}).with { @mod_forum } end end + + context "as an admin" do + setup do + CurrentUser.user = @admin + end + + should respond_to_search({}).with { [@unrelated_forum, @admin_forum, @mod_forum, @other_forum, @forum_post] } + end end context "show action" do diff --git a/test/functional/forum_topics_controller_test.rb b/test/functional/forum_topics_controller_test.rb index 4b3a0e2e4..59eb04d05 100644 --- a/test/functional/forum_topics_controller_test.rb +++ b/test/functional/forum_topics_controller_test.rb @@ -1,15 +1,18 @@ require 'test_helper' class ForumTopicsControllerTest < ActionDispatch::IntegrationTest + def default_search_order(items) + ->{ items.each { |val| val.reload }.sort_by(&:updated_at).reverse } + end + context "The forum topics controller" do setup do @user = create(:user) @other_user = create(:user) - @mod = create(:moderator_user) + @mod = create(:moderator_user, name: "okuu") as(@user) do - @forum_topic = create(:forum_topic, creator: @user, title: "my forum topic") - @forum_post = create(:forum_post, creator: @user, topic: @forum_topic, body: "xxx") + @forum_topic = create(:forum_topic, creator: @user, title: "my forum topic", original_post: build(:forum_post, creator: @user, topic: @forum_topic, body: "xxx")) end end @@ -88,25 +91,26 @@ class ForumTopicsControllerTest < ActionDispatch::IntegrationTest context "index action" do setup do as(@user) do - @topic1 = create(:forum_topic, is_sticky: true, creator: @user) - @topic2 = create(:forum_topic, creator: @user) - @post1 = create(:forum_post, topic: @topic1, creator: @user, body: "xxx") - @post2 = create(:forum_post, topic: @topic2, creator: @user, body: "xxx") + @sticky_topic = create(:forum_topic, is_sticky: true, creator: @user, original_post: build(:forum_post)) + @other_topic = create(:forum_topic, creator: @user, original_post: build(:forum_post)) end + @mod_topic = as(@mod) { create(:forum_topic, creator: @mod, min_level: User::Levels::MODERATOR, original_post: build(:forum_post)) } + create(:bulk_update_request, forum_topic: @forum_topic) + create(:tag_alias, forum_topic: @other_topic) end should "list public forum topics for members" do get forum_topics_path assert_response :success - assert_select "a.forum-post-link", count: 1, text: @topic1.title - assert_select "a.forum-post-link", count: 1, text: @topic2.title + assert_select "a.forum-post-link", count: 1, text: @sticky_topic.title + assert_select "a.forum-post-link", count: 1, text: @other_topic.title end should "not list stickied topics first for JSON responses" do get forum_topics_path, params: {format: :json} forum_topics = JSON.parse(response.body) - assert_equal([@topic2.id, @topic1.id, @forum_topic.id], forum_topics.map {|t| t["id"]}) + assert_equal(default_search_order([@other_topic, @sticky_topic, @forum_topic]).call.map(&:id), forum_topics.map {|t| t["id"]}) end should "render for atom feed" do @@ -122,39 +126,54 @@ class ForumTopicsControllerTest < ActionDispatch::IntegrationTest context "with private topics" do should "not show private topics to unprivileged users" do - as(@user) { @topic2.update!(min_level: User::Levels::MODERATOR) } + as(@user) { @other_topic.update!(min_level: User::Levels::MODERATOR) } get forum_topics_path assert_response :success - assert_select "a.forum-post-link", count: 1, text: @topic1.title - assert_select "a.forum-post-link", count: 0, text: @topic2.title + assert_select "a.forum-post-link", count: 1, text: @sticky_topic.title + assert_select "a.forum-post-link", count: 0, text: @other_topic.title end should "show private topics to privileged users" do - as(@user) { @topic2.update!(min_level: User::Levels::MODERATOR) } + as(@user) { @other_topic.update!(min_level: User::Levels::MODERATOR) } get_auth forum_topics_path, @mod assert_response :success - assert_select "a.forum-post-link", count: 1, text: @topic1.title - assert_select "a.forum-post-link", count: 1, text: @topic2.title + assert_select "a.forum-post-link", count: 1, text: @sticky_topic.title + assert_select "a.forum-post-link", count: 1, text: @other_topic.title end end context "with search conditions" do - should "list all matching forum topics" do - get forum_topics_path, params: {:search => {:title_matches => "forum"}} - assert_response :success - assert_select "a.forum-post-link", @forum_topic.title - assert_select "a.forum-post-link", count: 0, text: @topic1.title - assert_select "a.forum-post-link", count: 0, text: @topic2.title + context "as a user" do + setup do + CurrentUser.user = @user + end + + should respond_to_search({}).with { default_search_order([@sticky_topic, @other_topic, @forum_topic]) } + should respond_to_search(order: "id").with { [@other_topic, @sticky_topic, @forum_topic] } + should respond_to_search(title_matches: "forum").with { @forum_topic } + should respond_to_search(title_matches: "bababa").with { [] } + should respond_to_search(is_sticky: "true").with { @sticky_topic } + + context "using includes" do + should respond_to_search(forum_posts: {body_matches: "xxx"}).with { @forum_topic } + should respond_to_search(has_bulk_update_requests: "true").with { @forum_topic } + should respond_to_search(has_tag_aliases: "true").with { @other_topic } + should respond_to_search(creator_name: "okuu").with { [] } + end end - should "list nothing for when the search matches nothing" do - get forum_topics_path, params: {:search => {:title_matches => "bababa"}} - assert_response :success - assert_select "a.forum-post-link", count: 0, text: @forum_topic.title - assert_select "a.forum-post-link", count: 0, text: @topic1.title - assert_select "a.forum-post-link", count: 0, text: @topic2.title + context "as a moderator" do + setup do + CurrentUser.user = @mod + end + + should respond_to_search({}).with { default_search_order([@sticky_topic, @other_topic, @mod_topic, @forum_topic]) } + + context "using includes" do + should respond_to_search(creator_name: "okuu").with { @mod_topic } + end end end diff --git a/test/functional/ip_bans_controller_test.rb b/test/functional/ip_bans_controller_test.rb index bd6465afc..2ac8f3075 100644 --- a/test/functional/ip_bans_controller_test.rb +++ b/test/functional/ip_bans_controller_test.rb @@ -3,8 +3,8 @@ require 'test_helper' class IpBansControllerTest < ActionDispatch::IntegrationTest context "The ip bans controller" do setup do - @admin = create(:admin_user) - @ip_ban = create(:ip_ban) + @admin = create(:admin_user, name: "yukari") + @ip_ban = create(:ip_ban, ip_addr: "6.7.8.9") end context "new action" do @@ -24,21 +24,34 @@ class IpBansControllerTest < ActionDispatch::IntegrationTest should "log a mod action" do post_auth ip_bans_path, @admin, params: { ip_ban: { ip_addr: "1.2.3.4", reason: "xyz" }} - assert_equal("ip_ban_create", ModAction.last.category) + assert_equal("ip_ban_create", ModAction.last&.category) end end context "index action" do + setup do + CurrentUser.user = @admin + @subnet_ban = create(:ip_ban, ip_addr: "2.0.0.0/24", creator: @admin) + @other_ban = create(:ip_ban, reason: "malware") + end + + should "render access denied for anonymous users" do + get ip_bans_path + assert_response 403 + end + should "render" do get_auth ip_bans_path, @admin assert_response :success end - context "with search parameters" do - should "render" do - get_auth ip_bans_path, @admin, params: {:search => {:ip_addr => "1.2.3.4"}} - assert_response :success - end + should respond_to_search({}).with { [@other_ban, @subnet_ban, @ip_ban] } + should respond_to_search(ip_addr: "6.7.8.9").with { @ip_ban } + should respond_to_search(reason_matches: "malware").with { @other_ban } + + context "using includes" do + should respond_to_search(creator_name: "yukari").with { @subnet_ban } + should respond_to_search(creator: {level: User::Levels::ADMIN}).with { @subnet_ban } end end diff --git a/test/functional/mod_actions_controller_test.rb b/test/functional/mod_actions_controller_test.rb index 8d5466a45..e013b264b 100644 --- a/test/functional/mod_actions_controller_test.rb +++ b/test/functional/mod_actions_controller_test.rb @@ -3,14 +3,28 @@ require 'test_helper' class ModActionsControllerTest < ActionDispatch::IntegrationTest context "The mod actions controller" do setup do - @mod_action = create(:mod_action) + @mod_action = create(:mod_action, description: "blah", category: "post_delete") end context "index action" do - should "work" do + setup do + @promote_action = create(:mod_action, category: "user_level_change", creator: build(:builder_user, name: "rumia")) + @unrelated_action = create(:mod_action) + end + + should "render" do get mod_actions_path assert_response :success end + + should respond_to_search({}).with { [@unrelated_action, @promote_action, @mod_action] } + should respond_to_search(category: ModAction.categories["user_level_change"]).with { @promote_action } + should respond_to_search(description_matches: "blah").with { @mod_action } + + context "using includes" do + should respond_to_search(creator_name: "rumia").with { @promote_action } + should respond_to_search(creator: {level: User::Levels::BUILDER}).with { @promote_action } + end end context "show action" do diff --git a/test/functional/moderation_reports_controller_test.rb b/test/functional/moderation_reports_controller_test.rb index 568e6e81b..ff9af203c 100644 --- a/test/functional/moderation_reports_controller_test.rb +++ b/test/functional/moderation_reports_controller_test.rb @@ -9,9 +9,8 @@ class ModerationReportsControllerTest < ActionDispatch::IntegrationTest as(@spammer) do @dmail = create(:dmail, from: @spammer, owner: @user, to: @user) - @comment = create(:comment, creator: @spammer) - @forum_topic = create(:forum_topic, creator: @spammer) - @forum_post = create(:forum_post, topic: @forum_topic, creator: @spammer) + @comment = create(:comment, id: 1234, creator: @spammer) + @forum_post = create(:forum_post, topic: build(:forum_topic), body: "xxx", creator: @spammer) end end @@ -29,24 +28,37 @@ class ModerationReportsControllerTest < ActionDispatch::IntegrationTest context "index action" do setup do - create(:moderation_report, model: @comment, creator: @user) + @comment_report = create(:moderation_report, model: @comment, creator: @user) + @forum_report = create(:moderation_report, model: @forum_post, creator: @user) + @dmail_report = create(:moderation_report, reason: "spam", model: @dmail, creator: build(:builder_user, name: "daiyousei", created_at: 2.weeks.ago)) end - should "render the access denied page for members" do - get_auth moderation_reports_path, @user - assert_response 403 + context "as a user" do + should "render the access denied page" do + get_auth moderation_reports_path, @user + assert_response 403 + end end - should "render for mods" do - get_auth moderation_reports_path, @mod - assert_response :success - end + context "as a moderator" do + setup do + CurrentUser.user = @mod + end - context "with search parameters" do should "render" do - get_auth moderation_reports_path, @mod, params: {:search => {:model_id => @comment.id}} + get_auth moderation_reports_path, @mod assert_response :success end + + should respond_to_search({}).with { [@dmail_report, @forum_report, @comment_report] } + should respond_to_search(reason_matches: "spam").with { @dmail_report } + + context "using includes" do + should respond_to_search(model_id: 1234).with { @comment_report } + should respond_to_search(model_type: "ForumPost").with { @forum_report } + should respond_to_search(ForumPost: {body_matches: "xxx"}).with { @forum_report } + should respond_to_search(creator_name: "daiyousei").with { @dmail_report } + end end end diff --git a/test/functional/note_versions_controller_test.rb b/test/functional/note_versions_controller_test.rb index cbc100c99..22b5da38d 100644 --- a/test/functional/note_versions_controller_test.rb +++ b/test/functional/note_versions_controller_test.rb @@ -3,23 +3,34 @@ require 'test_helper' class NoteVersionsControllerTest < ActionDispatch::IntegrationTest context "The note versions controller" do setup do - @user = create(:user) - @user_2 = create(:user) + @user = create(:user, id: 100) + @user_2 = create(:user, name: "cirno") - as(@user) { @note = create(:note) } - as(@user_2) { @note.update(body: "1 2") } - as(@user) { @note.update(body: "1 2 3") } + as(@user) { @note = create(:note, id: 101) } + as(@user_2) { @note.update(body: "blah", is_active: false) } + as(@user) { @note.update(body: "1 2 3", is_active: true) } end context "index action" do - should "list all versions" do + setup do + @versions = @note.versions + end + + should "render" do get note_versions_path assert_response :success end - should "list all versions that match the search criteria" do - get note_versions_path, params: {:search => {:updater_id => @user_2.id}} - assert_response :success + should respond_to_search({}).with { @versions.reverse } + should respond_to_search(body_matches: "blah").with { @versions[1] } + should respond_to_search(version: 1).with { @versions[0] } + should respond_to_search(is_active: "false").with { @versions[1] } + + context "using includes" do + should respond_to_search(note_id: 101).with { @versions.reverse } + should respond_to_search(note_id: 102).with { [] } + should respond_to_search(updater_id: 100).with { [@versions[2], @versions[0]] } + should respond_to_search(updater: {name: "cirno"}).with { @versions[1] } end end diff --git a/test/functional/notes_controller_test.rb b/test/functional/notes_controller_test.rb index 8bae95026..1acb91d36 100644 --- a/test/functional/notes_controller_test.rb +++ b/test/functional/notes_controller_test.rb @@ -8,24 +8,25 @@ class NotesControllerTest < ActionDispatch::IntegrationTest end context "index action" do - should "list all notes" do + setup do + as(@user) do + @post_note = create(:note, post: build(:post, id: 2001, tag_string: "touhou")) + @deleted_note = create(:note, is_active: false) + end + end + + should "render" do get notes_path assert_response :success end - should "list all notes (with search)" do - params = { - group_by: "note", - search: { - body_matches: "000", - is_active: true, - post_id: @note.post_id, - post_tags_match: @note.post.tag_array.first - } - } + should respond_to_search({}).with { [@deleted_note, @post_note, @note] } + should respond_to_search(body_matches: "000").with { @note } + should respond_to_search(is_active: "true").with { [@post_note, @note] } - get notes_path, params: params - assert_response :success + context "using includes" do + should respond_to_search(post_id: 2001).with { @post_note } + should respond_to_search(post_tags_match: "touhou").with { @post_note } end end diff --git a/test/functional/post_appeals_controller_test.rb b/test/functional/post_appeals_controller_test.rb index faa5982de..8e3d9c585 100644 --- a/test/functional/post_appeals_controller_test.rb +++ b/test/functional/post_appeals_controller_test.rb @@ -3,7 +3,8 @@ require 'test_helper' class PostAppealsControllerTest < ActionDispatch::IntegrationTest context "The post appeals controller" do setup do - @user = create(:user) + @user = create(:user, name: "orin") + @post = create(:post, id: 101, is_deleted: true) end context "new action" do @@ -24,8 +25,10 @@ class PostAppealsControllerTest < ActionDispatch::IntegrationTest context "index action" do setup do as(@user) do - @post = create(:post, :is_deleted => true) - @post_appeal = create(:post_appeal, :post => @post) + @post_appeal = create(:post_appeal, post: @post, creator: @user) + @unrelated_appeal = create(:post_appeal, reason: "Good.") + @resolved_appeal = create(:post_appeal) + @resolved_appeal.post.update(is_deleted: false) end end @@ -34,24 +37,18 @@ class PostAppealsControllerTest < ActionDispatch::IntegrationTest assert_response :success end - should "render for json" do - get post_appeals_path, as: :json - assert_response :success - end + should respond_to_search({}).with { [@resolved_appeal, @unrelated_appeal, @post_appeal] } + should respond_to_search(reason_matches: "Good.").with { @unrelated_appeal } + should respond_to_search(is_resolved: "true").with { @resolved_appeal } - context "with search parameters" do - should "render" do - get_auth post_appeals_path, @user, params: {:search => {:post_id => @post_appeal.post_id}} - assert_response :success - end + context "using includes" do + should respond_to_search(post_id: 101).with { @post_appeal } + should respond_to_search(post: {is_deleted: "true"}).with { [@unrelated_appeal, @post_appeal] } + should respond_to_search(creator_name: "orin").with { @post_appeal } end end context "create action" do - setup do - @post = as(@user) { create(:post, is_deleted: true) } - end - should "create a new appeal" do assert_difference("PostAppeal.count", 1) do post_auth post_appeals_path, @user, params: {:format => "js", :post_appeal => {:post_id => @post.id, :reason => "xxx"}} diff --git a/test/functional/post_approvals_controller_test.rb b/test/functional/post_approvals_controller_test.rb index e4b93c65f..7b933b44b 100644 --- a/test/functional/post_approvals_controller_test.rb +++ b/test/functional/post_approvals_controller_test.rb @@ -3,7 +3,7 @@ require 'test_helper' class PostApprovalsControllerTest < ActionDispatch::IntegrationTest context "The post approvals controller" do setup do - @approver = create(:approver) + @approver = create(:approver, name: "eiki") end context "create action" do @@ -37,11 +37,25 @@ class PostApprovalsControllerTest < ActionDispatch::IntegrationTest end context "index action" do + setup do + @post = create(:post, tag_string: "touhou", is_pending: true, uploader: build(:user, name: "komachi", created_at: 2.weeks.ago)) + @post_approval = create(:post_approval, post: @post) + @user_approval = create(:post_approval, user: @approver) + @unrelated_approval = create(:post_approval) + end + should "render" do - @approval = create(:post_approval) get post_approvals_path assert_response :success end + + should respond_to_search({}).with { [@unrelated_approval, @user_approval, @post_approval] } + + context "using includes" do + should respond_to_search(user_name: "eiki").with { @user_approval } + should respond_to_search(post_tags_match: "touhou").with { @post_approval } + should respond_to_search(post: {uploader_name: "komachi"}).with { @post_approval } + end end end end diff --git a/test/functional/post_disapprovals_controller_test.rb b/test/functional/post_disapprovals_controller_test.rb index 9260dda0f..513b16c67 100644 --- a/test/functional/post_disapprovals_controller_test.rb +++ b/test/functional/post_disapprovals_controller_test.rb @@ -3,9 +3,8 @@ require 'test_helper' class PostDisapprovalsControllerTest < ActionDispatch::IntegrationTest context "The post disapprovals controller" do setup do - @approver = create(:approver) - @post = create(:post, is_pending: true) - @post_disapproval = create(:post_disapproval, post: @post) + @approver = create(:approver, name: "eiki") + @post = create(:post, tag_string: "touhou", is_pending: true, uploader: build(:user, name: "marisa", created_at: 2.weeks.ago)) end context "create action" do @@ -40,16 +39,36 @@ class PostDisapprovalsControllerTest < ActionDispatch::IntegrationTest end context "index action" do + setup do + @post_disapproval = create(:post_disapproval, post: @post) + @user_disapproval = create(:post_disapproval, user: @approver) + @unrelated_disapproval = create(:post_disapproval, message: "bad") + end + + should "render" do + get post_disapprovals_path + assert_response :success + end + + should respond_to_search({}).with { [@unrelated_disapproval, @user_disapproval, @post_disapproval] } + should respond_to_search(message: "bad").with { @unrelated_disapproval } + + context "using includes" do + should respond_to_search(post_tags_match: "touhou").with { @post_disapproval } + should respond_to_search(post: {uploader_name: "marisa"}).with { @post_disapproval } + should respond_to_search(user_name: "eiki").with { @user_disapproval } + end + should "allow mods to see disapprover names" do get_auth post_disapprovals_path, create(:mod_user) assert_response :success - assert_select "tr#post-disapproval-#{@post_disapproval.id} .created-column a.user-member", true + assert_select "tr#post-disapproval-#{@post_disapproval.id} .created-column a.user-post-approver", true end should "not allow non-mods to see disapprover names" do get post_disapprovals_path assert_response :success - assert_select "tr#post-disapproval-#{@post_disapproval.id} .created-column a.user-member", false + assert_select "tr#post-disapproval-#{@post_disapproval.id} .created-column a.user-post-approver", false end end end diff --git a/test/functional/post_flags_controller_test.rb b/test/functional/post_flags_controller_test.rb index a4766c54f..fe74264ea 100644 --- a/test/functional/post_flags_controller_test.rb +++ b/test/functional/post_flags_controller_test.rb @@ -4,10 +4,10 @@ class PostFlagsControllerTest < ActionDispatch::IntegrationTest context "The post flags controller" do setup do @user = create(:user) - @flagger = create(:gold_user, created_at: 2.weeks.ago) - @uploader = create(:mod_user, created_at: 2.weeks.ago) + @flagger = create(:gold_user, id: 999, created_at: 2.weeks.ago) + @uploader = create(:mod_user, name: "chen", created_at: 2.weeks.ago) @mod = create(:mod_user) - @post = create(:post, is_flagged: true, uploader: @uploader) + @post = create(:post, id: 101, is_flagged: true, uploader: @uploader) @post_flag = create(:post_flag, post: @post, creator: @flagger) end @@ -26,6 +26,11 @@ class PostFlagsControllerTest < ActionDispatch::IntegrationTest end context "index action" do + setup do + @other_flag = create(:post_flag, post: build(:post, is_flagged: true, tag_string: "touhou")) + @unrelated_flag = create(:post_flag, reason: "poor quality") + end + should "render" do get post_flags_path assert_response :success @@ -60,23 +65,46 @@ class PostFlagsControllerTest < ActionDispatch::IntegrationTest assert_select "tr#post-flag-#{@post_flag.id} .flagged-column a.user-gold", true end - context "with search parameters" do - should "render" do - get_auth post_flags_path(search: { post_id: @post_flag.post_id }), @user - assert_response :success + context "as a normal user" do + setup do + CurrentUser.user = @user end - should "hide flagged posts when the searcher is the uploader" do - get_auth post_flags_path(search: { creator_id: @flagger.id }), @uploader - assert_response :success - assert_select "tr#post-flag-#{@post_flag.id}", false + should respond_to_search({}).with { [@unrelated_flag, @other_flag, @post_flag] } + should respond_to_search(reason_matches: "poor quality").with { @unrelated_flag } + should respond_to_search(category: "normal").with { [@unrelated_flag, @other_flag, @post_flag] } + should respond_to_search(category: "deleted").with { [] } + + context "using includes" do + should respond_to_search(post_id: 101).with { @post_flag } + should respond_to_search(post_tags_match: "touhou").with { @other_flag } + should respond_to_search(post: {uploader_name: "chen"}).with { @post_flag } + should respond_to_search(creator_id: 999).with { [] } + end + end + + context "when the user is the uploader" do + setup do + CurrentUser.user = @uploader end - should "show flagged posts when the searcher is not the uploader" do - get_auth post_flags_path(search: { creator_id: @flagger.id }), @mod - assert_response :success - assert_select "tr#post-flag-#{@post_flag.id}", true + should respond_to_search(creator_id: 999).with { [] } + end + + context "when the user is a mod and not the uploader" do + setup do + CurrentUser.user = @mod end + + should respond_to_search(creator_id: 999).with { @post_flag } + end + + context "when the user is the flagger" do + setup do + CurrentUser.user = @flagger + end + + should respond_to_search(creator_id: 999).with { @post_flag } end end diff --git a/test/functional/post_replacements_controller_test.rb b/test/functional/post_replacements_controller_test.rb index 26f41ccf5..e9021d1de 100644 --- a/test/functional/post_replacements_controller_test.rb +++ b/test/functional/post_replacements_controller_test.rb @@ -3,9 +3,9 @@ require 'test_helper' class PostReplacementsControllerTest < ActionDispatch::IntegrationTest context "The post replacements controller" do setup do - @mod = create(:moderator_user, can_approve_posts: true, created_at: 1.month.ago) + @mod = create(:moderator_user, name: "yukari", can_approve_posts: true, created_at: 1.month.ago) as(@mod) do - @post = create(:post, source: "https://google.com") + @post = create(:post, source: "https://google.com", tag_string: "touhou") @post_replacement = create(:post_replacement, post: @post) end end @@ -60,10 +60,23 @@ class PostReplacementsControllerTest < ActionDispatch::IntegrationTest end context "index action" do + setup do + as(create(:admin_user)) { @admin_replacement = create(:post_replacement, replacement_url: "https://danbooru.donmai.us") } + end + should "render" do - get post_replacements_path, params: {format: "json"} + get post_replacements_path assert_response :success end + + should respond_to_search({}).with { [@admin_replacement, @post_replacement] } + should respond_to_search(replacement_url_like: "*danbooru*").with { @admin_replacement } + + context "using includes" do + should respond_to_search(post_tags_match: "touhou").with { @post_replacement } + should respond_to_search(creator: {level: User::Levels::ADMIN}).with { @admin_replacement } + should respond_to_search(creator_name: "yukari").with { @post_replacement } + end end end end diff --git a/test/functional/post_votes_controller_test.rb b/test/functional/post_votes_controller_test.rb index 4024010d7..65313b022 100644 --- a/test/functional/post_votes_controller_test.rb +++ b/test/functional/post_votes_controller_test.rb @@ -3,17 +3,45 @@ require 'test_helper' class PostVotesControllerTest < ActionDispatch::IntegrationTest context "The post vote controller" do setup do - @user = create(:gold_user) - @post = create(:post) + @user = create(:gold_user, name: "meiling") + @post = create(:post, tag_string: "dragon") end context "index action" do - should "work" do - as(@user) { create(:post_vote, post_id: @post.id, user_id: @user.id) } - get_auth post_votes_path, @user + setup do + @admin = create(:admin_user) + as(@user) { @post_vote = create(:post_vote, post: @post, user: @user) } + as(@admin) { @admin_vote = create(:post_vote, post: @post, user: @admin) } + @unrelated_vote = create(:post_vote) + end + should "render" do + get_auth post_votes_path, @user assert_response :success end + + context "as a user" do + setup do + CurrentUser.user = @user + end + + should respond_to_search({}).with { @post_vote } + end + + context "as a moderator" do + setup do + CurrentUser.user = @admin + end + + should respond_to_search({}).with { [@unrelated_vote, @admin_vote, @post_vote] } + should respond_to_search(score: 1).with { [@unrelated_vote, @admin_vote, @post_vote].select{ |v| v.score == 1 } } + + context "using includes" do + should respond_to_search(post_tags_match: "dragon").with { [@admin_vote, @post_vote] } + should respond_to_search(user_name: "meiling").with { @post_vote } + should respond_to_search(user: {level: User::Levels::ADMIN}).with { @admin_vote } + end + end end context "create action" do diff --git a/test/functional/tag_aliases_controller_test.rb b/test/functional/tag_aliases_controller_test.rb index f987f4580..4e6111d83 100644 --- a/test/functional/tag_aliases_controller_test.rb +++ b/test/functional/tag_aliases_controller_test.rb @@ -7,14 +7,42 @@ class TagAliasesControllerTest < ActionDispatch::IntegrationTest end context "index action" do - should "list all tag alias" do + setup do + @user = create(:builder_user, name: "sakuya") + as (@user) do + @forum_topic = create(:forum_topic, title: "Touhou BUR") + @forum_post = create(:forum_post, topic: @forum_topic, body: "because") + end + @antecedent_tag = create(:copyright_tag, name: "touhou", post_count: 1000) + @consequent_tag = create(:copyright_tag, name: "touhou_project", post_count: 10) + @antecedent_wiki = create(:wiki_page, title: "touhou", body: "zun project") + @consequent_wiki = create(:wiki_page, title: "touhou_project") + + @other_alias = create(:tag_alias, antecedent_name: "touhou", consequent_name: "touhou_project", creator: @user, status: "pending", forum_topic: @forum_topic, forum_post: @forum_post) + @unrelated_alias = create(:tag_alias) + end + + should "render" do get tag_aliases_path assert_response :success end - should "list all tag_alias (with search)" do - get tag_aliases_path, params: {:search => {:antecedent_name => "aaa"}} - assert_response :success + should respond_to_search({}).with { [@unrelated_alias, @other_alias, @tag_alias] } + should respond_to_search(antecedent_name: "aaa").with { @tag_alias } + should respond_to_search(consequent_name: "bbb").with { @tag_alias } + should respond_to_search(status: "pending").with { @other_alias } + + context "using includes" do + should respond_to_search(antecedent_tag: {post_count: 1000}).with { @other_alias } + should respond_to_search(consequent_tag: {category: Tag.categories.copyright}).with { @other_alias } + should respond_to_search(has_antecedent_tag: "true").with { @other_alias } + should respond_to_search(has_consequent_tag: "false").with { [@unrelated_alias, @tag_alias] } + should respond_to_search(antecedent_wiki: {body_matches: "zun project"}).with { @other_alias } + should respond_to_search(has_consequent_wiki: "true").with { @other_alias } + should respond_to_search(forum_topic: {title_matches: "Touhou BUR"}).with { @other_alias } + should respond_to_search(forum_post: {body: "because"}).with { @other_alias } + should respond_to_search(creator_name: "sakuya").with { @other_alias } + should respond_to_search(creator: {level: User::Levels::BUILDER}).with { @other_alias } end end diff --git a/test/functional/tag_implications_controller_test.rb b/test/functional/tag_implications_controller_test.rb index c43858be3..f7f9b4187 100644 --- a/test/functional/tag_implications_controller_test.rb +++ b/test/functional/tag_implications_controller_test.rb @@ -7,6 +7,44 @@ class TagImplicationsControllerTest < ActionDispatch::IntegrationTest end context "index action" do + setup do + @user = create(:builder_user, name: "sakuya") + as (@user) do + @forum_topic = create(:forum_topic, title: "Weapon BUR") + @forum_post = create(:forum_post, topic: @forum_topic, body: "because") + end + @antecedent_tag = create(:copyright_tag, name: "cannon", post_count: 10) + @consequent_tag = create(:copyright_tag, name: "weapon", post_count: 1000) + @antecedent_wiki = create(:wiki_page, title: "cannon", body: "made of fun") + @consequent_wiki = create(:wiki_page, title: "weapon") + + @other_implication = create(:tag_implication, antecedent_name: "cannon", consequent_name: "weapon", creator: @user, status: "pending", forum_topic: @forum_topic, forum_post: @forum_post) + @unrelated_implication = create(:tag_implication) + end + + should "render" do + get tag_implications_path + assert_response :success + end + + should respond_to_search({}).with { [@unrelated_implication, @other_implication, @tag_implication] } + should respond_to_search(antecedent_name: "aaa").with { @tag_implication } + should respond_to_search(consequent_name: "bbb").with { @tag_implication } + should respond_to_search(status: "pending").with { @other_implication } + + context "using includes" do + should respond_to_search(antecedent_tag: {post_count: 10}).with { @other_implication } + should respond_to_search(consequent_tag: {category: Tag.categories.copyright}).with { @other_implication } + should respond_to_search(has_antecedent_tag: "true").with { @other_implication } + should respond_to_search(has_consequent_tag: "false").with { [@unrelated_implication, @tag_implication] } + should respond_to_search(antecedent_wiki: {body_matches: "made of fun"}).with { @other_implication } + should respond_to_search(has_consequent_wiki: "true").with { @other_implication } + should respond_to_search(forum_topic: {title_matches: "Weapon BUR"}).with { @other_implication } + should respond_to_search(forum_post: {body: "because"}).with { @other_implication } + should respond_to_search(creator_name: "sakuya").with { @other_implication } + should respond_to_search(creator: {level: User::Levels::BUILDER}).with { @other_implication } + end + should "list all tag implications" do get tag_implications_path assert_response :success diff --git a/test/functional/tags_controller_test.rb b/test/functional/tags_controller_test.rb index 91eea376d..56dead38c 100644 --- a/test/functional/tags_controller_test.rb +++ b/test/functional/tags_controller_test.rb @@ -36,27 +36,43 @@ class TagsControllerTest < ActionDispatch::IntegrationTest context "searching" do setup do as(@user) do - @miku = create(:tag, name: "hatsune_miku", category: Tag.categories.character) - @wokada = create(:tag, name: "wokada", category: Tag.categories.artist) - @vocaloid = create(:tag, name: "vocaloid", category: Tag.categories.copyright) + @miku = create(:character_tag, name: "hatsune_miku") + @wokada = create(:artist_tag, name: "wokada") + @vocaloid = create(:copyright_tag, name: "vocaloid") + @weapon = create(:tag, name: "weapon") @empty = create(:tag, name: "empty", post_count: 0) create(:tag_alias, antecedent_name: "miku", consequent_name: "hatsune_miku") - create(:wiki_page, title: "hatsune_miku") + create(:tag_implication, antecedent_name: "axe", consequent_name: "weapon") + create(:wiki_page, title: "hatsune_miku", body: "[[vocaloid]]") create(:artist, name: "wokada") end end + should "render" do + get tags_path + assert_response :success + end + + should respond_to_search({}).with { [@weapon, @vocaloid, @wokada, @miku, @tag] } should respond_to_search(name_matches: "hatsune_miku").with { @miku } should respond_to_search(name_normalize: "HATSUNE_MIKU ").with { @miku } should respond_to_search(name_or_alias_matches: "miku").with { @miku } should respond_to_search(fuzzy_name_matches: "miku_hatsune", order: "similarity").with { @miku } should respond_to_search(name: "empty", hide_empty: "true").with { [] } should respond_to_search(name: "empty", hide_empty: "false").with { [@empty] } - should respond_to_search(name: "wokada", has_artist: "true").with { @wokada } - should respond_to_search(name: "hatsune_miku", has_artist: "false").with { @miku } - should respond_to_search(name: "hatsune_miku", has_wiki: "true").with { @miku } - should respond_to_search(name: "vocaloid", has_wiki: "false").with { @vocaloid } + + context "using includes" do + should respond_to_search(name: "wokada", has_artist: "true").with { @wokada } + should respond_to_search(name: "hatsune_miku", has_artist: "false").with { @miku } + should respond_to_search(name: "hatsune_miku", has_wiki_page: "true").with { @miku } + should respond_to_search(name: "vocaloid", has_wiki_page: "false").with { @vocaloid } + should respond_to_search(consequent_aliases: {antecedent_name: "miku"}).with { @miku } + should respond_to_search(consequent_implications: {antecedent_name: "axe"}).with { @weapon } + should respond_to_search(wiki_page: {body_matches: "*vocaloid*"}).with { @miku } + should respond_to_search(artist: {is_banned: "false"}).with { @wokada } + should respond_to_search(has_dtext_links: "true").with { @vocaloid } + end end end diff --git a/test/functional/uploads_controller_test.rb b/test/functional/uploads_controller_test.rb index e5fcc445c..17bbb071d 100644 --- a/test/functional/uploads_controller_test.rb +++ b/test/functional/uploads_controller_test.rb @@ -30,7 +30,7 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest context "The uploads controller" do setup do - @user = create(:contributor_user) + @user = create(:contributor_user, name: "marisa") mock_iqdb_service! end @@ -173,8 +173,11 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest context "index action" do setup do as(@user) do - @upload = create(:source_upload, tag_string: "foo bar") - @upload2 = create(:source_upload, tag_string: "tagme", rating: "e") + @upload = create(:upload, tag_string: "foo bar", source: "http://example.com/foobar") + @post_upload = create(:source_upload, status: "completed", post: build(:post, tag_string: "touhou"), rating: "e") + end + as(create(:user)) do + @upload3 = create(:upload) end end @@ -183,23 +186,28 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest assert_response :success end - context "with search parameters" do - should "render" do - search_params = { - uploader_name: @upload.uploader.name, - source_matches: @upload.source, - rating: @upload.rating, - status: @upload.status, - server: @upload.server - } - - get_auth uploads_path, @user, params: { search: search_params } - assert_response :success - - get_auth uploads_path(format: :json), @user, params: { search: search_params } - assert_response :success - assert_equal(@upload.id, response.parsed_body.first["id"]) + context "as an uploader" do + setup do + CurrentUser.user = @user end + + should respond_to_search({}).with { [@post_upload, @upload] } + should respond_to_search(source: "http://example.com/foobar").with { @upload } + should respond_to_search(rating: "e").with { @post_upload } + should respond_to_search(tag_string: "*foo*").with { @upload } + + context "using includes" do + should respond_to_search(post_tags_match: "touhou").with { @post_upload } + should respond_to_search(uploader: {name: "marisa"}).with { [@post_upload, @upload] } + end + end + + context "as an admin" do + setup do + CurrentUser.user = create(:admin_user) + end + + should respond_to_search({}).with { [@upload3, @post_upload, @upload] } end end diff --git a/test/functional/user_feedbacks_controller_test.rb b/test/functional/user_feedbacks_controller_test.rb index 4c88f6f24..012f2be58 100644 --- a/test/functional/user_feedbacks_controller_test.rb +++ b/test/functional/user_feedbacks_controller_test.rb @@ -3,9 +3,9 @@ require 'test_helper' class UserFeedbacksControllerTest < ActionDispatch::IntegrationTest context "The user feedbacks controller" do setup do - @user = create(:user) - @critic = create(:gold_user) - @mod = create(:moderator_user) + @user = create(:user, name: "cirno") + @critic = create(:gold_user, name: "eiki") + @mod = create(:moderator_user, id: 1000) @user_feedback = create(:user_feedback, user: @user, creator: @critic) end @@ -37,23 +37,43 @@ class UserFeedbacksControllerTest < ActionDispatch::IntegrationTest end context "index action" do + setup do + @other_feedback = create(:user_feedback, user: @user, creator: @mod, body: "blah", category: "neutral") + @unrelated_feedback = create(:user_feedback, is_deleted: true) + end + should "render" do get_auth user_feedbacks_path, @user assert_response :success end - should "not allow members to see deleted feedbacks" do - as(@user) { @user_feedback.update!(is_deleted: true) } - get_auth user_feedbacks_path, @user + context "as a user" do + setup do + CurrentUser.user = @user + end - assert_response :success - assert_select "tr#user-feedback-#{@user_feedback.id}", false + should respond_to_search({}).with { [@other_feedback, @user_feedback] } + should respond_to_search(body_matches: "blah").with { @other_feedback } + should respond_to_search(category: "positive").with { @user_feedback } + should respond_to_search(is_deleted: "true").with { [] } + + context "using includes" do + should respond_to_search(creator_name: "eiki").with { @user_feedback } + should respond_to_search(creator_id: 1000).with { @other_feedback } + should respond_to_search(creator: {level: User::Levels::GOLD}).with { @user_feedback } + end end - context "with search parameters" do - should "render" do - get_auth user_feedbacks_path, @critic, params: {:search => {:user_id => @user.id}} - assert_response :success + context "as a moderator" do + setup do + CurrentUser.user = @mod + end + + should respond_to_search({}).with { [@unrelated_feedback, @other_feedback, @user_feedback] } + should respond_to_search(is_deleted: "true").with { @unrelated_feedback } + + context "using includes" do + should respond_to_search(user_name: "cirno").with { [@other_feedback, @user_feedback] } end end end diff --git a/test/functional/users_controller_test.rb b/test/functional/users_controller_test.rb index c342a98a0..694c38fe7 100644 --- a/test/functional/users_controller_test.rb +++ b/test/functional/users_controller_test.rb @@ -7,7 +7,14 @@ class UsersControllerTest < ActionDispatch::IntegrationTest end context "index action" do - should "list all users" do + setup do + @first_user = User.find(1) + @mod_user = create(:moderator_user, name: "yukari") + @other_user = create(:builder_user, can_upload_free: true, inviter: @mod_user, created_at: 2.weeks.ago) + @uploader = create(:user, created_at: 2.weeks.ago) + end + + should "render" do get users_path assert_response :success end @@ -28,14 +35,54 @@ class UsersControllerTest < ActionDispatch::IntegrationTest assert_response 404 end - should "list all users (with search)" do - get users_path, params: {:search => {:name_matches => @user.name}} - assert_response :success - end + should respond_to_search({}).with { [@uploader, @other_user, @mod_user, @user, @first_user] } + should respond_to_search(min_level: User::Levels::BUILDER).with { [@other_user, @mod_user, @first_user] } + should respond_to_search(can_upload_free: "true").with { @other_user } + should respond_to_search(name_matches: "yukari").with { @mod_user } - should "list all users (with blank search parameters)" do - get users_path, params: { search: { inviter: { name_matches: "" }, level: "", name: "test" } } - assert_redirected_to users_path(search: { name: "test" }) + context "using includes" do + setup do + as (@uploader) { @post = create(:post, tag_string: "touhou", uploader: @uploader, is_flagged: true) } + as (@user) do + create(:note, post: @post) + create(:artist_commentary, post: @post) + create(:artist) + create(:wiki_page) + @forum = create(:forum_post, creator: @user, topic: build(:forum_topic, creator: @user)) + end + as (@other_user) do + @other_post = create(:post, rating: "e", uploader: @other_user) + create(:post_appeal, creator: @other_user, post: @post) + create(:comment, creator: @other_user, post: @other_post) + create(:forum_post_vote, creator: @other_user, forum_post: @forum) + create(:tag_alias, creator: @other_user) + create(:tag_implication, creator: @other_user) + end + as (@mod_user) do + create(:post_approval, user: @mod_user, post: @post) + create(:user_feedback, user: @other_user, creator: @mod_user) + create(:ban, user: @other_user, banner: @mod_user) + end + end + + should respond_to_search(has_artist_versions: "true").with { @user } + should respond_to_search(has_wiki_page_versions: "true").with { @user } + should respond_to_search(has_forum_topics: "true").with { @user } + should respond_to_search(has_forum_posts: "true").with { @user } + should respond_to_search(has_forum_post_votes: "true").with { @other_user } + should respond_to_search(has_feedback: "true").with { @other_user } + should respond_to_search(has_tag_aliases: "true").with { @other_user } + should respond_to_search(has_tag_implications: "true").with { @other_user } + should respond_to_search(has_bans: "true").with { @other_user } + should respond_to_search(has_artist_commentary_versions: "true").with { @user } + should respond_to_search(has_comments: "true").with { @other_user } + should respond_to_search(has_note_versions: "true").with { @user } + should respond_to_search(has_post_appeals: "true").with { @other_user } + should respond_to_search(has_post_approvals: "true").with { @mod_user } + should respond_to_search(has_posts: "true").with { [@uploader, @other_user] } + should respond_to_search(posts_tags_match: "touhou").with { @uploader } + should respond_to_search(posts: {rating: "e"}).with { @other_user } + should respond_to_search(inviter: {name: "yukari"}).with { @other_user } end end diff --git a/test/functional/wiki_page_versions_controller_test.rb b/test/functional/wiki_page_versions_controller_test.rb index 110021e59..ad897b10c 100644 --- a/test/functional/wiki_page_versions_controller_test.rb +++ b/test/functional/wiki_page_versions_controller_test.rb @@ -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 diff --git a/test/functional/wiki_pages_controller_test.rb b/test/functional/wiki_pages_controller_test.rb index 713b28e1e..5a4ad9c2b 100644 --- a/test/functional/wiki_pages_controller_test.rb +++ b/test/functional/wiki_pages_controller_test.rb @@ -14,11 +14,13 @@ class WikiPagesControllerTest < ActionDispatch::IntegrationTest @deleted = create(:wiki_page, title: "deleted", is_deleted: true) @vocaloid = create(:wiki_page, title: "vocaloid") @miku = create(:wiki_page, title: "hatsune_miku", other_names: ["初音ミク"], body: "miku is a [[vocaloid]]") - create(:tag, name: "hatsune_miku", category: Tag.categories.character) + @picasso = create(:wiki_page, title: "picasso") + create(:artist, name: "picasso", is_banned: true) + create(:character_tag, name: "hatsune_miku") end end - should "list all wiki_pages" do + should "render" do get wiki_pages_path assert_response :success end @@ -34,19 +36,27 @@ class WikiPagesControllerTest < ActionDispatch::IntegrationTest assert_redirected_to wiki_pages_path(search: { title_normalize: "tagme" }, redirect: true) end + should respond_to_search({}).with { [@picasso, @miku, @vocaloid, @deleted, @tagme] } should respond_to_search(title: "tagme").with { @tagme } should respond_to_search(title: "tagme", order: "post_count").with { @tagme } should respond_to_search(title_normalize: "TAGME ").with { @tagme } - should respond_to_search(tag: { category: Tag.categories.character }).with { @miku } - should respond_to_search(hide_deleted: "true").with { [@miku, @vocaloid, @tagme] } + should respond_to_search(hide_deleted: "true").with { [@picasso, @miku, @vocaloid, @tagme] } should respond_to_search(linked_to: "vocaloid").with { @miku } - should respond_to_search(not_linked_to: "vocaloid").with { [@vocaloid, @deleted, @tagme] } + should respond_to_search(not_linked_to: "vocaloid").with { [@picasso, @vocaloid, @deleted, @tagme] } should respond_to_search(other_names_match: "初音ミク").with { @miku } should respond_to_search(other_names_match: "初*").with { @miku } should respond_to_search(other_names_present: "true").with { @miku } - should respond_to_search(other_names_present: "false").with { [@vocaloid, @deleted, @tagme] } + should respond_to_search(other_names_present: "false").with { [@picasso, @vocaloid, @deleted, @tagme] } + + context "using includes" do + should respond_to_search(has_tag: "true").with { @miku } + should respond_to_search(tag: { category: Tag.categories.character }).with { @miku } + should respond_to_search(has_dtext_links: "true").with { @miku } + should respond_to_search(has_artist: "true").with { @picasso } + should respond_to_search(artist: {is_banned: "true"}).with { @picasso } + end end context "search action" do