tests: add missing controller tests.

This commit is contained in:
evazion
2020-03-30 12:36:06 -05:00
parent 83c2abf1ae
commit 4e2fd82ef6
19 changed files with 227 additions and 14 deletions

View File

@@ -1,3 +1,6 @@
FactoryBot.define do
factory(:forum_topic_visit)
factory(:forum_topic_visit) do
user
forum_topic
end
end

View File

@@ -0,0 +1,12 @@
FactoryBot.define do
factory(:pixiv_ugoira_frame_data) do
post
content_type { "image/jpeg" }
data do
[
{ "file" => "000000.jpg", "delay" => 200 },
{ "file" => "000001.jpg", "delay" => 200 },
]
end
end
end

View File

@@ -1,7 +1,7 @@
FactoryBot.define do
factory(:post_appeal) do
creator
post
post { build(:post, is_deleted: true) }
reason {"xxx"}
end
end

View File

@@ -10,7 +10,14 @@ class BulkUpdateRequestsControllerTest < ActionDispatch::IntegrationTest
context "#new" do
should "render" do
get_auth bulk_update_requests_path, @user
get_auth new_bulk_update_request_path, @user
assert_response :success
end
end
context "#edit" do
should "render" do
get_auth edit_bulk_update_request_path(@bulk_update_request), @user
assert_response :success
end
end

View File

@@ -2,12 +2,44 @@ require 'test_helper'
class DelayedJobsControllerTest < ActionDispatch::IntegrationTest
context "The delayed jobs controller" do
setup do
@user = create(:admin_user)
@job = create(:delayed_job)
end
context "index action" do
should "render" do
create(:delayed_job)
get delayed_jobs_path
assert_response :success
end
end
context "cancel action" do
should "work" do
put_auth cancel_delayed_job_path(@job), @user, xhr: true
assert_response :success
end
end
context "retry action" do
should "work" do
put_auth retry_delayed_job_path(@job), @user, xhr: true
assert_response :success
end
end
context "run action" do
should "work" do
put_auth run_delayed_job_path(@job), @user, xhr: true
assert_response :success
end
end
context "destroy action" do
should "work" do
delete_auth delayed_job_path(@job), @user, xhr: true
assert_response :success
end
end
end
end

View File

@@ -0,0 +1,12 @@
require "test_helper"
class DtextLinksControllerTest < ActionDispatch::IntegrationTest
context "index action" do
should "work" do
@user = create(:user)
@wiki = as(@user) { create(:wiki_page, body: "[[test]]") }
get dtext_links_path
assert_response :success
end
end
end

View File

@@ -4,10 +4,7 @@ module Explore
class PostsControllerTest < ActionDispatch::IntegrationTest
context "in all cases" do
setup do
@user = create(:user)
as_user do
create(:post)
end
@post = create(:post)
end
context "#popular" do
@@ -17,6 +14,15 @@ module Explore
end
end
context "#curated" do
should "render" do
@builder = create(:builder_user)
@post.add_favorite!(@builder)
get curated_explore_posts_path
assert_response :success
end
end
context "#searches" do
should "render" do
get searches_explore_posts_path

View File

@@ -0,0 +1,13 @@
require "test_helper"
class ForumTopicVisitsControllerTest < ActionDispatch::IntegrationTest
context "index action" do
should "work for json responses" do
@user = create(:user)
@visit = as(@user) { create(:forum_topic_visit, user: @user) }
get_auth forum_topic_visits_path, @user, as: :json
assert_response :success
end
end
end

View File

@@ -40,5 +40,17 @@ class IpAddressesControllerTest < ActionDispatch::IntegrationTest
assert_response 403
end
end
context "show action" do
should "be visible to mods" do
get_auth ip_address_path("1.1.1.1"), @mod
assert_response :success
end
should "not be visible to members" do
get_auth ip_address_path("1.1.1.1"), @user
assert_response 403
end
end
end
end

View File

