mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #30198 from betesh/activestorage-rack-test-uploaded-file
Activestorage rack test uploaded file
This commit is contained in:
commit
4766b2da02
2 changed files with 8 additions and 2 deletions
|
@ -17,7 +17,7 @@ module ActiveStorage
|
||||||
case attachable
|
case attachable
|
||||||
when ActiveStorage::Blob
|
when ActiveStorage::Blob
|
||||||
attachable
|
attachable
|
||||||
when ActionDispatch::Http::UploadedFile
|
when ActionDispatch::Http::UploadedFile, Rack::Test::UploadedFile
|
||||||
ActiveStorage::Blob.create_after_upload! \
|
ActiveStorage::Blob.create_after_upload! \
|
||||||
io: attachable.open,
|
io: attachable.open,
|
||||||
filename: attachable.original_filename,
|
filename: attachable.original_filename,
|
||||||
|
|
|
@ -18,11 +18,17 @@ class ActiveStorage::AttachmentsTest < ActiveSupport::TestCase
|
||||||
assert_equal "funky.jpg", @user.avatar.filename.to_s
|
assert_equal "funky.jpg", @user.avatar.filename.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
test "attach new blob" do
|
test "attach new blob from a Hash" do
|
||||||
@user.avatar.attach io: StringIO.new("STUFF"), filename: "town.jpg", content_type: "image/jpg"
|
@user.avatar.attach io: StringIO.new("STUFF"), filename: "town.jpg", content_type: "image/jpg"
|
||||||
assert_equal "town.jpg", @user.avatar.filename.to_s
|
assert_equal "town.jpg", @user.avatar.filename.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "attach new blob from an UploadedFile" do
|
||||||
|
file = file_fixture "racecar.jpg"
|
||||||
|
@user.avatar.attach Rack::Test::UploadedFile.new file
|
||||||
|
assert_equal "racecar.jpg", @user.avatar.filename.to_s
|
||||||
|
end
|
||||||
|
|
||||||
test "access underlying associations of new blob" do
|
test "access underlying associations of new blob" do
|
||||||
@user.avatar.attach create_blob(filename: "funky.jpg")
|
@user.avatar.attach create_blob(filename: "funky.jpg")
|
||||||
assert_equal @user, @user.avatar_attachment.record
|
assert_equal @user, @user.avatar_attachment.record
|
||||||
|
|
Loading…
Reference in a new issue