Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Activestorage rack test uploaded file #30198

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion activestorage/lib/active_storage/attached.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def create_blob_from(attachable)
case attachable
when ActiveStorage::Blob
attachable
when ActionDispatch::Http::UploadedFile
when ActionDispatch::Http::UploadedFile, Rack::Test::UploadedFile
ActiveStorage::Blob.create_after_upload! \
io: attachable.open,
filename: attachable.original_filename,
Expand Down
8 changes: 7 additions & 1 deletion activestorage/test/models/attachments_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@ class ActiveStorage::AttachmentsTest < ActiveSupport::TestCase
assert_equal "funky.jpg", @user.avatar.filename.to_s
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"
assert_equal "town.jpg", @user.avatar.filename.to_s
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
@user.avatar.attach create_blob(filename: "funky.jpg")
assert_equal @user, @user.avatar_attachment.record
Expand Down