aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage/test/models/blob_test.rb
diff options
context:
space:
mode:
authorRyan Davidson <daviryan@aol.com>2018-05-06 16:25:05 +0100
committerRyan Davidson <daviryan@aol.com>2018-05-08 23:01:57 +0100
commit8e98bb7758f081622ab5c4eebf3730cce22ee627 (patch)
tree005431e48933ba96e655a56fabd436bcba442c1a /activestorage/test/models/blob_test.rb
parent5c7656d9a568fda855e6e558b7e44b1ba51425be (diff)
downloadrails-8e98bb7758f081622ab5c4eebf3730cce22ee627.tar.gz
rails-8e98bb7758f081622ab5c4eebf3730cce22ee627.tar.bz2
rails-8e98bb7758f081622ab5c4eebf3730cce22ee627.zip
Add option to ActiveStorage::Blob to set extract_content_type_from_io
This adds a boolean argument called identify to ActiveStorage::Blob methods #create_after_upload, #build_after_upload and #upload. It allows a user to bypass the automatic content_type inference from the io.
Diffstat (limited to 'activestorage/test/models/blob_test.rb')
-rw-r--r--activestorage/test/models/blob_test.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/activestorage/test/models/blob_test.rb b/activestorage/test/models/blob_test.rb
index daa01015f7..17151117db 100644
--- a/activestorage/test/models/blob_test.rb
+++ b/activestorage/test/models/blob_test.rb
@@ -43,6 +43,16 @@ class ActiveStorage::BlobTest < ActiveSupport::TestCase
assert_equal "text/plain", blob.content_type
end
+ test "create after upload extracts content_type from io when no content_type given and identify: false" do
+ blob = create_blob content_type: nil, identify: false
+ assert_equal "text/plain", blob.content_type
+ end
+
+ test "create after upload uses content_type when identify: false" do
+ blob = create_blob data: "Article,dates,analysis\n1, 2, 3", filename: "table.csv", content_type: "text/csv", identify: false
+ assert_equal "text/csv", blob.content_type
+ end
+
test "image?" do
blob = create_file_blob filename: "racecar.jpg"
assert_predicate blob, :image?