Merge branch 'master' into attribute-searching

This commit is contained in:
evazion
2020-08-17 14:23:00 -05:00
committed by GitHub
155 changed files with 2834 additions and 2169 deletions

View File

@@ -57,6 +57,7 @@ class BansControllerTest < ActionDispatch::IntegrationTest
context "create action" do
should "allow mods to ban members" do
assert_difference("Ban.count", 1) do
@user = create(:user)
post_auth bans_path, @mod, params: { ban: { duration: 60, reason: "xxx", user_id: @user.id }}
assert_redirected_to bans_path
@@ -85,12 +86,20 @@ class BansControllerTest < ActionDispatch::IntegrationTest
should "not allow regular users to ban anyone" do
assert_difference("Ban.count", 0) do
@user = create(:user)
post_auth bans_path, @user, params: { ban: { duration: 60, reason: "xxx", user_id: @mod.id }}
assert_response 403
assert_equal(false, @mod.reload.is_banned?)
end
end
should "not allow users to be double banned" do
assert_difference("Ban.count", 0) do
post_auth bans_path, @mod, params: { ban: { duration: 60, reason: "xxx", user_id: @ban.user.id }}
assert_response :success
end
end
end
context "update action" do

View File

@@ -7,6 +7,7 @@ class EmailsControllerTest < ActionDispatch::IntegrationTest
setup do
@user = create(:user, email_address: build(:email_address, { address: "bob@ogres.net", is_verified: false }))
@other_user = create(:user, email_address: build(:email_address, { address: "alice@ogres.net", is_verified: false }))
@restricted_user = create(:user, requires_verification: true, is_verified: false)
end
context "#show" do
@@ -22,9 +23,38 @@ class EmailsControllerTest < ActionDispatch::IntegrationTest
end
context "#edit" do
should "render" do
get_auth edit_user_email_path(@user), @user
assert_response :success
context "for a user with an email address" do
should "render" do
get_auth edit_user_email_path(@user), @user
assert_equal true, @user.email_address.present?
assert_response :success
end
end
context "for a user without an email address" do
should "render" do
@user.email_address.destroy!
@user.reload_email_address
get_auth edit_user_email_path(@user), @user
assert_equal false, @user.email_address.present?
assert_response :success
assert_select "h1", text: "Add Email"
end
end
context "for a restricted user" do
should "render" do
get_auth edit_user_email_path(@restricted_user), @restricted_user
assert_response :success
end
end
context "for an unauthorized user" do
should "render" do
get_auth edit_user_email_path(@user), @other_user
assert_response 403
end
end
end
@@ -109,6 +139,48 @@ class EmailsControllerTest < ActionDispatch::IntegrationTest
assert_equal(false, @user.is_verified)
end
end
context "for a user without an email address" do
should "redirect to the add email page" do
@user.email_address.destroy!
get_auth verify_user_email_path(@user), @user
assert_redirected_to edit_user_email_path(@user)
end
end
context "for a user with an unverified email address" do
should "show the resend confirmation email page" do
get_auth verify_user_email_path(@user), @user
assert_response :success
end
end
context "for an unauthorized user" do
should "fail" do
get_auth verify_user_email_path(@user), @other_user
assert_response 403
end
end
end
context "#send_confirmation" do
context "for an authorized user" do
should "resend the confirmation email" do
post_auth send_confirmation_user_email_path(@user), @user
assert_redirected_to @user
assert_enqueued_emails 1
end
end
context "for an unauthorized user" do
should "fail" do
post_auth send_confirmation_user_email_path(@user), @other_user
assert_response 403
assert_no_enqueued_emails
end
end
end
end
end

View File

