Merge branch 'master' into attribute-searching
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
FactoryBot.define do
|
||||
factory(:ban) do |f|
|
||||
banner :factory => :admin_user
|
||||
user
|
||||
reason {FFaker::Lorem.words.join(" ")}
|
||||
duration {60}
|
||||
end
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
FactoryBot.define do
|
||||
factory(:post_flag) do
|
||||
creator factory: :user, created_at: 2.weeks.ago
|
||||
post
|
||||
creator
|
||||
post { build(:post, is_flagged: true) }
|
||||
reason {"xxx"}
|
||||
is_resolved {false}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -1,21 +1,30 @@
|
||||
require 'test_helper'
|
||||
|
||||
class DanbooruMaintenanceTest < ActiveSupport::TestCase
|
||||
context "daily maintenance" do
|
||||
context "hourly maintenance" do
|
||||
should "work" do
|
||||
assert_nothing_raised { DanbooruMaintenance.daily }
|
||||
assert_nothing_raised { DanbooruMaintenance.hourly }
|
||||
end
|
||||
|
||||
should "prune expired posts" do
|
||||
@pending = FactoryBot.create(:post, is_pending: true, created_at: 4.days.ago)
|
||||
@flagged = FactoryBot.create(:post, is_flagged: true, created_at: 4.days.ago)
|
||||
@pending = create(:post, is_pending: true, created_at: 5.days.ago)
|
||||
@flagged = create(:post, is_flagged: true, created_at: 5.days.ago)
|
||||
@appealed = create(:post, is_deleted: true, created_at: 5.days.ago)
|
||||
|
||||
DanbooruMaintenance.daily
|
||||
@flag = create(:post_flag, post: @flagged, created_at: 4.days.ago)
|
||||
@appeal = create(:post_appeal, post: @appealed, created_at: 4.days.ago)
|
||||
|
||||
assert(true, @pending.reload.is_deleted)
|
||||
assert(true, @flagged.reload.is_deleted)
|
||||
DanbooruMaintenance.hourly
|
||||
|
||||
assert_equal(true, @pending.reload.is_deleted?)
|
||||
assert_equal(true, @flagged.reload.is_deleted?)
|
||||
assert_equal(true, @appealed.reload.is_deleted?)
|
||||
assert_equal(true, @flag.reload.succeeded?)
|
||||
assert_equal(true, @appeal.reload.rejected?)
|
||||
end
|
||||
end
|
||||
|
||||
context "hourly maintenance" do
|
||||
context "when pruning bans" do
|
||||
should "clear the is_banned flag for users who are no longer banned" do
|
||||
banner = FactoryBot.create(:admin_user)
|
||||
@@ -29,4 +38,32 @@ class DanbooruMaintenanceTest < ActiveSupport::TestCase
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "PostAppealForumUpdater" do
|
||||
should "work when there are no pending appeals" do
|
||||
assert_nothing_raised do
|
||||
PostAppealForumUpdater.update_forum!
|
||||
end
|
||||
end
|
||||
|
||||
should "post pending appeals to the deletion appeal thread" do
|
||||
@topic = as(create(:user)) { create(:forum_topic, title: PostAppealForumUpdater::APPEAL_TOPIC_TITLE) }
|
||||
@appeal1 = create(:post_appeal, reason: "test")
|
||||
@appeal2 = create(:post_appeal, reason: "")
|
||||
@appeal3 = create(:post_appeal, created_at: 2.hours.ago)
|
||||
|
||||
PostAppealForumUpdater.update_forum!
|
||||
|
||||
assert_equal(@topic.id, ForumPost.last.topic_id)
|
||||
assert_equal("post ##{@appeal1.post_id}: #{@appeal1.reason}\npost ##{@appeal2.post_id}", ForumPost.last.body)
|
||||
end
|
||||
|
||||
should "create the deletion appeal thread if it doesn't already exist" do
|
||||
@appeal = create(:post_appeal, reason: "")
|
||||
PostAppealForumUpdater.update_forum!
|
||||
|
||||
assert_equal(PostAppealForumUpdater::APPEAL_TOPIC_TITLE, ForumPost.last.topic.title)
|
||||
assert_equal("post ##{@appeal.post_id}", ForumPost.last.body)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,36 +3,54 @@ require 'test_helper'
|
||||
class PostAppealTest < ActiveSupport::TestCase
|
||||
context "In all cases" do
|
||||
setup do
|
||||
@alice = create(:user)
|
||||
@user = create(:user, upload_points: 1000)
|
||||
end
|
||||
|
||||
context "a user" do
|
||||
setup do
|
||||
@post = FactoryBot.create(:post, :tag_string => "aaa", :is_deleted => true)
|
||||
@post = create(:post, tag_string: "aaa", is_deleted: true)
|
||||
end
|
||||
|
||||
should "not be able to appeal a post more than twice" do
|
||||
@post_appeal = create(:post_appeal, post: @post, creator: @alice)
|
||||
@post_appeal = build(:post_appeal, post: @post, creator: @alice)
|
||||
should "not be able to appeal a post more than once" do
|
||||
@post_appeal = create(:post_appeal, post: @post, creator: @user)
|
||||
@post_appeal = build(:post_appeal, post: @post, creator: @user)
|
||||
|
||||
assert_equal(false, @post_appeal.valid?)
|
||||
assert_includes(@post_appeal.errors.full_messages, "You have already appealed this post")
|
||||
end
|
||||
|
||||
should "not be able to appeal more than 1 post in 24 hours" do
|
||||
@post_appeal = create(:post_appeal, post: @post, creator: @alice)
|
||||
@post_appeal = build(:post_appeal, post: create(:post, is_deleted: true), creator: @alice)
|
||||
should "not be able to appeal an active post" do
|
||||
@post.update!(is_deleted: false)
|
||||
@post_appeal = build(:post_appeal, post: @post, creator: @user)
|
||||
|
||||
assert_equal(false, @post_appeal.valid?)
|
||||
assert_equal(["You can appeal at most 1 post a day"], @post_appeal.errors.full_messages)
|
||||
assert_equal(["Post cannot be appealed"], @post_appeal.errors.full_messages)
|
||||
end
|
||||
|
||||
should "not be able to appeal an active post" do
|
||||
@post.update_attribute(:is_deleted, false)
|
||||
@post_appeal = build(:post_appeal, post: @post, creator: @alice)
|
||||
context "appeal limits" do
|
||||
context "for members" do
|
||||
should "not be able to appeal more than their upload limit" do
|
||||
create_list(:post_appeal, 5, creator: @user)
|
||||
|
||||
assert_equal(false, @post_appeal.valid?)
|
||||
assert_equal(["Post is active"], @post_appeal.errors.full_messages)
|
||||
assert_equal(15, @user.upload_limit.upload_slots)
|
||||
assert_equal(15, @user.upload_limit.used_upload_slots)
|
||||
|
||||
@post_appeal = build(:post_appeal, creator: @user)
|
||||
assert_equal(false, @post_appeal.valid?)
|
||||
assert_equal(["have reached your appeal limit"], @post_appeal.errors[:creator])
|
||||
end
|
||||
end
|
||||
|
||||
context "for users with unrestricted uploads" do
|
||||
should "should not have an appeal limit" do
|
||||
@user = create(:user, can_upload_free: true)
|
||||
create_list(:post_appeal, 10, creator: @user)
|
||||
|
||||
assert_equal(15, @user.upload_limit.upload_slots)
|
||||
assert_equal(30, @user.upload_limit.used_upload_slots)
|
||||
assert_equal(false, @user.is_appeal_limited?)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,64 +3,36 @@ require 'test_helper'
|
||||
class PostApprovalTest < ActiveSupport::TestCase
|
||||
context "a pending post" do
|
||||
setup do
|
||||
@user = FactoryBot.create(:user, created_at: 2.weeks.ago)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
|
||||
@post = FactoryBot.create(:post, uploader_id: @user.id, tag_string: "touhou", is_pending: true)
|
||||
|
||||
@approver = FactoryBot.create(:user)
|
||||
@approver.can_approve_posts = true
|
||||
@approver.save
|
||||
CurrentUser.user = @approver
|
||||
|
||||
CurrentUser.stubs(:can_approve_posts?).returns(true)
|
||||
end
|
||||
|
||||
teardown do
|
||||
CurrentUser.user = nil
|
||||
CurrentUser.ip_addr = nil
|
||||
@user = create(:user, created_at: 2.weeks.ago)
|
||||
@post = create(:post, uploader: @user, is_pending: true)
|
||||
@approver = create(:user, can_approve_posts: true)
|
||||
end
|
||||
|
||||
context "That is approved" do
|
||||
should "create a postapproval record" do
|
||||
assert_difference("PostApproval.count") do
|
||||
@post.approve!
|
||||
@post.approve!(@approver)
|
||||
end
|
||||
end
|
||||
|
||||
context "that is then flagged" do
|
||||
setup do
|
||||
@user2 = create(:user, created_at: 2.weeks.ago)
|
||||
@user3 = create(:user, created_at: 2.weeks.ago)
|
||||
@approver2 = FactoryBot.create(:user)
|
||||
@approver2.can_approve_posts = true
|
||||
@approver2.save
|
||||
end
|
||||
should "prevent an approver from approving the same post twice" do
|
||||
@approval1 = create(:post_approval, post: @post, user: @approver)
|
||||
@approval2 = build(:post_approval, post: @post, user: @approver)
|
||||
|
||||
should "prevent the first approver from approving again" do
|
||||
@post.approve!(@approver)
|
||||
CurrentUser.user = @user2
|
||||
@post.flag!("blah")
|
||||
@post.approve!(@approver2)
|
||||
assert_not_equal(@approver.id, @post.approver_id)
|
||||
CurrentUser.user = @user3
|
||||
travel(PostFlag::COOLDOWN_PERIOD + 1.minute) do
|
||||
@post.flag!("blah blah")
|
||||
end
|
||||
|
||||
approval = @post.approve!(@approver)
|
||||
assert_includes(approval.errors.full_messages, "You have previously approved this post and cannot approve it again")
|
||||
end
|
||||
assert_equal(false, @approval2.valid?)
|
||||
assert_equal(["You have previously approved this post and cannot approve it again"], @approval2.errors[:base])
|
||||
end
|
||||
end
|
||||
|
||||
context "#search method" do
|
||||
should "work" do
|
||||
@approval = @post.approve!(@approver)
|
||||
@approvals = PostApproval.search(user_name: @approver.name, post_tags_match: "touhou", post_id: @post.id)
|
||||
CurrentUser.scoped(@approver) do
|
||||
@post.update!(tag_string: "touhou")
|
||||
@approval = @post.approve!(@approver)
|
||||
@approvals = PostApproval.search(user_name: @approver.name, post_tags_match: "touhou", post_id: @post.id)
|
||||
|
||||
assert_equal([@approval.id], @approvals.map(&:id))
|
||||
assert_equal([@approval.id], @approvals.map(&:id))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,6 +5,7 @@ class PostEventTest < ActiveSupport::TestCase
|
||||
@user = create(:user, created_at: 2.weeks.ago)
|
||||
@post = create(:post)
|
||||
@post_flag = create(:post_flag, creator: @user, post: @post)
|
||||
@post.update(is_deleted: true)
|
||||
@post_appeal = create(:post_appeal, creator: @user, post: @post)
|
||||
end
|
||||
|
||||
|
||||
@@ -1,99 +1,103 @@
|
||||
require 'test_helper'
|
||||
|
||||
class PostFlagTest < ActiveSupport::TestCase
|
||||
context "In all cases" do
|
||||
setup do
|
||||
travel_to(2.weeks.ago) do
|
||||
@alice = create(:gold_user)
|
||||
context "PostFlag: " do
|
||||
context "an approver" do
|
||||
should "be able to flag an unlimited number of posts" do
|
||||
@user = create(:user, can_approve_posts: true)
|
||||
|
||||
assert_nothing_raised do
|
||||
create_list(:post_flag, 6, creator: @user, status: :pending)
|
||||
end
|
||||
end
|
||||
as(@alice) do
|
||||
@post = create(:post, tag_string: "aaa", uploader: @alice)
|
||||
end
|
||||
|
||||
context "a user with unlimited flags" do
|
||||
should "be able to flag an unlimited number of posts" do
|
||||
@user = create(:user)
|
||||
create_list(:post_flag, 30, status: :succeeded, creator: @user)
|
||||
|
||||
assert_equal(true, @user.has_unlimited_flags?)
|
||||
assert_equal(false, @user.is_flag_limited?)
|
||||
|
||||
assert_nothing_raised do
|
||||
create_list(:post_flag, 6, creator: @user, status: :pending)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "a basic user" do
|
||||
should "not be able to flag more than 1 post in 24 hours" do
|
||||
@bob = create(:user, created_at: 2.weeks.ago)
|
||||
@post_flag = build(:post_flag, creator: @bob)
|
||||
@post_flag.expects(:flag_count_for_creator).returns(1)
|
||||
should "be able to flag up to 5 posts at once" do
|
||||
@user = create(:user)
|
||||
@flags = create_list(:post_flag, 5, creator: @user, status: :pending)
|
||||
@flag = build(:post_flag, creator: @user, status: :pending)
|
||||
|
||||
assert_equal(false, @post_flag.valid?)
|
||||
assert_equal(["You can flag 1 post a day"], @post_flag.errors.full_messages)
|
||||
assert_equal(false, @flag.valid?)
|
||||
assert_equal(["have reached your flag limit"], @flag.errors[:creator])
|
||||
end
|
||||
|
||||
should "have early rejected flags count against their flag limit" do
|
||||
@user = create(:user)
|
||||
|
||||
create(:post_flag, creator: @user, status: :pending)
|
||||
assert_equal(1, @user.post_flags.active.count)
|
||||
|
||||
create(:post_flag, creator: @user, status: :rejected)
|
||||
assert_equal(2, @user.post_flags.active.count)
|
||||
|
||||
create(:post_flag, creator: @user, status: :succeeded)
|
||||
assert_equal(2, @user.post_flags.active.count)
|
||||
|
||||
create(:post_flag, creator: @user, status: :rejected, created_at: 4.days.ago)
|
||||
assert_equal(2, @user.post_flags.active.count)
|
||||
end
|
||||
end
|
||||
|
||||
context "a gold user" do
|
||||
setup do
|
||||
@bob = create(:gold_user, created_at: 1.month.ago)
|
||||
end
|
||||
|
||||
should "not be able to flag a post more than twice" do
|
||||
@post_flag = create(:post_flag, post: @post, creator: @bob)
|
||||
@post_flag = build(:post_flag, post: @post, creator: @bob)
|
||||
context "a user" do
|
||||
should "not be able to flag a post more than once" do
|
||||
@user = create(:user)
|
||||
@post = create(:post)
|
||||
@post_flag = create(:post_flag, post: @post, creator: @user)
|
||||
@post_flag = build(:post_flag, post: @post, creator: @user)
|
||||
|
||||
assert_equal(false, @post_flag.valid?)
|
||||
assert_equal(["have already flagged this post"], @post_flag.errors[:creator_id])
|
||||
end
|
||||
|
||||
should "not be able to flag more than 10 posts in 24 hours" do
|
||||
@post_flag = build(:post_flag, post: @post, creator: @bob)
|
||||
@post_flag.expects(:flag_count_for_creator).returns(10)
|
||||
|
||||
assert_difference(-> { PostFlag.count }, 0) do
|
||||
@post_flag.save
|
||||
end
|
||||
|
||||
assert_equal(["You can flag 10 posts a day"], @post_flag.errors.full_messages)
|
||||
end
|
||||
|
||||
should "not be able to flag a deleted post" do
|
||||
as(@alice) do
|
||||
@post.update(is_deleted: true)
|
||||
end
|
||||
@post = create(:post, is_deleted: true)
|
||||
@post_flag = build(:post_flag, post: @post)
|
||||
|
||||
@post_flag = build(:post_flag, post: @post, creator: @bob)
|
||||
@post_flag.save
|
||||
assert_equal(["Post is deleted"], @post_flag.errors.full_messages)
|
||||
assert_equal(false, @post_flag.valid?)
|
||||
assert_equal(["Post is deleted and cannot be flagged"], @post_flag.errors.full_messages)
|
||||
end
|
||||
|
||||
should "not be able to flag a pending post" do
|
||||
as(@alice) do
|
||||
@post.update(is_pending: true)
|
||||
end
|
||||
@flag = @post.flags.create(reason: "test", creator: @bob)
|
||||
@post = create(:post, is_pending: true)
|
||||
@flag = build(:post_flag, post: @post)
|
||||
|
||||
assert_equal(false, @flag.valid?)
|
||||
assert_equal(["Post is pending and cannot be flagged"], @flag.errors.full_messages)
|
||||
end
|
||||
|
||||
should "not be able to flag a post in the cooldown period" do
|
||||
@mod = create(:moderator_user)
|
||||
@users = create_list(:user, 2)
|
||||
@post = create(:post)
|
||||
@flag1 = create(:post_flag, post: @post, creator: @users.first)
|
||||
as(@mod) { @post.approve! }
|
||||
|
||||
travel_to(2.weeks.ago) do
|
||||
@users = FactoryBot.create_list(:user, 2)
|
||||
end
|
||||
|
||||
@flag1 = create(:post_flag, post: @post, reason: "something", creator: @users.first)
|
||||
|
||||
as(@mod) do
|
||||
@post.approve!
|
||||
end
|
||||
|
||||
travel_to(PostFlag::COOLDOWN_PERIOD.from_now - 1.minute) do
|
||||
travel_to(Danbooru.config.moderation_period.from_now - 1.minute) do
|
||||
@flag2 = build(:post_flag, post: @post, reason: "something", creator: @users.second)
|
||||
assert_equal(false, @flag2.valid?)
|
||||
assert_match(/cannot be flagged more than once/, @flag2.errors[:post].join)
|
||||
end
|
||||
|
||||
travel_to(PostFlag::COOLDOWN_PERIOD.from_now + 1.minute) do
|
||||
travel_to(Danbooru.config.moderation_period.from_now + 1.minute) do
|
||||
@flag3 = create(:post_flag, post: @post, reason: "something", creator: @users.second)
|
||||
assert(@flag3.errors.empty?)
|
||||
end
|
||||
end
|
||||
|
||||
should "initialize its creator" do
|
||||
@post_flag = create(:post_flag, creator: @alice)
|
||||
assert_equal(@alice.id, @post_flag.creator_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,30 +1,108 @@
|
||||
require 'test_helper'
|
||||
|
||||
class PostPrunerTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
@old_post = FactoryBot.create(:post, :created_at => 5.days.ago, :is_pending => true)
|
||||
@unresolved_flagged_post = FactoryBot.create(:post, :is_flagged => true)
|
||||
@resolved_flagged_post = FactoryBot.create(:post, :is_flagged => true)
|
||||
context "PostPruner" do
|
||||
context "for a pending post" do
|
||||
should "prune expired posts" do
|
||||
@post = create(:post, created_at: 5.days.ago, is_pending: true)
|
||||
PostPruner.prune!
|
||||
|
||||
@flagger = create(:gold_user, created_at: 2.weeks.ago)
|
||||
@unresolved_post_flag = create(:post_flag, creator: @flagger, created_at: 5.days.ago, is_resolved: false, post: @unresolved_flagged_post)
|
||||
@resolved_post_flag = create(:post_flag, creator: @flagger, created_at: 5.days.ago, is_resolved: true, post: @resolved_flagged_post)
|
||||
assert_equal(true, @post.reload.is_deleted?)
|
||||
assert_equal(false, @post.is_pending?)
|
||||
|
||||
PostPruner.new.prune!
|
||||
end
|
||||
assert_equal(1, @post.flags.size)
|
||||
assert_equal("Unapproved in three days", @post.flags.last.reason)
|
||||
end
|
||||
end
|
||||
|
||||
should "prune old pending posts" do
|
||||
@old_post.reload
|
||||
assert(@old_post.is_deleted?)
|
||||
end
|
||||
context "for a flagged post" do
|
||||
should "prune expired flags" do
|
||||
@post = create(:post, created_at: 4.weeks.ago, is_flagged: true)
|
||||
@flag = create(:post_flag, post: @post, created_at: 5.days.ago)
|
||||
PostPruner.prune!
|
||||
|
||||
should "prune old flagged posts that are still unresolved" do
|
||||
@unresolved_flagged_post.reload
|
||||
assert(@unresolved_flagged_post.is_deleted?)
|
||||
end
|
||||
assert_equal(true, @post.reload.is_deleted?)
|
||||
assert_equal(false, @post.is_pending?)
|
||||
assert_equal(false, @post.is_flagged?)
|
||||
assert_equal(true, @flag.reload.succeeded?)
|
||||
|
||||
should "not prune old flagged posts that are resolved" do
|
||||
@resolved_flagged_post.reload
|
||||
assert(!@resolved_flagged_post.is_deleted?)
|
||||
assert_equal(2, @post.flags.size)
|
||||
assert_equal("Unapproved in three days after returning to moderation queue", @post.flags.last.reason)
|
||||
end
|
||||
|
||||
should "not prune unexpired flags" do
|
||||
@post = create(:post, created_at: 4.weeks.ago, is_flagged: true)
|
||||
@flag = create(:post_flag, post: @post, created_at: 1.day.ago)
|
||||
PostPruner.prune!
|
||||
|
||||
assert_equal(false, @post.reload.is_deleted?)
|
||||
assert_equal(false, @post.is_pending?)
|
||||
assert_equal(true, @post.is_flagged?)
|
||||
assert_equal(true, @flag.reload.pending?)
|
||||
|
||||
assert_equal(1, @post.flags.size)
|
||||
end
|
||||
|
||||
should "leave the status of old flags unchanged" do
|
||||
@post = create(:post, created_at: 4.weeks.ago, is_flagged: true)
|
||||
@flag1 = create(:post_flag, post: @post, created_at: 3.weeks.ago, status: :succeeded)
|
||||
@flag2 = create(:post_flag, post: @post, created_at: 2.weeks.ago, status: :rejected)
|
||||
@flag3 = create(:post_flag, post: @post, created_at: 1.weeks.ago, status: :pending)
|
||||
PostPruner.prune!
|
||||
|
||||
assert_equal(true, @post.reload.is_deleted?)
|
||||
assert_equal(false, @post.is_pending?)
|
||||
assert_equal(false, @post.is_flagged?)
|
||||
|
||||
assert_equal(true, @flag1.reload.succeeded?)
|
||||
assert_equal(true, @flag2.reload.rejected?)
|
||||
assert_equal(true, @flag3.reload.succeeded?)
|
||||
end
|
||||
end
|
||||
|
||||
context "for an appealed post" do
|
||||
should "prune expired appeals" do
|
||||
@post = create(:post, created_at: 4.weeks.ago, is_deleted: true)
|
||||
@appeal = create(:post_appeal, post: @post, created_at: 5.days.ago)
|
||||
PostPruner.prune!
|
||||
|
||||
assert_equal(false, @post.reload.is_pending?)
|
||||
assert_equal(false, @post.is_flagged?)
|
||||
assert_equal(true, @post.is_deleted?)
|
||||
assert_equal(true, @appeal.reload.rejected?)
|
||||
|
||||
assert_equal(1, @post.flags.size)
|
||||
assert_equal("Unapproved in three days after returning to moderation queue", @post.flags.last.reason)
|
||||
end
|
||||
|
||||
should "not prune unexpired appeals" do
|
||||
@post = create(:post, created_at: 4.weeks.ago, is_deleted: true)
|
||||
@appeal = create(:post_appeal, post: @post, created_at: 1.day.ago)
|
||||
PostPruner.prune!
|
||||
|
||||
assert_equal(false, @post.reload.is_pending?)
|
||||
assert_equal(false, @post.is_flagged?)
|
||||
assert_equal(true, @post.is_deleted?)
|
||||
assert_equal(true, @appeal.reload.pending?)
|
||||
|
||||
assert_equal(0, @post.flags.size)
|
||||
end
|
||||
|
||||
should "leave the status of old appeals unchanged" do
|
||||
@post = create(:post, created_at: 4.weeks.ago, is_deleted: true)
|
||||
@appeal1 = create(:post_appeal, post: @post, created_at: 3.weeks.ago, status: :succeeded)
|
||||
@appeal2 = create(:post_appeal, post: @post, created_at: 2.weeks.ago, status: :rejected)
|
||||
@appeal3 = create(:post_appeal, post: @post, created_at: 1.weeks.ago, status: :pending)
|
||||
PostPruner.prune!
|
||||
|
||||
assert_equal(true, @post.reload.is_deleted?)
|
||||
assert_equal(false, @post.is_pending?)
|
||||
assert_equal(false, @post.is_flagged?)
|
||||
|
||||
assert_equal(true, @appeal1.reload.succeeded?)
|
||||
assert_equal(true, @appeal2.reload.rejected?)
|
||||
assert_equal(false, @appeal3.reload.pending?)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -9,6 +9,13 @@ class PostQueryBuilderTest < ActiveSupport::TestCase
|
||||
assert_equal(count, PostQueryBuilder.new(query, **query_options).normalized_query.fast_count(**fast_count_options))
|
||||
end
|
||||
|
||||
def assert_parse_equals(expected, query)
|
||||
assert_equal(expected, PostQueryBuilder.new(query).split_query)
|
||||
|
||||
# parsing, serializing, then parsing again should produce the same result.
|
||||
assert_equal(PostQueryBuilder.new(query).to_s, PostQueryBuilder.new(PostQueryBuilder.new(query).to_s).to_s)
|
||||
end
|
||||
|
||||
setup do
|
||||
CurrentUser.user = create(:user)
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
@@ -584,22 +591,26 @@ class PostQueryBuilderTest < ActiveSupport::TestCase
|
||||
flagged = create(:post, is_flagged: true)
|
||||
deleted = create(:post, is_deleted: true)
|
||||
banned = create(:post, is_banned: true)
|
||||
all = [banned, deleted, flagged, pending]
|
||||
appealed = create(:post, is_deleted: true)
|
||||
appeal = create(:post_appeal, post: appealed)
|
||||
all = [appealed, banned, deleted, flagged, pending]
|
||||
|
||||
assert_tag_match([flagged, pending], "status:modqueue")
|
||||
assert_tag_match([appealed, flagged, pending], "status:modqueue")
|
||||
assert_tag_match([pending], "status:pending")
|
||||
assert_tag_match([flagged], "status:flagged")
|
||||
assert_tag_match([deleted], "status:deleted")
|
||||
assert_tag_match([appealed], "status:appealed")
|
||||
assert_tag_match([appealed, deleted], "status:deleted")
|
||||
assert_tag_match([banned], "status:banned")
|
||||
assert_tag_match([banned], "status:active")
|
||||
assert_tag_match([banned], "status:active status:banned")
|
||||
assert_tag_match(all, "status:any")
|
||||
assert_tag_match(all, "status:all")
|
||||
|
||||
assert_tag_match(all - [flagged, pending], "-status:modqueue")
|
||||
assert_tag_match(all - [flagged, pending, appealed], "-status:modqueue")
|
||||
assert_tag_match(all - [pending], "-status:pending")
|
||||
assert_tag_match(all - [flagged], "-status:flagged")
|
||||
assert_tag_match(all - [deleted], "-status:deleted")
|
||||
assert_tag_match(all - [appealed], "-status:appealed")
|
||||
assert_tag_match(all - [deleted, appealed], "-status:deleted")
|
||||
assert_tag_match(all - [banned], "-status:banned")
|
||||
assert_tag_match(all - [banned], "-status:active")
|
||||
|
||||
@@ -611,11 +622,13 @@ class PostQueryBuilderTest < ActiveSupport::TestCase
|
||||
flagged = create(:post, is_flagged: true)
|
||||
pending = create(:post, is_pending: true)
|
||||
disapproved = create(:post, is_pending: true)
|
||||
appealed = create(:post, is_deleted: true)
|
||||
|
||||
create(:post_flag, post: flagged, creator: create(:user, created_at: 2.weeks.ago))
|
||||
create(:post_appeal, post: appealed)
|
||||
create(:post_disapproval, user: CurrentUser.user, post: disapproved, reason: "disinterest")
|
||||
|
||||
assert_tag_match([pending, flagged], "status:unmoderated")
|
||||
assert_tag_match([appealed, pending, flagged], "status:unmoderated")
|
||||
assert_tag_match([disapproved], "-status:unmoderated")
|
||||
end
|
||||
|
||||
@@ -712,7 +725,11 @@ class PostQueryBuilderTest < ActiveSupport::TestCase
|
||||
|
||||
assert_tag_match([post3], "source:none")
|
||||
assert_tag_match([post3], "source:NONE")
|
||||
assert_tag_match([post3], 'source:""')
|
||||
assert_tag_match([post3], "source:''")
|
||||
assert_tag_match([post2, post1], "-source:none")
|
||||
assert_tag_match([post2, post1], "-source:''")
|
||||
assert_tag_match([post2, post1], '-source:""')
|
||||
|
||||
assert_tag_match([], "source:'none'")
|
||||
assert_tag_match([], "source:none source:abcde")
|
||||
@@ -1060,6 +1077,33 @@ class PostQueryBuilderTest < ActiveSupport::TestCase
|
||||
assert_equal(false, PostQueryBuilder.new('source:"foo bar baz"').is_simple_tag?)
|
||||
assert_equal(false, PostQueryBuilder.new("foo bar").is_simple_tag?)
|
||||
end
|
||||
|
||||
should "parse quoted metatags correctly" do
|
||||
assert_parse_equals(%w[status:"active" source:"https"], %q(status:'active' source:'https'))
|
||||
assert_parse_equals(%w[source:"https" status:"active"], %q(source:'https' status:'active'))
|
||||
assert_parse_equals(%w[status:"active" source:"https"], %q(status:"active" source:'https'))
|
||||
assert_parse_equals(%w[status:"active" source:"https"], %q(status:'active' source:"https"))
|
||||
assert_parse_equals(%w[status:"active" source:https], %q(status:'active' source:https))
|
||||
assert_parse_equals(%w[status:active source:"https"], %q(status:active source:'https'))
|
||||
|
||||
assert_parse_equals(%w[limit:"5" status:"active" source:"x"], %q(limit:"5" status:"active" source:"x"))
|
||||
assert_parse_equals(%w[source:"" limit:"1" status:"deleted"], %q(source:"" limit:'1' status:'deleted'))
|
||||
|
||||
assert_parse_equals(['source:"bar baz"', 'don\'t_say_"lazy"'], %q(source:"bar baz" don't_say_"lazy"))
|
||||
assert_parse_equals(['source:"bar baz"', 'don\'t_say_"lazy"'], %q(source:"bar baz" don't_say_"lazy"))
|
||||
assert_parse_equals(['source:"bar baz"', 'don\'t_say_"lazy"'], %q(source:'bar baz' don't_say_"lazy"))
|
||||
|
||||
assert_parse_equals([%q(source:"foo")], %q(source:"\f\o\o"))
|
||||
assert_parse_equals([%q(source:"foo")], %q(source:'\f\o\o'))
|
||||
assert_parse_equals([%q(source:foo\bar)], %q(source:foo\bar))
|
||||
assert_parse_equals([%q(source:"foo)], %q(source:"foo))
|
||||
assert_parse_equals([%q(source:'foo)], %q(source:'foo))
|
||||
assert_parse_equals([%q(source:"foo bar")], %q(source:foo\ bar))
|
||||
assert_parse_equals([%q(source:"\"foo bar\\\\")], %q(source:"foo\ bar\\))
|
||||
|
||||
assert_parse_equals(['source:"don\'t_say_\\"lazy\\""', 'don\'t_say_"lazy"'], %q(source:"don't_say_\"lazy\"" don't_say_"lazy"))
|
||||
assert_parse_equals(['source:"don\'t_say_\\"lazy\\""', 'don\'t_say_"lazy"'], %q(source:'don\'t_say_"lazy"' don't_say_"lazy"))
|
||||
end
|
||||
end
|
||||
|
||||
context "The normalized_query method" do
|
||||
|
||||
@@ -142,9 +142,11 @@ class PostTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "fail" do
|
||||
@post.delete!("test")
|
||||
assert_equal(["Is status locked ; cannot delete post"], @post.errors.full_messages)
|
||||
assert_equal(1, Post.where("id = ?", @post.id).count)
|
||||
assert_raise(ActiveRecord::RecordInvalid) do
|
||||
@post.delete!("test")
|
||||
end
|
||||
|
||||
assert_equal(false, @post.reload.is_deleted?)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -224,18 +226,6 @@ class PostTest < ActiveSupport::TestCase
|
||||
assert_equal(false, p1.has_children?)
|
||||
end
|
||||
|
||||
should "reassign favorites to the parent" do
|
||||
p1 = FactoryBot.create(:post)
|
||||
c1 = FactoryBot.create(:post, :parent_id => p1.id)
|
||||
user = FactoryBot.create(:user)
|
||||
c1.add_favorite!(user)
|
||||
c1.expunge!
|
||||
p1.reload
|
||||
assert(!Favorite.exists?(:post_id => c1.id, :user_id => user.id))
|
||||
assert(Favorite.exists?(:post_id => p1.id, :user_id => user.id))
|
||||
assert_equal(0, c1.score)
|
||||
end
|
||||
|
||||
should "update the parent's has_children flag" do
|
||||
p1 = FactoryBot.create(:post)
|
||||
c1 = FactoryBot.create(:post, :parent_id => p1.id)
|
||||
@@ -266,17 +256,6 @@ class PostTest < ActiveSupport::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
should "reparent all children to the first child" do
|
||||
@p1.expunge!
|
||||
@c1.reload
|
||||
@c2.reload
|
||||
@c3.reload
|
||||
|
||||
assert_nil(@c1.parent_id)
|
||||
assert_equal(@c1.id, @c2.parent_id)
|
||||
assert_equal(@c1.id, @c3.parent_id)
|
||||
end
|
||||
|
||||
should "save a post version record for each child" do
|
||||
assert_difference(["@c1.versions.count", "@c2.versions.count", "@c3.versions.count"]) do
|
||||
@p1.expunge!
|
||||
@@ -285,11 +264,6 @@ class PostTest < ActiveSupport::TestCase
|
||||
@c3.reload
|
||||
end
|
||||
end
|
||||
|
||||
should "set the has_children flag on the new parent" do
|
||||
@p1.expunge!
|
||||
assert_equal(true, @c1.reload.has_children?)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -539,24 +513,23 @@ class PostTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
context "A status locked post" do
|
||||
setup do
|
||||
@post = FactoryBot.create(:post, is_status_locked: true)
|
||||
end
|
||||
|
||||
should "not allow new flags" do
|
||||
assert_raises(PostFlag::Error) do
|
||||
@post = create(:post, is_status_locked: true)
|
||||
@post.flag!("wrong")
|
||||
end
|
||||
end
|
||||
|
||||
should "not allow new appeals" do
|
||||
@post = create(:post, is_status_locked: true, is_deleted: true)
|
||||
@appeal = build(:post_appeal, post: @post)
|
||||
|
||||
assert_equal(false, @appeal.valid?)
|
||||
assert_equal(["Post is active"], @appeal.errors.full_messages)
|
||||
assert_equal(["Post cannot be appealed"], @appeal.errors.full_messages)
|
||||
end
|
||||
|
||||
should "not allow approval" do
|
||||
@post = create(:post, is_status_locked: true, is_pending: true)
|
||||
approval = @post.approve!
|
||||
assert_includes(approval.errors.full_messages, "Post is locked and cannot be approved")
|
||||
end
|
||||
@@ -569,24 +542,6 @@ class PostTest < ActiveSupport::TestCase
|
||||
@post = FactoryBot.create(:post)
|
||||
end
|
||||
|
||||
context "as a new user" do
|
||||
setup do
|
||||
@post.update(:tag_string => "aaa bbb ccc ddd tagme")
|
||||
CurrentUser.user = FactoryBot.create(:user)
|
||||
end
|
||||
|
||||
should "not allow you to remove tags" do
|
||||
@post.update(tag_string: "aaa")
|
||||
assert_equal(["You must have an account at least 1 week old to remove tags"], @post.errors.full_messages)
|
||||
end
|
||||
|
||||
should "allow you to remove request tags" do
|
||||
@post.update(tag_string: "aaa bbb ccc ddd")
|
||||
@post.reload
|
||||
assert_equal("aaa bbb ccc ddd", @post.tag_string)
|
||||
end
|
||||
end
|
||||
|
||||
context "with a banned artist" do
|
||||
setup do
|
||||
CurrentUser.scoped(FactoryBot.create(:admin_user)) do
|
||||
|
||||
@@ -69,7 +69,8 @@ module Sources
|
||||
["眼鏡", "https://nijie.info/search.php?word=%E7%9C%BC%E9%8F%A1"],
|
||||
["谷間", "https://nijie.info/search.php?word=%E8%B0%B7%E9%96%93"],
|
||||
["リトルウィッチアカデミア", "https://nijie.info/search.php?word=%E3%83%AA%E3%83%88%E3%83%AB%E3%82%A6%E3%82%A3%E3%83%83%E3%83%81%E3%82%A2%E3%82%AB%E3%83%87%E3%83%9F%E3%82%A2"],
|
||||
["アーシュラ先生", "https://nijie.info/search.php?word=%E3%82%A2%E3%83%BC%E3%82%B7%E3%83%A5%E3%83%A9%E5%85%88%E7%94%9F"]
|
||||
["アーシュラ先生", "https://nijie.info/search.php?word=%E3%82%A2%E3%83%BC%E3%82%B7%E3%83%A5%E3%83%A9%E5%85%88%E7%94%9F"],
|
||||
["上着全開", "https://nijie.info/search.php?word=%E4%B8%8A%E7%9D%80%E5%85%A8%E9%96%8B"]
|
||||
]
|
||||
|
||||
assert_equal(tags, @site.tags)
|
||||
@@ -292,6 +293,18 @@ module Sources
|
||||
end
|
||||
end
|
||||
|
||||
context "a post requiring login" do
|
||||
should "not fail" do
|
||||
site = Sources::Strategies.find("https://nijie.info/view.php?id=203688")
|
||||
|
||||
urls = %w[
|
||||
https://pic.nijie.net/01/nijie_picture/676327_20170216212803_0.jpg
|
||||
https://pic.nijie.net/04/nijie_picture/diff/main/676327_20170216212806_0.jpg
|
||||
]
|
||||
assert_equal(urls, site.image_urls)
|
||||
end
|
||||
end
|
||||
|
||||
context "normalizing for source" do
|
||||
should "normalize correctly" do
|
||||
source1 = "https://pic01.nijie.info/nijie_picture/diff/main/218856_0_236014_20170620101329.png"
|
||||
|
||||
@@ -220,14 +220,13 @@ module Sources
|
||||
|
||||
context "A Tumblr post with new image URLs" do
|
||||
should "return the correct image url" do
|
||||
page_url = "https://emlan.tumblr.com/post/189469423572/kuro-attempts-to-buy-a-racy-book-at-comiket-but"
|
||||
image1_url = "https://66.media.tumblr.com/168dabd09d5ad69eb5fedcf94c45c31a/3dbfaec9b9e0c2e3-72/s640x960/bf33a1324f3f36d2dc64f011bfeab4867da62bc8.png"
|
||||
image2_url = "https://66.media.tumblr.com/5a2c3fe25c977e2281392752ab971c90/3dbfaec9b9e0c2e3-92/s540x810/cd270c29db06b5e7fdcee63114fe3eb2c9c0d590.png"
|
||||
strategy = Sources::Strategies.find(image2_url, page_url)
|
||||
image_url = "https://64.media.tumblr.com/3dfdab77d913ad1ea59f22407d6ac6f3/b1764aa0f9c378d0-23/s1280x1920/46f4af7ec94456f8fef380ee6311eb81178ce7e9.jpg"
|
||||
page_url = "https://make-do5.tumblr.com/post/619663949657423872"
|
||||
strategy = Sources::Strategies.find(image_url, page_url)
|
||||
|
||||
assert_equal([image1_url, image2_url], strategy.image_urls)
|
||||
assert_equal(image2_url, strategy.image_url)
|
||||
assert_equal("https://emlan.tumblr.com/post/189469423572", strategy.canonical_url)
|
||||
assert_match(%r{/3dfdab77d913ad1ea59f22407d6ac6f3/b1764aa0f9c378d0-23/s\d+x\d+/}i, image_url)
|
||||
assert_equal(page_url, strategy.canonical_url)
|
||||
assert_downloaded(7_428_704, strategy.image_url)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -12,11 +12,19 @@ class UploadLimitTest < ActiveSupport::TestCase
|
||||
@post = create(:post, uploader: @user, is_pending: true, created_at: 7.days.ago)
|
||||
assert_equal(1000, @user.reload.upload_points)
|
||||
|
||||
PostPruner.new.prune!
|
||||
PostPruner.prune!
|
||||
assert_equal(967, @user.reload.upload_points)
|
||||
end
|
||||
end
|
||||
|
||||
context "a new post that is deleted within the first 3 days" do
|
||||
should "cost the uploader 5 upload slots" do
|
||||
@post = create(:post, uploader: @user, is_deleted: true, created_at: 1.days.ago)
|
||||
|
||||
assert_equal(5, @user.upload_limit.used_upload_slots)
|
||||
end
|
||||
end
|
||||
|
||||
context "a pending post that is approved" do
|
||||
should "increase the uploader's upload points" do
|
||||
@post = create(:post, uploader: @user, is_pending: true, created_at: 7.days.ago)
|
||||
|
||||
Reference in New Issue
Block a user