diff --git a/app/controllers/artists_controller.rb b/app/controllers/artists_controller.rb index 41f871aad..a85c7d992 100644 --- a/app/controllers/artists_controller.rb +++ b/app/controllers/artists_controller.rb @@ -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 diff --git a/test/functional/artists_controller_test.rb b/test/functional/artists_controller_test.rb index 386e9cb9a..7da27b5be 100644 --- a/test/functional/artists_controller_test.rb +++ b/test/functional/artists_controller_test.rb @@ -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 diff --git a/test/functional/favorites_controller_test.rb b/test/functional/favorites_controller_test.rb index 00f7b339c..3c576f733 100644 --- a/test/functional/favorites_controller_test.rb +++ b/test/functional/favorites_controller_test.rb @@ -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 diff --git a/test/functional/post_appeals_controller_test.rb b/test/functional/post_appeals_controller_test.rb index b3e0429a2..e14277105 100644 --- a/test/functional/post_appeals_controller_test.rb +++ b/test/functional/post_appeals_controller_test.rb @@ -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}} diff --git a/test/functional/post_flags_controller_test.rb b/test/functional/post_flags_controller_test.rb index 8f24aea45..a4766c54f 100644 --- a/test/functional/post_flags_controller_test.rb +++ b/test/functional/post_flags_controller_test.rb @@ -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 diff --git a/test/functional/posts_controller_test.rb b/test/functional/posts_controller_test.rb index be346c32a..83bd9967e 100644 --- a/test/functional/posts_controller_test.rb +++ b/test/functional/posts_controller_test.rb @@ -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 diff --git a/test/functional/users_controller_test.rb b/test/functional/users_controller_test.rb index ed03c3838..4fd277963 100644 --- a/test/functional/users_controller_test.rb +++ b/test/functional/users_controller_test.rb @@ -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. diff --git a/test/functional/wiki_pages_controller_test.rb b/test/functional/wiki_pages_controller_test.rb index de2a1ea04..0eafc7d4d 100644 --- a/test/functional/wiki_pages_controller_test.rb +++ b/test/functional/wiki_pages_controller_test.rb @@ -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 diff --git a/test/unit/user_mailer_test.rb b/test/unit/user_mailer_test.rb new file mode 100644 index 000000000..7b96b86c4 --- /dev/null +++ b/test/unit/user_mailer_test.rb @@ -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