@@ -8,11 +8,11 @@ class ModActionsControllerTest < ActionDispatch::IntegrationTest
context "index action" do
setup do
@promote_action = create(:mod_action, category: "user_level_change", creator: build(:builder_user, name: "rumia"))
@unrelated_action = create(:mod_action)
@ban = create(:mod_action, category: :post_ban)
@unban = create(:mod_action, category: :post_unban)
end
should "render" do
should "work" do
get mod_actions_path
assert_response :success
end
@@ -25,10 +25,24 @@ class ModActionsControllerTest < ActionDispatch::IntegrationTest
should respond_to_search(creator_name: "rumia").with { @promote_action }
should respond_to_search(creator: {level: User::Levels::BUILDER}).with { @promote_action }
end
context "category enum searches" do
should respond_to_search(category: "post_ban").with { [@ban] }
should respond_to_search(category: "post_unban").with { [@unban] }
should respond_to_search(category: "Post_ban").with { [@ban] }
should respond_to_search(category: "post_ban post_unban").with { [@unban, @ban] }
should respond_to_search(category: "post_ban,post_unban").with { [@unban, @ban] }
should respond_to_search(category: "44").with { [@ban] }
should respond_to_search(category_id: "44").with { [@ban] }
should respond_to_search(category_id: "44,45").with { [@unban, @ban] }
should respond_to_search(category_id: ">=44").with { [@unban, @ban] }
end
end
context "show action" do
should "work" do
@mod_action = create(:mod_action)
get mod_action_path(@mod_action)
assert_redirected_to mod_actions_path(search: { id: @mod_action.id })
end

View File

@@ -15,26 +15,6 @@ module Moderator
end
end
context "confirm_delete action" do
should "render" do
get_auth confirm_delete_moderator_post_post_path(@post), @admin
assert_response :success
end
end
context "delete action" do
should "render" do
post_auth delete_moderator_post_post_path(@post), @admin, params: {:reason => "xxx", :format => "js", :commit => "Delete"}
assert(@post.reload.is_deleted?)
end
should "work even if the deleter has flagged the post previously" do
create(:post_flag, post: @post, creator: @admin)
post_auth delete_moderator_post_post_path(@post), @admin, params: {:reason => "xxx", :format => "js", :commit => "Delete"}
assert(@post.reload.is_deleted?)
end
end
context "confirm_move_favorites action" do
should "render" do
get_auth confirm_move_favorites_moderator_post_post_path(@post), @admin

View File

@@ -13,6 +13,14 @@ class ModqueueControllerTest < ActionDispatch::IntegrationTest
get_auth modqueue_index_path, @admin
assert_response :success
end
should "include appealed posts in the modqueue" do
@appeal = create(:post_appeal)
get_auth modqueue_index_path, @admin
assert_response :success
assert_select "#post-#{@appeal.post_id}"
end
end
end
end

View File

@@ -49,12 +49,56 @@ class PostAppealsControllerTest < ActionDispatch::IntegrationTest
end
context "create action" do
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"}}
context "appealing a deleted post" do
should "create a new appeal" do
@post = create(:post, is_deleted: true)
assert_difference("PostAppeal.count", 1) do
post_auth post_appeals_path, @user, params: { post_appeal: { post_id: @post.id, reason: "xxx" }}, as: :json
end
assert_response :success
end
end
context "appealing a flagged post" do
should "fail" do
@flag = create(:post_flag)
assert_no_difference("PostAppeal.count") do
post_auth post_appeals_path, @user, params: { post_appeal: { post_id: @flag.post.id, reason: "xxx" }}, as: :json
end
assert_response 422
assert_equal(["cannot be appealed"], response.parsed_body.dig("errors", "post"))
end
end
context "appealing a pending post" do
should "fail" do
@post = create(:post, is_pending: true)
assert_no_difference("PostAppeal.count") do
post_auth post_appeals_path, @user, params: { post_appeal: { post_id: @post.id, reason: "xxx" }}, as: :json
end
assert_response 422
assert_equal(["cannot be appealed"], response.parsed_body.dig("errors", "post"))
end
end
context "appealing an already appealed post" do
should "fail" do
@appeal = create(:post_appeal)
assert_no_difference("PostAppeal.count") do
post_auth post_appeals_path, @user, params: { post_appeal: { post_id: @appeal.post.id, reason: "xxx" }}, as: :json
end
assert_response 422
assert_equal(["cannot be appealed"], response.parsed_body.dig("errors", "post"))
end
end
end
end
end

View File

