uploads: fix broken tests.

* Fix broken upload tests.
* Fix uploads to return an error if both a file and a source are given
  at the same time, or if neither are given. Also fix the error message
  in this case so that it doesn't include "base" at the start of the string.
* Fix uploads to percent-encode any Unicode characters in the source URL.
* Add a max filesize validation to media assets.
This commit is contained in:
evazion
2022-01-29 04:38:47 -06:00
parent 5d0c14d2bd
commit 11b7bcac91
9 changed files with 248 additions and 611 deletions

View File

@@ -5,6 +5,14 @@ class PostsControllerTest < ActionDispatch::IntegrationTest
assert_equal(expected, response.parsed_body.css("link[rel=canonical]").attribute("href").value)
end
def create_post!(user: create(:user), rating: "q", tag_string: "tagme", **params)
upload = build(:upload, uploader: user)
asset = create(:upload_media_asset, upload: upload)
post_auth posts_path, user, params: { post: { upload_media_asset_id: asset.id, rating: rating, tag_string: tag_string, **params }}
Post.last
end
context "The posts controller" do
setup do
@user = travel_to(1.month.ago) {create(:user)}
@@ -638,6 +646,32 @@ class PostsControllerTest < ActionDispatch::IntegrationTest
end
end
context "create action" do
should "autoban the post when it is tagged banned_artist" do
@post = create_post!(tag_string: "banned_artist")
assert_equal(true, @post.is_banned?)
end
should "autoban the post if it is tagged paid_reward" do
@post = create_post!(tag_string: "paid_reward")
assert_equal(true, @post.is_banned?)
end
should "not create a post when the uploader is upload-limited" do
@user = create(:user, upload_points: 0)
@user.upload_limit.upload_slots.times do
assert_difference("Post.count", 1) do
create_post!(user: @user)
end
end
assert_no_difference("Post.count") do
create_post!(user: @user)
end
end
end
context "update action" do
should "work" do
put_auth post_path(@post), @user, params: {:post => {:tag_string => "bbb"}}