@@ -2,11 +2,22 @@ require 'test_helper'
class ModActionsControllerTest < ActionDispatch::IntegrationTest
context "The mod actions controller" do
setup do
@mod_action = create(:mod_action)
end
context "index action" do
should "work" do
get mod_actions_path
assert_response :success
end
end
context "show action" do
should "work" do
get mod_action_path(@mod_action)
assert_redirected_to mod_actions_path(search: { id: @mod_action.id })
end
end
end
end

View File

@@ -0,0 +1,11 @@
require "test_helper"
class PixivUgoiraFrameDataControllerTest < ActionDispatch::IntegrationTest
context "index action" do
should "work" do
create(:pixiv_ugoira_frame_data)
get pixiv_ugoira_frame_data_path, as: :json
assert_response :success
end
end
end

View File

@@ -13,6 +13,14 @@ class PostAppealsControllerTest < ActionDispatch::IntegrationTest
end
end
context "show action" do
should "render" do
@appeal = create(:post_appeal)
get post_appeal_path(@appeal)
assert_redirected_to post_appeals_path(search: { id: @appeal.id })
end
end
context "index action" do
setup do
as_user do

View File

@@ -0,0 +1,10 @@
require "test_helper"
class RobotsControllerTest < ActionDispatch::IntegrationTest
context "index action" do
should "work" do
get robots_path(format: :text)
assert_response :success
end
end
end

View File

@@ -0,0 +1,65 @@
require "test_helper"
class StaticControllerTest < ActionDispatch::IntegrationTest
context "site_map action" do
should "work for anonymous users" do
get site_map_path
assert_response :success
end
should "work for admin users" do
get_auth site_map_path, create(:admin_user)
assert_response :success
end
end
context "sitemap action" do
should "work" do
create_list(:post, 3)
get sitemap_path, as: :xml
assert_response :success
end
end
context "dtext_help action" do
should "work" do
get dtext_help_path(format: :js), xhr: true
assert_response :success
end
end
context "terms_of_service action" do
should "work" do
get terms_of_service_path
assert_response :success
end
end
context "not_found action" do
should "work" do
get "/qwoiqogieqg"
assert_response 404
end
end
context "bookmarklet action" do
should "work" do
get bookmarklet_path
assert_response :success
end
end
context "contact action" do
should "work" do
get contact_path
assert_response :success
end
end
context "keyboard_shortcuts action" do
should "work" do
get keyboard_shortcuts_path
assert_response :success
end
end
end

View File

@@ -18,6 +18,13 @@ class TagAliasesControllerTest < ActionDispatch::IntegrationTest
end
end
context "show action" do
should "work" do
get tag_alias_path(@tag_alias)
assert_response :success
end
end
context "destroy action" do
should "allow admins to delete aliases" do
delete_auth tag_alias_path(@tag_alias), create(:admin_user)

View File

@@ -18,6 +18,13 @@ class TagImplicationsControllerTest < ActionDispatch::IntegrationTest
end
end
context "show action" do
should "work" do
get tag_implication_path(@tag_implication)
assert_response :success
end
end
context "destroy action" do
should "allow admins to delete implications" do
delete_auth tag_implication_path(@tag_implication), create(:admin_user)

View File

@@ -11,7 +11,7 @@ class TagsControllerTest < ActionDispatch::IntegrationTest
context "edit action" do
should "render" do
get_auth tag_path(@tag), @user, params: {:id => @tag.id}
get_auth edit_tag_path(@tag), @user
assert_response :success
end
end

View File

@@ -140,11 +140,8 @@ class WikiPagesControllerTest < ActionDispatch::IntegrationTest
context "edit action" do
should "render" do
as_user do
@wiki_page = create(:wiki_page)
end
get_auth wiki_page_path(@wiki_page), @mod
@wiki_page = as(@user) { create(:wiki_page) }
get_auth edit_wiki_page_path(@wiki_page), @user
assert_response :success
end
end