Replace the old IQDB API client with a new client for the new forked version of IQDB at https://github.com/danbooru/iqdb. Changes: * The /iqdb_queries endpoint now returns `hash` and `signature` fields. The `signature` is the full decoded Haar signature, while the `hash` is a encoded version of the signature. * The /iqdb_queries endpoint no longer returns `width` and `height` fields in the response (these were always 128x128). * We no longer need the IQDBs frontend server, now we talk to the IQDB instance directly. * We no longer send add/remove image commands to IQDB through AWS SQS, now we send them to IQDB directly. They are sent in a delayed job so that if IQDB is down, uploading images is still possible, the add image commands will just get queued up. * Fix a bug where regenerating an image's thumbnails didn't regenerate IQDB, because IQDB silently ignored add image commands when the image already existed in the database.
65 lines
2.4 KiB
Ruby
65 lines
2.4 KiB
Ruby
require 'test_helper'
|
|
|
|
class PostRegenerationsControllerTest < ActionDispatch::IntegrationTest
|
|
context "The post regenerations controller" do
|
|
setup do
|
|
@mod = create(:moderator_user, name: "yukari", created_at: 1.month.ago)
|
|
@upload = assert_successful_upload("test/files/test.jpg", user: @mod)
|
|
@post = @upload.post
|
|
perform_enqueued_jobs # add post to iqdb
|
|
end
|
|
|
|
context "create action" do
|
|
should "render" do
|
|
post_auth post_regenerations_path, @mod, params: { post_id: @post.id, category: "iqdb" }
|
|
|
|
assert_redirected_to @post
|
|
assert_enqueued_jobs(1, only: RegeneratePostJob)
|
|
end
|
|
|
|
should "not allow non-mods to regenerate posts" do
|
|
post_auth post_regenerations_path, create(:user), params: { post_id: @post.id, category: "iqdb" }
|
|
assert_response 403
|
|
end
|
|
|
|
context "for an IQDB regeneration" do
|
|
should "regenerate IQDB" do
|
|
post_auth post_regenerations_path, @mod, params: { post_id: @post.id, category: "iqdb" }
|
|
perform_enqueued_jobs
|
|
end
|
|
|
|
should "log a mod action" do
|
|
post_auth post_regenerations_path, @mod, params: { post_id: @post.id, category: "iqdb" }
|
|
perform_enqueued_jobs
|
|
|
|
assert_equal(@mod, ModAction.last.creator)
|
|
assert_equal("post_regenerate_iqdb", ModAction.last.category)
|
|
assert_equal("<@#{@mod.name}> regenerated IQDB for post ##{@post.id}", ModAction.last.description)
|
|
end
|
|
end
|
|
|
|
context "for an image sample regeneration" do
|
|
should "regenerate missing thumbnails" do
|
|
@preview_file_size = @post.file(:preview).size
|
|
@post.storage_manager.delete_file(@post.id, @post.md5, @post.file_ext, :preview)
|
|
assert_raise(Errno::ENOENT) { @post.file(:preview) }
|
|
|
|
post_auth post_regenerations_path, @mod, params: { post_id: @post.id }
|
|
perform_enqueued_jobs
|
|
|
|
assert_equal(@preview_file_size, @post.file(:preview).size)
|
|
end
|
|
|
|
should "log a mod action" do
|
|
post_auth post_regenerations_path, @mod, params: { post_id: @post.id }
|
|
perform_enqueued_jobs
|
|
|
|
assert_equal(@mod, ModAction.last.creator)
|
|
assert_equal("post_regenerate", ModAction.last.category)
|
|
assert_equal("<@#{@mod.name}> regenerated image samples for post ##{@post.id}", ModAction.last.description)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|