summaryrefslogtreecommitdiff
path: root/test/models
diff options
context:
space:
mode:
authorerdgeist <erdgeist@erdgeist.org>2026-08-03 04:13:34 +0200
committererdgeist <erdgeist@erdgeist.org>2026-08-03 04:13:34 +0200
commit0fa491188456332bacddb6310d86014cd8c87688 (patch)
treea1238383f29c28c179858f5643512de36836c6ff /test/models
parent45bb56ad1d809bead00379e68144e91bb471da06 (diff)
Believe the file over the browser about what was uploaded
Diffstat (limited to 'test/models')
-rw-r--r--test/models/asset_test.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/test/models/asset_test.rb b/test/models/asset_test.rb
index ab1cc5df..2677681b 100644
--- a/test/models/asset_test.rb
+++ b/test/models/asset_test.rb
@@ -1,4 +1,5 @@
1require 'test_helper' 1require 'test_helper'
2require "rack/test/uploaded_file"
2 3
3class AssetTest < ActiveSupport::TestCase 4class AssetTest < ActiveSupport::TestCase
4 5
@@ -53,4 +54,26 @@ class AssetTest < ActiveSupport::TestCase
53 assert asset.has_credit? 54 assert asset.has_credit?
54 assert_not asset.show_credit? 55 assert_not asset.show_credit?
55 end 56 end
57
58 test "an upload that claims to be an image but is not is refused" do
59 Tempfile.create(["fake", ".jpg"]) do |f|
60 f.write("this is not a jpeg")
61 f.flush
62
63 asset = Asset.new(:name => "fake")
64 asset.upload = Rack::Test::UploadedFile.new(f.path, "image/jpeg")
65
66 assert_not asset.valid?
67 assert_includes asset.errors.full_messages.to_sentence,
68 I18n.t("activerecord.errors.models.asset.attributes.upload.unreadable_image")
69 end
70 end
71
72 test "a real image is accepted and its type comes from the file" do
73 asset = Asset.new(:name => "real")
74 asset.upload = Rack::Test::UploadedFile.new(file_fixture("test_image.png"), "image/jpeg")
75
76 assert asset.valid?, asset.errors.full_messages.to_sentence
77 assert_equal "image/png", asset.upload_content_type
78 end
56end 79end