tests: fix various broken tests.
This commit is contained in:
@@ -16,7 +16,7 @@ class PostReplacementsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
format: :json,
|
format: :json,
|
||||||
post_id: @post.id,
|
post_id: @post.id,
|
||||||
post_replacement: {
|
post_replacement: {
|
||||||
replacement_url: "https://raikou1.donmai.us/d3/4e/d34e4cf0a437a5d65f8e82b7bcd02606.jpg"
|
replacement_url: "https://cdn.donmai.us/original/d3/4e/d34e4cf0a437a5d65f8e82b7bcd02606.jpg"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ class PostReplacementsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
perform_enqueued_jobs
|
perform_enqueued_jobs
|
||||||
|
|
||||||
assert_response :success
|
assert_response :success
|
||||||
assert_equal("https://raikou1.donmai.us/d3/4e/d34e4cf0a437a5d65f8e82b7bcd02606.jpg", @post.source)
|
assert_equal("https://cdn.donmai.us/original/d3/4e/d34e4cf0a437a5d65f8e82b7bcd02606.jpg", @post.source)
|
||||||
assert_equal("d34e4cf0a437a5d65f8e82b7bcd02606", @post.md5)
|
assert_equal("d34e4cf0a437a5d65f8e82b7bcd02606", @post.md5)
|
||||||
assert_equal("d34e4cf0a437a5d65f8e82b7bcd02606", Digest::MD5.file(@post.file(:original)).hexdigest)
|
assert_equal("d34e4cf0a437a5d65f8e82b7bcd02606", Digest::MD5.file(@post.file(:original)).hexdigest)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
context "preprocess action" do
|
context "preprocess action" do
|
||||||
should "prefer the file over the source when preprocessing" do
|
should "prefer the file over the source when preprocessing" do
|
||||||
file = Rack::Test::UploadedFile.new("#{Rails.root}/test/files/test.jpg", "image/jpeg")
|
file = Rack::Test::UploadedFile.new("#{Rails.root}/test/files/test.jpg", "image/jpeg")
|
||||||
post_auth preprocess_uploads_path, @user, params: {:upload => {:source => "https://raikou1.donmai.us/d3/4e/d34e4cf0a437a5d65f8e82b7bcd02606.jpg", :file => file}}
|
post_auth preprocess_uploads_path, @user, params: {:upload => {:source => "https://cdn.donmai.us/original/d3/4e/d34e4cf0a437a5d65f8e82b7bcd02606.jpg", :file => file}}
|
||||||
assert_response :success
|
assert_response :success
|
||||||
perform_enqueued_jobs
|
perform_enqueued_jobs
|
||||||
assert_equal("ecef68c44edb8a0d6a3070b5f8e8ee76", Upload.last.md5)
|
assert_equal("ecef68c44edb8a0d6a3070b5f8e8ee76", Upload.last.md5)
|
||||||
@@ -51,18 +51,18 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
context "with a url" do
|
context "with a url" do
|
||||||
should "preprocess" do
|
should "preprocess" do
|
||||||
assert_difference(-> { Upload.count }) do
|
assert_difference(-> { Upload.count }) do
|
||||||
get_auth new_upload_path, @user, params: {:url => "https://raikou1.donmai.us/d3/4e/d34e4cf0a437a5d65f8e82b7bcd02606.jpg"}
|
get_auth new_upload_path, @user, params: {:url => "https://cdn.donmai.us/original/d3/4e/d34e4cf0a437a5d65f8e82b7bcd02606.jpg"}
|
||||||
perform_enqueued_jobs
|
perform_enqueued_jobs
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
should "prefer the file" do
|
should "prefer the file" do
|
||||||
get_auth new_upload_path, @user, params: {url: "https://raikou1.donmai.us/d3/4e/d34e4cf0a437a5d65f8e82b7bcd02606.jpg"}
|
get_auth new_upload_path, @user, params: {url: "https://cdn.donmai.us/original/d3/4e/d34e4cf0a437a5d65f8e82b7bcd02606.jpg"}
|
||||||
perform_enqueued_jobs
|
perform_enqueued_jobs
|
||||||
file = Rack::Test::UploadedFile.new("#{Rails.root}/test/files/test.jpg", "image/jpeg")
|
file = Rack::Test::UploadedFile.new("#{Rails.root}/test/files/test.jpg", "image/jpeg")
|
||||||
assert_difference(-> { Post.count }) do
|
assert_difference(-> { Post.count }) do
|
||||||
post_auth uploads_path, @user, params: {upload: {file: file, tag_string: "aaa", rating: "q", source: "https://raikou1.donmai.us/d3/4e/d34e4cf0a437a5d65f8e82b7bcd02606.jpg"}}
|
post_auth uploads_path, @user, params: {upload: {file: file, tag_string: "aaa", rating: "q", source: "https://cdn.donmai.us/original/d3/4e/d34e4cf0a437a5d65f8e82b7bcd02606.jpg"}}
|
||||||
end
|
end
|
||||||
post = Post.last
|
post = Post.last
|
||||||
assert_equal("ecef68c44edb8a0d6a3070b5f8e8ee76", post.md5)
|
assert_equal("ecef68c44edb8a0d6a3070b5f8e8ee76", post.md5)
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
|
|||||||
|
|
||||||
should "redirect anonymous users to the sign in page" do
|
should "redirect anonymous users to the sign in page" do
|
||||||
get profile_path
|
get profile_path
|
||||||
assert_redirected_to new_session_path
|
assert_redirected_to login_path(url: "/profile")
|
||||||
end
|
end
|
||||||
|
|
||||||
should "return 404 for anonymous api calls" do
|
should "return 404 for anonymous api calls" do
|
||||||
@@ -150,7 +150,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
|
|||||||
|
|
||||||
should "redirect anonymous users to the sign in page" do
|
should "redirect anonymous users to the sign in page" do
|
||||||
get settings_path
|
get settings_path
|
||||||
assert_redirected_to new_session_path
|
assert_redirected_to login_path(url: "/settings")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ class UploadServiceTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
context "for a corrupt jpeg" do
|
context "for a corrupt jpeg" do
|
||||||
setup do
|
setup do
|
||||||
@source = "https://raikou1.donmai.us/93/f4/93f4dd66ef1eb11a89e56d31f9adc8d0.jpg"
|
@source = "https://cdn.donmai.us/original/93/f4/93f4dd66ef1eb11a89e56d31f9adc8d0.jpg"
|
||||||
@mock_upload = mock("upload")
|
@mock_upload = mock("upload")
|
||||||
@mock_upload.stubs(:source_url).returns(@source)
|
@mock_upload.stubs(:source_url).returns(@source)
|
||||||
@mock_upload.stubs(:referer_url).returns(nil)
|
@mock_upload.stubs(:referer_url).returns(nil)
|
||||||
@@ -466,7 +466,7 @@ class UploadServiceTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
context "for null" do
|
context "for null" do
|
||||||
setup do
|
setup do
|
||||||
@source = "https://raikou1.donmai.us/93/f4/93f4dd66ef1eb11a89e56d31f9adc8d0.jpg"
|
@source = "https://cdn.donmai.us/original/93/f4/93f4dd66ef1eb11a89e56d31f9adc8d0.jpg"
|
||||||
end
|
end
|
||||||
|
|
||||||
should "download the file" do
|
should "download the file" do
|
||||||
@@ -488,7 +488,7 @@ class UploadServiceTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
context "for a video" do
|
context "for a video" do
|
||||||
setup do
|
setup do
|
||||||
@source = "https://raikou2.donmai.us/b7/cb/b7cb80092be273771510952812380fa2.mp4"
|
@source = "https://cdn.donmai.us/original/b7/cb/b7cb80092be273771510952812380fa2.mp4"
|
||||||
end
|
end
|
||||||
|
|
||||||
should "work for a video" do
|
should "work for a video" do
|
||||||
@@ -506,7 +506,7 @@ class UploadServiceTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
context "on timeout errors" do
|
context "on timeout errors" do
|
||||||
setup do
|
setup do
|
||||||
@source = "https://raikou1.donmai.us/93/f4/93f4dd66ef1eb11a89e56d31f9adc8d0.jpg"
|
@source = "https://cdn.donmai.us/original/93/f4/93f4dd66ef1eb11a89e56d31f9adc8d0.jpg"
|
||||||
HTTParty.stubs(:get).raises(Net::ReadTimeout)
|
HTTParty.stubs(:get).raises(Net::ReadTimeout)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -666,14 +666,14 @@ class UploadServiceTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
context "for a source replacement" do
|
context "for a source replacement" do
|
||||||
setup do
|
setup do
|
||||||
@new_url = "https://raikou1.donmai.us/d3/4e/d34e4cf0a437a5d65f8e82b7bcd02606.jpg"
|
@new_url = "https://cdn.donmai.us/original/d3/4e/d34e4cf0a437a5d65f8e82b7bcd02606.jpg"
|
||||||
@new_md5 = "d34e4cf0a437a5d65f8e82b7bcd02606"
|
@new_md5 = "d34e4cf0a437a5d65f8e82b7bcd02606"
|
||||||
travel_to(1.month.ago) do
|
travel_to(1.month.ago) do
|
||||||
@user = FactoryBot.create(:user)
|
@user = FactoryBot.create(:user)
|
||||||
end
|
end
|
||||||
as_user do
|
as_user do
|
||||||
@post_md5 = "710fd9cba4ef37260f9152ffa9d154d8"
|
@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 = FactoryBot.create(:post, source: "https://cdn.donmai.us/original/71/0f/#{@post_md5}.png", file_ext: "png", md5: @post_md5, uploader_ip_addr: "127.0.0.2")
|
||||||
@post.stubs(:queue_delete_files)
|
@post.stubs(:queue_delete_files)
|
||||||
@replacement = FactoryBot.create(:post_replacement, post: @post, replacement_url: @new_url)
|
@replacement = FactoryBot.create(:post_replacement, post: @post, replacement_url: @new_url)
|
||||||
end
|
end
|
||||||
@@ -707,8 +707,8 @@ class UploadServiceTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
context "a post when given a final_source" do
|
context "a post when given a final_source" do
|
||||||
should "change the source to the final_source" do
|
should "change the source to the final_source" do
|
||||||
replacement_url = "https://raikou1.donmai.us/fd/b4/fdb47f79fb8da82e66eeb1d84a1cae8d.jpg"
|
replacement_url = "https://cdn.donmai.us/original/fd/b4/fdb47f79fb8da82e66eeb1d84a1cae8d.jpg"
|
||||||
final_source = "https://raikou1.donmai.us/71/0f/710fd9cba4ef37260f9152ffa9d154d8.png"
|
final_source = "https://cdn.donmai.us/original/71/0f/710fd9cba4ef37260f9152ffa9d154d8.png"
|
||||||
|
|
||||||
as_user { @post.replace!(replacement_url: replacement_url, final_source: final_source) }
|
as_user { @post.replace!(replacement_url: replacement_url, final_source: final_source) }
|
||||||
|
|
||||||
@@ -731,9 +731,9 @@ class UploadServiceTest < ActiveSupport::TestCase
|
|||||||
setup do
|
setup do
|
||||||
@user = travel_to(1.month.ago) { FactoryBot.create(:user) }
|
@user = travel_to(1.month.ago) { FactoryBot.create(:user) }
|
||||||
as_user do
|
as_user do
|
||||||
@post = FactoryBot.create(:post, source: "https://raikou1.donmai.us/d3/4e/d34e4cf0a437a5d65f8e82b7bcd02606.jpg")
|
@post = FactoryBot.create(:post, source: "https://cdn.donmai.us/original/d3/4e/d34e4cf0a437a5d65f8e82b7bcd02606.jpg")
|
||||||
@post.stubs(:queue_delete_files)
|
@post.stubs(:queue_delete_files)
|
||||||
@post.replace!(replacement_url: "https://raikou1.donmai.us/fd/b4/fdb47f79fb8da82e66eeb1d84a1cae8d.jpg", tags: "-tag1 tag2")
|
@post.replace!(replacement_url: "https://cdn.donmai.us/original/fd/b4/fdb47f79fb8da82e66eeb1d84a1cae8d.jpg", tags: "-tag1 tag2")
|
||||||
end
|
end
|
||||||
|
|
||||||
@replacement = @post.replacements.last
|
@replacement = @post.replacements.last
|
||||||
@@ -751,7 +751,7 @@ class UploadServiceTest < ActiveSupport::TestCase
|
|||||||
assert_equal("jpg", @post.file_ext)
|
assert_equal("jpg", @post.file_ext)
|
||||||
assert_equal("d34e4cf0a437a5d65f8e82b7bcd02606", @post.md5)
|
assert_equal("d34e4cf0a437a5d65f8e82b7bcd02606", @post.md5)
|
||||||
assert_equal("d34e4cf0a437a5d65f8e82b7bcd02606", Digest::MD5.file(@post.file).hexdigest)
|
assert_equal("d34e4cf0a437a5d65f8e82b7bcd02606", Digest::MD5.file(@post.file).hexdigest)
|
||||||
assert_equal("https://raikou1.donmai.us/d3/4e/d34e4cf0a437a5d65f8e82b7bcd02606.jpg", @post.source)
|
assert_equal("https://cdn.donmai.us/original/d3/4e/d34e4cf0a437a5d65f8e82b7bcd02606.jpg", @post.source)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -916,7 +916,7 @@ class UploadServiceTest < ActiveSupport::TestCase
|
|||||||
assert_equal("cad1da177ef309bf40a117c17b8eecf5", @post2.md5)
|
assert_equal("cad1da177ef309bf40a117c17b8eecf5", @post2.md5)
|
||||||
|
|
||||||
@post2.reload
|
@post2.reload
|
||||||
@post2.replace!(replacement_url: "https://raikou1.donmai.us/d3/4e/d34e4cf0a437a5d65f8e82b7bcd02606.jpg")
|
@post2.replace!(replacement_url: "https://cdn.donmai.us/original/d3/4e/d34e4cf0a437a5d65f8e82b7bcd02606.jpg")
|
||||||
assert_equal("d34e4cf0a437a5d65f8e82b7bcd02606", @post2.md5)
|
assert_equal("d34e4cf0a437a5d65f8e82b7bcd02606", @post2.md5)
|
||||||
Upload.destroy_all
|
Upload.destroy_all
|
||||||
@post1.reload
|
@post1.reload
|
||||||
@@ -948,7 +948,7 @@ class UploadServiceTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
as_user do
|
as_user do
|
||||||
@post.update(image_width: 160, image_height: 164)
|
@post.update(image_width: 160, image_height: 164)
|
||||||
@note = @post.notes.create(x: 80, y: 82, width: 80, height: 82, body: "test")
|
@note = @post.notes.create(x: 80, y: 82, width: 80, height: 82, body: "test", creator: @post.uploader)
|
||||||
@note.reload
|
@note.reload
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -980,7 +980,7 @@ class UploadServiceTest < ActiveSupport::TestCase
|
|||||||
subject { UploadService }
|
subject { UploadService }
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
@source = "https://raikou1.donmai.us/d3/4e/d34e4cf0a437a5d65f8e82b7bcd02606.jpg"
|
@source = "https://cdn.donmai.us/original/d3/4e/d34e4cf0a437a5d65f8e82b7bcd02606.jpg"
|
||||||
CurrentUser.user = travel_to(1.month.ago) do
|
CurrentUser.user = travel_to(1.month.ago) do
|
||||||
FactoryBot.create(:user)
|
FactoryBot.create(:user)
|
||||||
end
|
end
|
||||||
@@ -1094,8 +1094,8 @@ class UploadServiceTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
context "with a source containing unicode characters" do
|
context "with a source containing unicode characters" do
|
||||||
should "upload successfully" do
|
should "upload successfully" do
|
||||||
source1 = "https://raikou1.donmai.us/d3/4e/d34e4cf0a437a5d65f8e82b7bcd02606.jpg?one=東方&two=a%20b"
|
source1 = "https://cdn.donmai.us/original/d3/4e/d34e4cf0a437a5d65f8e82b7bcd02606.jpg?one=東方&two=a%20b"
|
||||||
source2 = "https://raikou1.donmai.us/d3/4e/d34e4cf0a437a5d65f8e82b7bcd02606.jpg?one=%E6%9D%B1%E6%96%B9&two=a%20b"
|
source2 = "https://cdn.donmai.us/original/d3/4e/d34e4cf0a437a5d65f8e82b7bcd02606.jpg?one=%E6%9D%B1%E6%96%B9&two=a%20b"
|
||||||
service = subject.new(source: source1, rating: "s")
|
service = subject.new(source: source1, rating: "s")
|
||||||
|
|
||||||
assert_nothing_raised { @upload = service.start! }
|
assert_nothing_raised { @upload = service.start! }
|
||||||
|
|||||||
Reference in New Issue
Block a user