@@ -27,6 +27,29 @@ class PostApprovalsControllerTest < ActionDispatch::IntegrationTest
end
end
context "for an appealed post" do
should "undelete the post and mark the appeal as successful" do
@appeal = create(:post_appeal)
post_auth post_approvals_path(post_id: @appeal.post_id, format: :js), @approver
assert_response :success
assert_equal(false, @appeal.reload.post.is_deleted?)
assert_equal(true, @appeal.succeeded?)
end
end
context "for a flagged post" do
should "approve the post and mark the flag as rejected" do
@flag = create(:post_flag)
post_auth post_approvals_path(post_id: @flag.post_id, format: :js), @approver
assert_response :success
assert_equal(false, @flag.reload.post.is_deleted?)
assert_equal(false, @flag.post.is_flagged?)
assert_equal(true, @flag.rejected?)
end
end
should "not allow non-approvers to approve posts" do
@post = create(:post, is_pending: true)
post_auth post_approvals_path(post_id: @post.id, format: :js), create(:user)

View File

@@ -8,9 +8,10 @@ class PostEventsControllerTest < ActionDispatch::IntegrationTest
end
as(@user) do
@post = create(:post)
@post.flag!("aaa")
create(:post_appeal, post: @post)
@post = create(:post, is_flagged: true)
create(:post_flag, post: @post, status: :rejected)
@post.update(is_deleted: true)
create(:post_appeal, post: @post, status: :succeeded)
@post.approve!(@mod)
end
end
@@ -37,9 +38,5 @@ class PostEventsControllerTest < ActionDispatch::IntegrationTest
should "render" do
assert_not_nil(@appeal)
end
should "return is_resolved correctly" do
assert_equal(false, @appeal["is_resolved"])
end
end
end

View File

@@ -361,6 +361,30 @@ class PostsControllerTest < ActionDispatch::IntegrationTest
assert_response :success
assert_select "#post_#{@post.id}", 1
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
should "show deleted posts when searching for -status:active" do
get posts_path(tags: "-status:active")
assert_response :success
assert_select "#post_#{@post.id}", 1
end
context "with the hide_deleted_posts option enabled" do
should "show deleted posts when searching for status:appealed" do
@user.update!(hide_deleted_posts: true)
create(:post_appeal, post: @post)
get_auth posts_path(tags: "status:appealed"), @user
assert_response :success
assert_select "#post_#{@post.id}", 1
end
end
end
context "with restricted posts" do
@@ -483,7 +507,7 @@ class PostsControllerTest < ActionDispatch::IntegrationTest
create(:note, post: @post)
create(:artist_commentary, post: @post)
create(:post_flag, post: @post, creator: @user)
create(:post_appeal, post: @post, creator: @user)
#create(:post_appeal, post: @post, creator: @user)
create(:post_vote, post: @post, user: @user)
create(:favorite, post: @post, user: @user)
create(:moderation_report, model: @comment, creator: @builder)
@@ -516,6 +540,15 @@ class PostsControllerTest < ActionDispatch::IntegrationTest
end
end
context "a deleted post" do
should "render" do
@post.delete!("no", user: @user)
get post_path(@post)
assert_response :success
end
end
context "with pools" do
should "render the pool list" do
as(@user) { @post.update(tag_string: "newpool:comic") }
@@ -633,6 +666,42 @@ class PostsControllerTest < ActionDispatch::IntegrationTest
end
end
context "destroy action" do
setup do
@approver = create(:approver)
end
should "delete the post" do
delete_auth post_path(@post), @approver, params: { commit: "Delete", post: { reason: "test" } }
assert_redirected_to @post
assert_equal(true, @post.reload.is_deleted?)
assert_equal("test", @post.flags.last.reason)
end
should "delete the post even if the deleter has flagged the post previously" do
create(:post_flag, post: @post, creator: @approver)
delete_auth post_path(@post), @approver, params: { commit: "Delete", post: { reason: "test" } }
assert_redirected_to @post
assert_equal(true, @post.reload.is_deleted?)
end
should "not delete the post if the user is unauthorized" do
delete_auth post_path(@post), @user, params: { commit: "Delete" }
assert_response 403
assert_equal(false, @post.is_deleted?)
end
should "render the delete post dialog for an xhr request" do
delete_auth post_path(@post), @approver, xhr: true
assert_response :success
assert_equal(false, @post.is_deleted?)
end
end
context "revert action" do
setup do
PostVersion.sqs_service.stubs(:merge?).returns(false)