handle the case where a file is uploaded that doesn't match whatever was preprocessed

This commit is contained in:
Albert Yi
2018-07-02 14:47:23 -07:00
parent 9a522d9fef
commit 867406f410
2 changed files with 19 additions and 2 deletions

View File

@@ -35,7 +35,7 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest
context "preprocess action" do
should "prefer the file over the source when preprocessing" do
file = Rack::Test::UploadedFile.new("#{Rails.root}/test/files/test.jpg", "image/jpeg")
post_auth preprocess_uploads_path, @user, params: {:url => "http://www.google.com/intl/en_ALL/images/logo.gif", :file => file}
post_auth preprocess_uploads_path, @user, params: {:url => "https://raikou1.donmai.us/d3/4e/d34e4cf0a437a5d65f8e82b7bcd02606.jpg", :file => file}
assert_response :success
Delayed::Worker.new.work_off
assert_equal("ecef68c44edb8a0d6a3070b5f8e8ee76", Upload.last.md5)
@@ -51,10 +51,21 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest
context "with a url" do
should "preprocess" do
assert_difference(-> { Upload.count }) do
get_auth new_upload_path, @user, params: {:url => "http://www.google.com/intl/en_ALL/images/logo.gif"}
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"}
Delayed::Worker.new.work_off
file = Rack::Test::UploadedFile.new("#{Rails.root}/test/files/test.jpg", "image/jpeg")
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"}}
end
post = Post.last
assert_equal("ecef68c44edb8a0d6a3070b5f8e8ee76", post.md5)
end
end
context "for a twitter post" do