Files
danbooru/test/functional/post_replacements_controller_test.rb
evazion 0a6661d145 uploads: switch to active job.
* Switch upload processing from DelayedJob to ActiveJob.
* Remove remaining references to delayed job from tests.

Closes #4128.
2019-09-23 15:11:18 -05:00

64 lines
1.9 KiB
Ruby

require 'test_helper'
class PostReplacementsControllerTest < ActionDispatch::IntegrationTest
context "The post replacements controller" do
setup do
@user = create(:moderator_user, can_approve_posts: true, created_at: 1.month.ago)
@user.as_current do
@post = create(:post, source: "https://google.com")
@post_replacement = create(:post_replacement, post: @post)
end
end
context "create action" do
should "render" do
params = {
format: :json,
post_id: @post.id,
post_replacement: {
replacement_url: "https://raikou1.donmai.us/d3/4e/d34e4cf0a437a5d65f8e82b7bcd02606.jpg",
}
}
assert_difference(-> { @post.replacements.size }) do
post_auth post_replacements_path, @user, params: params
@post.reload
end
travel(PostReplacement::DELETION_GRACE_PERIOD + 1.day)
perform_enqueued_jobs
assert_response :success
assert_equal("https://raikou1.donmai.us/d3/4e/d34e4cf0a437a5d65f8e82b7bcd02606.jpg", @post.source)
assert_equal("d34e4cf0a437a5d65f8e82b7bcd02606", @post.md5)
assert_equal("d34e4cf0a437a5d65f8e82b7bcd02606", Digest::MD5.file(@post.file(:original)).hexdigest)
end
end
context "update action" do
should "update the replacement" do
params = {
format: :json,
id: @post_replacement.id,
post_replacement: {
file_size_was: 23,
file_size: 42,
}
}
put_auth post_replacement_path(@post_replacement), @user, params: params
@post_replacement.reload
assert_equal(23, @post_replacement.file_size_was)
assert_equal(42, @post_replacement.file_size)
end
end
context "index action" do
should "render" do
get post_replacements_path, params: {format: "json"}
assert_response :success
end
end
end
end