forked from e621ng/e621ng
[Tests] Fix a bunch
1269 runs, 2237 assertions, 68 failures, 27 errors, 0 skips
This commit is contained in:
parent
26d755b895
commit
0d50202bbd
@ -32,7 +32,7 @@ class BulkUpdateRequestsControllerTest < ActionDispatch::IntegrationTest
|
||||
should "still handle disabled secondary validations correctly" do
|
||||
put_auth bulk_update_request_path(@bulk_update_request.id), @user, params: {bulk_update_request: {script: "create alias zzz -> 222"}}
|
||||
@bulk_update_request.reload
|
||||
assert_equal("create alias zzz -> 222", @bulk_update_request.script)
|
||||
assert_equal("alias zzz -> 222", @bulk_update_request.script)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -9,7 +9,7 @@ class FavoritesControllerTest < ActionDispatch::IntegrationTest
|
||||
context "index action" do
|
||||
setup do
|
||||
@post = create(:post)
|
||||
@post.add_favorite!(@user)
|
||||
FavoriteManager.add!(user: @user, post: @post)
|
||||
end
|
||||
|
||||
context "with a specified tags parameter" do
|
||||
@ -40,7 +40,7 @@ class FavoritesControllerTest < ActionDispatch::IntegrationTest
|
||||
context "destroy action" do
|
||||
setup do
|
||||
@post = create(:post)
|
||||
@post.add_favorite!(@user)
|
||||
FavoriteManager.add!(user: @user, post: @post)
|
||||
end
|
||||
|
||||
should "remove the favorite from the current user" do
|
||||
|
@ -70,7 +70,7 @@ module Moderator
|
||||
end
|
||||
users = FactoryBot.create_list(:user, 2)
|
||||
users.each do |u|
|
||||
@child.add_favorite!(u)
|
||||
FavoriteManager.add!(user: u, post: @child)
|
||||
@child.reload
|
||||
end
|
||||
|
||||
@ -87,9 +87,9 @@ module Moderator
|
||||
|
||||
context "expunge action" do
|
||||
should "render" do
|
||||
post_auth expunge_moderator_post_post_path(@post), @admin, params: { format: "js" }
|
||||
post_auth expunge_moderator_post_post_path(@post), @admin
|
||||
|
||||
assert_response :success
|
||||
assert_response :found
|
||||
assert_equal(false, ::Post.exists?(@post.id))
|
||||
end
|
||||
end
|
||||
|
@ -1,18 +1,17 @@
|
||||
require 'test_helper'
|
||||
|
||||
class UploadsControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
setup do
|
||||
Sidekiq::Testing::inline!
|
||||
Sidekiq::Testing.inline!
|
||||
end
|
||||
|
||||
teardown do
|
||||
Sidekiq::Testing::fake!
|
||||
Sidekiq::Testing.fake!
|
||||
end
|
||||
|
||||
context "The uploads controller" do
|
||||
setup do
|
||||
@user = create(:contributor_user)
|
||||
@user = create(:janitor_user)
|
||||
mock_iqdb_service!
|
||||
end
|
||||
|
||||
@ -23,13 +22,6 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
context "with a url" do
|
||||
should "preprocess" do
|
||||
assert_difference(-> { Upload.count }) do
|
||||
get_auth new_upload_path, @user, params: {:url => "https://raikou1.donmai.us/d3/4e/d34e4cf0a437a5d65f8e82b7bcd02606.jpg"}
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
should "prefer the file" do
|
||||
get_auth new_upload_path, @user, params: {url: "https://raikou1.donmai.us/d3/4e/d34e4cf0a437a5d65f8e82b7bcd02606.jpg"}
|
||||
file = Rack::Test::UploadedFile.new("#{Rails.root}/test/files/test.jpg", "image/jpeg")
|
||||
@ -98,7 +90,7 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest
|
||||
status: @upload.status
|
||||
}
|
||||
|
||||
get uploads_path, params: { search: search_params }
|
||||
get_auth uploads_path, params: { search: search_params }
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
@ -151,14 +151,7 @@ class WikiPagesControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
should "destroy a wiki_page" do
|
||||
delete_auth wiki_page_path(@wiki_page), @mod
|
||||
@wiki_page.reload
|
||||
assert_equal(true, @wiki_page.is_deleted?)
|
||||
end
|
||||
|
||||
should "record the deleter" do
|
||||
delete_auth wiki_page_path(@wiki_page), @mod
|
||||
@wiki_page.reload
|
||||
assert_equal(@mod.id, @wiki_page.updater_id)
|
||||
assert_not(WikiPage.exists?(@wiki_page.id))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -216,389 +216,6 @@ class UploadServiceTest < ActiveSupport::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
context "::Replacer" do
|
||||
context "for a file replacement" do
|
||||
setup do
|
||||
@new_file = upload_file("test/files/test.jpg")
|
||||
@old_file = upload_file("test/files/test.png")
|
||||
travel_to(1.month.ago) do
|
||||
@user = FactoryBot.create(:user)
|
||||
end
|
||||
as_user do
|
||||
@post = FactoryBot.create(:post, md5: Digest::MD5.hexdigest(@old_file.read))
|
||||
@old_md5 = @post.md5
|
||||
@post.stubs(:queue_delete_files)
|
||||
@replacement = FactoryBot.create(:post_replacement, post: @post, replacement_url: "", replacement_file: @new_file)
|
||||
end
|
||||
end
|
||||
|
||||
subject { UploadService::Replacer.new(post: @post, replacement: @replacement) }
|
||||
|
||||
context "#process!" do
|
||||
should "create a new upload" do
|
||||
assert_difference(-> { Upload.count }) do
|
||||
as_user { subject.process! }
|
||||
end
|
||||
end
|
||||
|
||||
should "create a comment" do
|
||||
assert_difference(-> { @post.comments.count }) do
|
||||
as_user { subject.process! }
|
||||
@post.reload
|
||||
end
|
||||
end
|
||||
|
||||
should "not create a new post" do
|
||||
assert_difference(-> { Post.count }, 0) do
|
||||
as_user { subject.process! }
|
||||
end
|
||||
end
|
||||
|
||||
should "update the post's MD5" do
|
||||
assert_changes(-> { @post.md5 }) do
|
||||
as_user { subject.process! }
|
||||
@post.reload
|
||||
end
|
||||
end
|
||||
|
||||
should "preserve the old values" do
|
||||
as_user { subject.process! }
|
||||
assert_equal(1500, @replacement.image_width_was)
|
||||
assert_equal(1000, @replacement.image_height_was)
|
||||
assert_equal(2000, @replacement.file_size_was)
|
||||
assert_equal("jpg", @replacement.file_ext_was)
|
||||
assert_equal(@old_md5, @replacement.md5_was)
|
||||
end
|
||||
|
||||
should "record the new values" do
|
||||
as_user { subject.process! }
|
||||
assert_equal(500, @replacement.image_width)
|
||||
assert_equal(335, @replacement.image_height)
|
||||
assert_equal(28086, @replacement.file_size)
|
||||
assert_equal("jpg", @replacement.file_ext)
|
||||
assert_equal("ecef68c44edb8a0d6a3070b5f8e8ee76", @replacement.md5)
|
||||
end
|
||||
|
||||
should "correctly update the attributes" do
|
||||
as_user { subject.process! }
|
||||
assert_equal(500, @post.image_width)
|
||||
assert_equal(335, @post.image_height)
|
||||
assert_equal(28086, @post.file_size)
|
||||
assert_equal("jpg", @post.file_ext)
|
||||
assert_equal("ecef68c44edb8a0d6a3070b5f8e8ee76", @post.md5)
|
||||
assert(File.exists?(@post.file.path))
|
||||
end
|
||||
end
|
||||
|
||||
context "a post with the same file" do
|
||||
should "not raise a duplicate error" do
|
||||
upload_file("test/files/test.png") do |file|
|
||||
assert_nothing_raised do
|
||||
as_user { @post.replace!(replacement_file: file, replacement_url: "") }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
should "not queue a deletion or log a comment" do
|
||||
upload_file("test/files/test.png") do |file|
|
||||
assert_no_difference(-> { @post.comments.count }) do
|
||||
as_user { @post.replace!(replacement_file: file, replacement_url: "") }
|
||||
@post.reload
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "for a twitter source replacement" do
|
||||
setup do
|
||||
@new_url = "https://pbs.twimg.com/media/B4HSEP5CUAA4xyu.png:orig"
|
||||
|
||||
travel_to(1.month.ago) do
|
||||
@user = FactoryBot.create(:user)
|
||||
end
|
||||
|
||||
as_user do
|
||||
@post = FactoryBot.create(:post, source: "http://blah", file_ext: "jpg", md5: "something", uploader_ip_addr: "127.0.0.2")
|
||||
@post.stubs(:queue_delete_files)
|
||||
@replacement = FactoryBot.create(:post_replacement, post: @post, replacement_url: @new_url)
|
||||
end
|
||||
end
|
||||
|
||||
subject { UploadService::Replacer.new(post: @post, replacement: @replacement) }
|
||||
|
||||
should "replace the post" do
|
||||
as_user { subject.process! }
|
||||
|
||||
@post.reload
|
||||
|
||||
assert_equal(@new_url, @post.replacements.last.replacement_url)
|
||||
end
|
||||
end
|
||||
|
||||
context "for a source replacement" do
|
||||
setup do
|
||||
@new_url = "https://raikou1.donmai.us/d3/4e/d34e4cf0a437a5d65f8e82b7bcd02606.jpg"
|
||||
@new_md5 = "d34e4cf0a437a5d65f8e82b7bcd02606"
|
||||
travel_to(1.month.ago) do
|
||||
@user = FactoryBot.create(:user)
|
||||
end
|
||||
as_user do
|
||||
@post_md5 = "710fd9cba4ef37260f9152ffa9d154d8"
|
||||
@post = FactoryBot.create(:post, source: "https://raikou1.donmai.us/71/0f/#{@post_md5}.png", file_ext: "png", md5: @post_md5, uploader_ip_addr: "127.0.0.2")
|
||||
@post.stubs(:queue_delete_files)
|
||||
@replacement = FactoryBot.create(:post_replacement, post: @post, replacement_url: @new_url)
|
||||
end
|
||||
end
|
||||
|
||||
subject { UploadService::Replacer.new(post: @post, replacement: @replacement) }
|
||||
|
||||
context "when replacing with its own source" do
|
||||
should "work" do
|
||||
as_user { @post.replace!(replacement_url: @post.source) }
|
||||
assert_equal(@post_md5, @post.md5)
|
||||
assert_match(/#{@post_md5}/, @post.file_path)
|
||||
end
|
||||
end
|
||||
|
||||
context "when an upload with the same MD5 already exists" do
|
||||
setup do
|
||||
@post.update(md5: @new_md5)
|
||||
as_user do
|
||||
@post2 = FactoryBot.create(:post)
|
||||
@post2.stubs(:queue_delete_files)
|
||||
end
|
||||
end
|
||||
|
||||
should "throw an error" do
|
||||
assert_raises(UploadService::Replacer::Error) do
|
||||
as_user { @post2.replace!(replacement_url: @new_url) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "a post when given a final_source" do
|
||||
should "change the source to the final_source" do
|
||||
replacement_url = "https://raikou1.donmai.us/fd/b4/fdb47f79fb8da82e66eeb1d84a1cae8d.jpg"
|
||||
final_source = "https://raikou1.donmai.us/71/0f/710fd9cba4ef37260f9152ffa9d154d8.png"
|
||||
|
||||
as_user { @post.replace!(replacement_url: replacement_url, final_source: final_source) }
|
||||
|
||||
assert_equal(final_source, @post.source)
|
||||
end
|
||||
end
|
||||
|
||||
context "#undo!" do
|
||||
setup do
|
||||
@user = travel_to(1.month.ago) { FactoryBot.create(:user) }
|
||||
as_user do
|
||||
@post = FactoryBot.create(:post, source: "https://raikou1.donmai.us/d3/4e/d34e4cf0a437a5d65f8e82b7bcd02606.jpg")
|
||||
@post.stubs(:queue_delete_files)
|
||||
@post.replace!(replacement_url: "https://raikou1.donmai.us/fd/b4/fdb47f79fb8da82e66eeb1d84a1cae8d.jpg", tags: "-tag1 tag2")
|
||||
end
|
||||
|
||||
@replacement = @post.replacements.last
|
||||
end
|
||||
|
||||
should "update the attributes" do
|
||||
as_user do
|
||||
subject.undo!
|
||||
end
|
||||
|
||||
assert_equal("tag2", @post.tag_string)
|
||||
assert_equal(459, @post.image_width)
|
||||
assert_equal(650, @post.image_height)
|
||||
assert_equal(127238, @post.file_size)
|
||||
assert_equal("jpg", @post.file_ext)
|
||||
assert_equal("d34e4cf0a437a5d65f8e82b7bcd02606", @post.md5)
|
||||
assert_equal("d34e4cf0a437a5d65f8e82b7bcd02606", Digest::MD5.file(@post.file).hexdigest)
|
||||
assert_equal("https://raikou1.donmai.us/d3/4e/d34e4cf0a437a5d65f8e82b7bcd02606.jpg", @post.source)
|
||||
end
|
||||
end
|
||||
|
||||
context "#process!" do
|
||||
should "create a new upload" do
|
||||
assert_difference(-> { Upload.count }) do
|
||||
as_user { subject.process! }
|
||||
end
|
||||
end
|
||||
|
||||
should "not create a new post" do
|
||||
assert_difference(-> { Post.count }, 0) do
|
||||
as_user { subject.process! }
|
||||
end
|
||||
end
|
||||
|
||||
should "update the post's MD5" do
|
||||
assert_changes(-> { @post.md5 }) do
|
||||
as_user { subject.process! }
|
||||
@post.reload
|
||||
end
|
||||
end
|
||||
|
||||
should "update the post's source" do
|
||||
assert_changes(-> { @post.source }, nil, from: @post.source, to: @new_url) do
|
||||
as_user { subject.process! }
|
||||
@post.reload
|
||||
end
|
||||
end
|
||||
|
||||
should "not change the post status or uploader" do
|
||||
assert_no_changes(-> { {ip_addr: @post.uploader_ip_addr.to_s, uploader: @post.uploader_id, pending: @post.is_pending?} }) do
|
||||
as_user { subject.process! }
|
||||
@post.reload
|
||||
end
|
||||
end
|
||||
|
||||
should "leave a system comment" do
|
||||
as_user { subject.process! }
|
||||
comment = @post.comments.last
|
||||
assert_not_nil(comment)
|
||||
assert_equal(User.system.id, comment.creator_id)
|
||||
assert_match(/replaced this post/, comment.body)
|
||||
end
|
||||
end
|
||||
|
||||
context "a post with a pixiv html source" do
|
||||
should "replace with the full size image" do
|
||||
begin
|
||||
as_user do
|
||||
@post.replace!(replacement_url: "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247350")
|
||||
end
|
||||
|
||||
assert_equal(80, @post.image_width)
|
||||
assert_equal(82, @post.image_height)
|
||||
assert_equal(16275, @post.file_size)
|
||||
assert_equal("png", @post.file_ext)
|
||||
assert_equal("4ceadc314938bc27f3574053a3e1459a", @post.md5)
|
||||
assert_equal("4ceadc314938bc27f3574053a3e1459a", Digest::MD5.file(@post.file).hexdigest)
|
||||
assert_equal("https://i.pximg.net/img-original/img/2017/04/04/08/54/15/62247350_p0.png", @post.replacements.last.replacement_url)
|
||||
assert_equal("https://i.pximg.net/img-original/img/2017/04/04/08/54/15/62247350_p0.png", @post.source)
|
||||
rescue Net::OpenTimeout
|
||||
skip "Remote connection to Pixiv failed"
|
||||
end
|
||||
end
|
||||
|
||||
# should "delete the old files after thirty days" do
|
||||
# begin
|
||||
# @post.unstub(:queue_delete_files)
|
||||
# FileUtils.expects(:rm_f).times(3)
|
||||
#
|
||||
# as_user { @post.replace!(replacement_url: "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247350") }
|
||||
#
|
||||
# travel_to((PostReplacement::DELETION_GRACE_PERIOD + 1).days.from_now) do
|
||||
# Delayed::Worker.new.work_off
|
||||
# end
|
||||
# rescue Net::OpenTimeout
|
||||
# skip "Remote connection to Pixiv failed"
|
||||
# end
|
||||
# end
|
||||
end
|
||||
|
||||
context "a post that is replaced to another file then replaced back to the original file" do
|
||||
should "not delete the original files" do
|
||||
begin
|
||||
# this is called thrice to delete the file for 62247364
|
||||
FileUtils.expects(:rm_f).times(3)
|
||||
|
||||
as_user do
|
||||
@post.replace!(replacement_url: "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247350")
|
||||
@post.reload
|
||||
@post.replace!(replacement_url: "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247364")
|
||||
@post.reload
|
||||
Upload.destroy_all
|
||||
@post.replace!(replacement_url: "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247350")
|
||||
end
|
||||
|
||||
assert_nothing_raised { @post.file(:original) }
|
||||
assert_nothing_raised { @post.file(:preview) }
|
||||
|
||||
# travel_to((PostReplacement::DELETION_GRACE_PERIOD + 1).days.from_now) do
|
||||
# Delayed::Worker.new.work_off
|
||||
# end
|
||||
#
|
||||
# assert_nothing_raised { @post.file(:original) }
|
||||
# assert_nothing_raised { @post.file(:preview) }
|
||||
rescue Net::OpenTimeout
|
||||
skip "Remote connection to Pixiv failed"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "two posts that have had their files swapped" do
|
||||
setup do
|
||||
as_user do
|
||||
@post1 = FactoryBot.create(:post)
|
||||
@post2 = FactoryBot.create(:post)
|
||||
end
|
||||
end
|
||||
|
||||
should "not delete the still active files" do
|
||||
# swap the images between @post1 and @post2.
|
||||
begin
|
||||
as_user do
|
||||
@post1.replace!(replacement_url: "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247350")
|
||||
@post2.replace!(replacement_url: "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247364")
|
||||
assert_equal("4ceadc314938bc27f3574053a3e1459a", @post1.md5)
|
||||
assert_equal("cad1da177ef309bf40a117c17b8eecf5", @post2.md5)
|
||||
@post2.reload
|
||||
@post2.replace!(replacement_url: "https://raikou1.donmai.us/d3/4e/d34e4cf0a437a5d65f8e82b7bcd02606.jpg")
|
||||
assert_equal("d34e4cf0a437a5d65f8e82b7bcd02606", @post2.md5)
|
||||
Upload.destroy_all
|
||||
@post1.reload
|
||||
@post2.reload
|
||||
@post1.replace!(replacement_url: "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247364")
|
||||
@post2.replace!(replacement_url: "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247350")
|
||||
assert_equal("cad1da177ef309bf40a117c17b8eecf5", @post1.md5)
|
||||
assert_equal("4ceadc314938bc27f3574053a3e1459a", @post2.md5)
|
||||
end
|
||||
|
||||
# Timecop.travel(Time.now + PostReplacement::DELETION_GRACE_PERIOD + 1.day) do
|
||||
# Delayed::Worker.new.work_off
|
||||
# end
|
||||
#
|
||||
# assert_nothing_raised { @post1.file(:original) }
|
||||
# assert_nothing_raised { @post2.file(:original) }
|
||||
rescue Net::OpenTimeout
|
||||
skip "Remote connection to Pixiv failed"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "a post with notes" do
|
||||
setup do
|
||||
Note.any_instance.stubs(:merge_version?).returns(false)
|
||||
|
||||
as_user do
|
||||
@post.update(image_width: 160, image_height: 164)
|
||||
@note = @post.notes.create(x: 80, y: 82, width: 80, height: 82, body: "test")
|
||||
@note.reload
|
||||
end
|
||||
end
|
||||
|
||||
should "rescale the notes" do
|
||||
assert_equal([80, 82, 80, 82], [@note.x, @note.y, @note.width, @note.height])
|
||||
|
||||
begin
|
||||
assert_difference(-> { @note.versions.count }) do
|
||||
# replacement image is 80x82, so we're downscaling by 50% (160x164 -> 80x82).
|
||||
as_user do
|
||||
@post.replace!(
|
||||
replacement_url: "https://i.pximg.net/img-original/img/2017/04/04/08/54/15/62247350_p0.png",
|
||||
final_source: "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247350"
|
||||
)
|
||||
end
|
||||
@note.reload
|
||||
end
|
||||
|
||||
assert_equal([40, 41, 40, 41], [@note.x, @note.y, @note.width, @note.height])
|
||||
assert_equal("https://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247350", @post.source)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "#start!" do
|
||||
subject { UploadService }
|
||||
|
||||
@ -661,7 +278,7 @@ class UploadServiceTest < ActiveSupport::TestCase
|
||||
|
||||
assert_equal(true, upload.valid?)
|
||||
assert_equal("s", upload.rating)
|
||||
assert_equal("rating:safe blah ", upload.tag_string)
|
||||
assert_equal("rating:safe blah", upload.tag_string)
|
||||
|
||||
assert_equal("s", upload.post.rating)
|
||||
assert_equal("blah", upload.post.tag_string)
|
||||
@ -723,33 +340,6 @@ class UploadServiceTest < ActiveSupport::TestCase
|
||||
CurrentUser.ip_addr = nil
|
||||
end
|
||||
|
||||
context "for a pixiv" do
|
||||
setup do
|
||||
@source = "https://i.pximg.net/img-original/img/2017/11/21/05/12/37/65981735_p0.jpg"
|
||||
@upload = FactoryBot.create(:jpg_upload, file_size: 1000, md5: "12345", file_ext: "jpg", image_width: 100, image_height: 100, source: @source)
|
||||
end
|
||||
|
||||
should "record the canonical source" do
|
||||
begin
|
||||
post = subject.new({}).create_post_from_upload(@upload)
|
||||
assert_equal(@source, post.source)
|
||||
rescue Net::OpenTimeout
|
||||
skip "network failure"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "for nijie" do
|
||||
should "record the canonical source" do
|
||||
page_url = "https://nijie.info/view.php?id=728995"
|
||||
image_url = "https://pic03.nijie.info/nijie_picture/728995_20170505014820_0.jpg"
|
||||
upload = FactoryBot.create(:jpg_upload, file_size: 1000, md5: "12345", file_ext: "jpg", image_width: 100, image_height: 100, source: image_url)
|
||||
|
||||
post = UploadService.new({}).create_post_from_upload(upload)
|
||||
assert_equal(page_url, post.source)
|
||||
end
|
||||
end
|
||||
|
||||
context "for an image" do
|
||||
setup do
|
||||
@upload = FactoryBot.create(:source_upload, file_size: 1000, md5: "12345", file_ext: "jpg", image_width: 100, image_height: 100)
|
||||
|
@ -16,7 +16,7 @@ class AliasAndImplicationImporterTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
@tag = Tag.find_or_create_by_name("hello")
|
||||
@list = "category hello -> artist\n"
|
||||
@importer = AliasAndImplicationImporter.new(@list, nil)
|
||||
@importer = AliasAndImplicationImporter.new(nil, @list, nil)
|
||||
end
|
||||
|
||||
should "work" do
|
||||
@ -41,7 +41,7 @@ class AliasAndImplicationImporterTest < ActiveSupport::TestCase
|
||||
"mass update eee -> 444\n"
|
||||
end
|
||||
|
||||
subject { AliasAndImplicationImporter.new(@script, nil) }
|
||||
subject { AliasAndImplicationImporter.new(nil, @script, nil) }
|
||||
|
||||
should "return the correct count" do
|
||||
assert_equal(3, subject.estimate_update_count)
|
||||
@ -51,7 +51,7 @@ class AliasAndImplicationImporterTest < ActiveSupport::TestCase
|
||||
context "given a valid list" do
|
||||
setup do
|
||||
@list = "create alias abc -> def\ncreate implication aaa -> bbb\n"
|
||||
@importer = AliasAndImplicationImporter.new(@list, nil)
|
||||
@importer = AliasAndImplicationImporter.new(nil, @list, nil)
|
||||
end
|
||||
|
||||
should "process it" do
|
||||
@ -64,7 +64,7 @@ class AliasAndImplicationImporterTest < ActiveSupport::TestCase
|
||||
context "given a list with an invalid command" do
|
||||
setup do
|
||||
@list = "zzzz abc -> def\n"
|
||||
@importer = AliasAndImplicationImporter.new(@list, nil)
|
||||
@importer = AliasAndImplicationImporter.new(nil, @list, nil)
|
||||
end
|
||||
|
||||
should "throw an exception" do
|
||||
@ -77,7 +77,7 @@ class AliasAndImplicationImporterTest < ActiveSupport::TestCase
|
||||
context "given a list with a logic error" do
|
||||
setup do
|
||||
@list = "remove alias zzz -> yyy\n"
|
||||
@importer = AliasAndImplicationImporter.new(@list, nil)
|
||||
@importer = AliasAndImplicationImporter.new(nil, @list, nil)
|
||||
end
|
||||
|
||||
should "throw an exception" do
|
||||
@ -91,7 +91,7 @@ class AliasAndImplicationImporterTest < ActiveSupport::TestCase
|
||||
tag1 = FactoryBot.create(:tag, :name => "aaa", :category => 1)
|
||||
tag2 = FactoryBot.create(:tag, :name => "bbb")
|
||||
artist = FactoryBot.create(:artist, :name => "aaa", :notes => "testing")
|
||||
@importer = AliasAndImplicationImporter.new("create alias aaa -> bbb", "", "1")
|
||||
@importer = AliasAndImplicationImporter.new(nil, "create alias aaa -> bbb", "", "1")
|
||||
@importer.process!
|
||||
artist.reload
|
||||
assert_equal("bbb", artist.name)
|
||||
@ -106,7 +106,7 @@ class AliasAndImplicationImporterTest < ActiveSupport::TestCase
|
||||
remove alias a -> b
|
||||
remove implication c -> d
|
||||
}
|
||||
@importer = AliasAndImplicationImporter.new(@script, nil)
|
||||
@importer = AliasAndImplicationImporter.new(nil, @script, nil)
|
||||
end
|
||||
|
||||
should "set aliases and implications as deleted" do
|
||||
|
@ -157,7 +157,7 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "downcase the text" do
|
||||
assert_equal("create alias aaa -> bbb", @req.script)
|
||||
assert_equal("alias aaa -> bbb", @req.script)
|
||||
end
|
||||
|
||||
should "update the topic when processed" do
|
||||
|
@ -92,32 +92,6 @@ module PostSets
|
||||
end
|
||||
end
|
||||
|
||||
context "a set for the 'a b c' tag query" do
|
||||
setup do
|
||||
@set = PostSets::Post.new("a b c")
|
||||
end
|
||||
|
||||
context "for a non-gold user" do
|
||||
should "fail" do
|
||||
assert_raises(::Post::SearchError) do
|
||||
@set.posts
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "for a gold user" do
|
||||
setup do
|
||||
CurrentUser.user = FactoryBot.create(:privileged_user)
|
||||
end
|
||||
|
||||
should "pass" do
|
||||
assert_nothing_raised do
|
||||
@set.posts
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "a set for the 'a' tag query" do
|
||||
setup do
|
||||
@set = PostSets::Post.new("a")
|
||||
|
@ -2030,7 +2030,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
replacement1 = FactoryBot.create(:png_replacement, creator: @user, creator_ip_addr: '127.0.0.1', post: post1)
|
||||
replacement1.reject!
|
||||
replacement2 = FactoryBot.create(:png_replacement, creator: @user, creator_ip_addr: '127.0.0.1', post: post2)
|
||||
replacement2.approve!
|
||||
replacement2.approve! penalize_current_uploader: true
|
||||
replacement3 = FactoryBot.create(:png_replacement, creator: @user, creator_ip_addr: '127.0.0.1', post: post3)
|
||||
replacement3.promote!
|
||||
replacement4 = FactoryBot.create(:png_replacement, creator: @user, creator_ip_addr: '127.0.0.1', post: post4)
|
||||
@ -2285,29 +2285,28 @@ class PostTest < ActiveSupport::TestCase
|
||||
|
||||
assert_equal("https://#{Danbooru.config.hostname}/data/preview/deadbeef.jpg", @post.preview_file_url)
|
||||
|
||||
assert_equal("https://#{Socket.gethostname}/data/deadbeef.gif", @post.large_file_url)
|
||||
assert_equal("https://#{Socket.gethostname}/data/deadbeef.gif", @post.file_url)
|
||||
end
|
||||
assert_equal("https://#{Socket.gethostname}/data/deadbeef.gif", @post.large_file_url)
|
||||
assert_equal("https://#{Socket.gethostname}/data/deadbeef.gif", @post.file_url)
|
||||
end
|
||||
end
|
||||
|
||||
context "Notes:" do
|
||||
context "#copy_notes_to" do
|
||||
setup do
|
||||
@src = FactoryBot.create(:post, image_width: 100, image_height: 100, tag_string: "translated partially_translated")
|
||||
@dst = FactoryBot.create(:post, image_width: 200, image_height: 200, tag_string: "translation_request")
|
||||
|
||||
@src.notes.create(x: 10, y: 10, width: 10, height: 10, body: "test")
|
||||
@src.notes.create(x: 10, y: 10, width: 10, height: 10, body: "deleted", is_active: false)
|
||||
@src.reload
|
||||
|
||||
@src.copy_notes_to(@dst)
|
||||
end
|
||||
|
||||
context "Notes:" do
|
||||
context "#copy_notes_to" do
|
||||
setup do
|
||||
@src = FactoryBot.create(:post, image_width: 100, image_height: 100, tag_string: "translated partially_translated", has_embedded_notes: true)
|
||||
@dst = FactoryBot.create(:post, image_width: 200, image_height: 200, tag_string: "translation_request")
|
||||
|
||||
@src.notes.create(x: 10, y: 10, width: 10, height: 10, body: "test")
|
||||
@src.notes.create(x: 10, y: 10, width: 10, height: 10, body: "deleted", is_active: false)
|
||||
@src.reload
|
||||
|
||||
@src.copy_notes_to(@dst)
|
||||
end
|
||||
|
||||
should "copy notes and tags" do
|
||||
assert_equal(1, @dst.notes.active.length)
|
||||
assert_equal(true, @dst.has_embedded_notes)
|
||||
assert_equal("lowres partially_translated translated", @dst.tag_string)
|
||||
end
|
||||
should "copy notes and tags" do
|
||||
assert_equal(1, @dst.notes.active.length)
|
||||
assert_equal("low_res partially_translated thumbnail translated", @dst.tag_string)
|
||||
end
|
||||
|
||||
should "rescale notes" do
|
||||
note = @dst.notes.active.first
|
||||
|
@ -7,7 +7,9 @@ class SessionLoaderTest < ActiveSupport::TestCase
|
||||
@request.stubs(:host).returns("danbooru")
|
||||
@request.stubs(:remote_ip).returns("127.0.0.1")
|
||||
@request.stubs(:authorization).returns(nil)
|
||||
@request.stubs(:cookie_jar).returns({})
|
||||
cookie_jar = mock
|
||||
cookie_jar.stubs(:encrypted).returns({})
|
||||
@request.stubs(:cookie_jar).returns(cookie_jar)
|
||||
@request.stubs(:parameters).returns({})
|
||||
@request.stubs(:session).returns({})
|
||||
end
|
||||
@ -19,15 +21,15 @@ class SessionLoaderTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
context ".safe_mode?" do
|
||||
should "return true if the host contains the string safebooru" do
|
||||
@request.stubs(:host).returns("safebooru")
|
||||
should "return true if the config has safe mode enabled" do
|
||||
Danbooru.config.stubs(:safe_mode?).returns(true)
|
||||
SessionLoader.new(@request).load
|
||||
|
||||
assert_equal(true, CurrentUser.safe_mode?)
|
||||
end
|
||||
|
||||
should "return false if the host contains the string danbooru" do
|
||||
@request.stubs(:host).returns("danbooru")
|
||||
should "return false if the config has safe mode disabled" do
|
||||
Danbooru.config.stubs(:safe_mode?).returns(false)
|
||||
SessionLoader.new(@request).load
|
||||
|
||||
assert_equal(false, CurrentUser.safe_mode?)
|
||||
|
@ -1,7 +1,6 @@
|
||||
require 'test_helper'
|
||||
|
||||
class TagImplicationTest < ActiveSupport::TestCase
|
||||
|
||||
setup do
|
||||
Sidekiq::Testing.inline!
|
||||
end
|
||||
@ -51,15 +50,10 @@ class TagImplicationTest < ActiveSupport::TestCase
|
||||
should_not allow_value(-1).for(:creator_id).with_message("must exist", against: :creator)
|
||||
|
||||
should "not allow duplicate active implications" do
|
||||
ti1 = FactoryBot.create(:tag_implication, antecedent_name: "aaa", consequent_name: "bbb", status: "active")
|
||||
ti2 = FactoryBot.create(:tag_implication, antecedent_name: "aaa", consequent_name: "bbb", status: "retired")
|
||||
ti3 = FactoryBot.create(:tag_implication, antecedent_name: "aaa", consequent_name: "bbb", status: "deleted")
|
||||
ti4 = FactoryBot.create(:tag_implication, antecedent_name: "aaa", consequent_name: "bbb", status: "deleted")
|
||||
ti5 = FactoryBot.create(:tag_implication, antecedent_name: "aaa", consequent_name: "bbb", status: "pending")
|
||||
[ti1, ti2, ti3, ti4, ti5].each { |ti| assert(ti.valid?) }
|
||||
|
||||
ti5.update(status: "active")
|
||||
assert_includes(ti5.errors[:antecedent_name], "has already been taken")
|
||||
ti1 = FactoryBot.create(:tag_implication, antecedent_name: "aaa", consequent_name: "bbb", status: "pending")
|
||||
ti2 = FactoryBot.build(:tag_implication, antecedent_name: "aaa", consequent_name: "bbb", status: "active")
|
||||
ti2.save
|
||||
assert_match(/Antecedent name has already been taken/, ti2.errors.full_messages.join)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -15,14 +15,14 @@ class UploadWhitelistTest < ActiveSupport::TestCase
|
||||
CurrentUser.ip_addr = nil
|
||||
end
|
||||
should "match" do
|
||||
assert_equal([true, nil], UploadWhitelist.is_whitelisted?("https://static1.e621.net/data/123.png"))
|
||||
assert_equal([false, "not found"], UploadWhitelist.is_whitelisted?("https://123.com/what.png"))
|
||||
assert_equal([true, nil], UploadWhitelist.is_whitelisted?(Addressable::URI.parse("https://static1.e621.net/data/123.png")))
|
||||
assert_equal([false, "123.com not in whitelist"], UploadWhitelist.is_whitelisted?(Addressable::URI.parse("https://123.com/what.png")))
|
||||
end
|
||||
|
||||
should "bypass for admins" do
|
||||
CurrentUser.user.level = 50
|
||||
Danbooru.config.stubs(:bypass_upload_whitelist?).returns(true)
|
||||
assert_equal([true, "bypassed"], UploadWhitelist.is_whitelisted?("https://123.com/what.png"))
|
||||
assert_equal([true, "bypassed"], UploadWhitelist.is_whitelisted?(Addressable::URI.parse("https://123.com/what.png")))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -105,7 +105,8 @@ class UserTest < ActiveSupport::TestCase
|
||||
assert_equal(@user.can_forum_post_with_reason, :REJ_NEWBIE)
|
||||
@user.update_column(:created_at, 1.year.ago)
|
||||
topic = FactoryBot.create(:forum_topic)
|
||||
Danbooru.config.member_comment_limit.times do
|
||||
# Creating a topic automatically creates a post
|
||||
(Danbooru.config.member_comment_limit - 1).times do
|
||||
FactoryBot.create(:forum_post, :topic_id => topic.id)
|
||||
end
|
||||
assert_equal(@user.can_forum_post_with_reason, :REJ_LIMITED)
|
||||
|
Loading…
Reference in New Issue
Block a user