tests: add more controller tests.

* Fix an exception in /artists/show_or_new.
This commit is contained in:
evazion
2020-03-31 17:46:45 -05:00
parent a272453bd0
commit e0a72ef135
9 changed files with 131 additions and 1 deletions

View File

@@ -73,7 +73,7 @@ class ArtistsController < ApplicationController
@artist = Artist.find_by_name(params[:name])
if params[:name].blank?
redirect_to new_artist_path(artist_params(:new))
redirect_to new_artist_path(permitted_attributes(Artist))
elsif @artist.present?
redirect_to artist_path(@artist)
else

View File

@@ -73,6 +73,11 @@ class ArtistsControllerTest < ActionDispatch::IntegrationTest
get_auth show_or_new_artists_path(name: "nobody"), @user
assert_response :success
end
should "redirect to the new artist page for a blank artist" do
get_auth show_or_new_artists_path, @user
assert_redirected_to new_artist_path
end
end
context "edit action" do

View File

@@ -24,6 +24,11 @@ class FavoritesControllerTest < ActionDispatch::IntegrationTest
get favorites_path
assert_redirected_to posts_path(format: "html")
end
should "render for json" do
get favorites_path, as: :json
assert_response :success
end
end
context "create action" do

View File

@@ -34,6 +34,11 @@ class PostAppealsControllerTest < ActionDispatch::IntegrationTest
assert_response :success
end
should "render for json" do
get post_appeals_path, as: :json
assert_response :success
end
context "with search parameters" do
should "render" do
get_auth post_appeals_path, @user, params: {:search => {:post_id => @post_appeal.post_id}}

View File

@@ -31,6 +31,11 @@ class PostFlagsControllerTest < ActionDispatch::IntegrationTest
assert_response :success
end
should "render for json" do
get post_flags_path, as: :json
assert_response :success
end
should "hide flagger names from regular users" do
get_auth post_flags_path, @user
assert_response :success

View File

@@ -58,6 +58,18 @@ class PostsControllerTest < ActionDispatch::IntegrationTest
get posts_path, params: { tags: "bkub" }
assert_response :success
end
should "render for a wildcard tag search" do
create(:post, tag_string: "1girl solo")
get posts_path(tags: "*girl*")
assert_response :success
end
should "render for a search:all search" do
create(:saved_search, user: @user)
get posts_path(tags: "search:all")
assert_response :success
end
end
context "with a multi-tag search" do
@@ -137,6 +149,43 @@ class PostsControllerTest < ActionDispatch::IntegrationTest
assert_select "entry", 0
end
end
context "with deleted posts" do
setup do
@post.update!(is_deleted: true)
end
should "not show deleted posts normally" do
get posts_path
assert_response :success
assert_select "#post_#{@post.id}", 0
end
should "show deleted posts when searching for status:deleted" do
get posts_path(tags: "status:deleted")
assert_response :success
assert_select "#post_#{@post.id}", 1
end
end
context "with restricted posts" do
setup do
Danbooru.config.stubs(:restricted_tags).returns(["tagme"])
as(@user) { @post.update!(tag_string: "tagme") }
end
should "not show restricted posts if user doesn't have permission" do
get posts_path
assert_response :success
assert_select "#post_#{@post.id}", 0
end
should "show restricted posts if user has permission" do
get_auth posts_path, create(:gold_user)
assert_response :success
assert_select "#post_#{@post.id}", 1
end
end
end
context "show_seq action" do
@@ -170,6 +219,11 @@ class PostsControllerTest < ActionDispatch::IntegrationTest
@builder = create(:builder_user, can_approve_posts: true)
as(@user) do
@post.update!(tag_string: "1girl solo highres blah 2001")
Tag.find_by_name("1girl").update(post_count: 20_000)
Tag.find_by_name("solo").update(post_count: 2_000)
Tag.find_by_name("blah").update(post_count: 1)
@pool = create(:pool)
@pool.add!(@post)
@@ -208,6 +262,11 @@ class PostsControllerTest < ActionDispatch::IntegrationTest
get_auth post_path(@post), @admin
assert_response :success
end
should "render for a builder with a search query" do
get_auth post_path(@post, q: "tagme"), @builder
assert_response :success
end
end
context "with pools" do

View File

@@ -33,6 +33,14 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
end
end
context "custom_style action" do
should "work" do
@user.update!(custom_style: "span { color: red; }")
get_auth custom_style_users_path(format: "css"), @user
assert_response :success
end
end
context "show action" do
setup do
# flesh out profile to get more test coverage of user presenter.

View File

@@ -129,6 +129,11 @@ class WikiPagesControllerTest < ActionDispatch::IntegrationTest
get show_or_new_wiki_pages_path, params: { title: "what" }
assert_redirected_to wiki_page_path("what")
end
should "redirect when given a blank title" do
get show_or_new_wiki_pages_path
assert_redirected_to new_wiki_page_path
end
end
context "new action" do

View File

@@ -0,0 +1,38 @@
require "test_helper"
class UserMailerTest < ActionMailer::TestCase
context "UserMailer" do
setup do
@user = create(:user, email_address: build(:email_address))
end
context "dmail_notice method" do
should "work" do
@dmail = create(:dmail, owner: @user, to: @user)
mail = UserMailer.dmail_notice(@dmail)
assert_emails(1) { mail.deliver_now }
end
end
context "password_reset method" do
should "work" do
mail = UserMailer.password_reset(@user)
assert_emails(1) { mail.deliver_now }
end
end
context "email_change_confirmation method" do
should "work" do
mail = UserMailer.email_change_confirmation(@user)
assert_emails(1) { mail.deliver_now }
end
end
context "welcome_user method" do
should "work" do
mail = UserMailer.welcome_user(@user)
assert_emails(1) { mail.deliver_now }
end
end
end
end