diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/models/asset_test.rb | 23 |
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 @@ | |||
| 1 | require 'test_helper' | 1 | require 'test_helper' |
| 2 | require "rack/test/uploaded_file" | ||
| 2 | 3 | ||
| 3 | class AssetTest < ActiveSupport::TestCase | 4 | class 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 | ||
| 56 | end | 79 | end |
