Skip to content

Commit

Permalink
Update active storage monkey patch with latest rails code
Browse files Browse the repository at this point in the history
rails 5.2.1.1 changed the signature for active storage upload function
and we didn't reflect that in the upgrade. This adds a test to catch
stuff like that in the future and updates the code to match.
Fixes #19
  • Loading branch information
renatolond committed Dec 7, 2018
1 parent 915826e commit be55c4a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 3 additions & 3 deletions config/initializers/active_storage.rb
Expand Up @@ -110,15 +110,15 @@ def create_blob_from(attachable)

if defined?(ActiveStorage::Service)
ActiveStorage::Service.class_eval do
def upload(key, io, checksum: nil, acl: "private")
def upload(key, io, checksum: nil, acl: "private", **)
raise NotImplementedError
end
end
end

if defined?(ActiveStorage::Service::DiskService)
ActiveStorage::Service::DiskService.class_eval do
def upload(key, io, checksum: nil, acl: "private")
def upload(key, io, checksum: nil, acl: "private", **)
instrument :upload, key: key, checksum: checksum do
IO.copy_stream(io, make_path_for(key))
ensure_integrity_of(key, checksum) if checksum
Expand All @@ -136,7 +136,7 @@ def cdn_url(url)
uri.to_s
end

def upload(key, io, checksum: nil, content_type: "binary/octet-stream", acl: "private")
def upload(key, io, checksum: nil, content_type: "binary/octet-stream", acl: "private", **)
instrument :upload, key: key, checksum: checksum, acl: acl do
begin
object_for(key).put(upload_options.merge(body: io,
Expand Down
9 changes: 9 additions & 0 deletions test/controllers/recipes_controller_test.rb
Expand Up @@ -39,6 +39,15 @@ class RecipesControllerTest < ActionDispatch::IntegrationTest
assert_equal ["source1", "source 2"], created_recipe.source
end

test "should create recipe with image" do
file = fixture_file_upload("files/burrito.jpg", "image/jpg")
assert_difference("ActiveStorage::Attachment.count") do
assert_difference("Recipe.count") do
post account_recipes_url(@account), params: { recipe: { info: @recipe.info, public: @recipe.public, title: @recipe.title, account_id: @recipe.account_id, photo: file } }
end
end
end

test "should show recipe" do
get account_recipe_url(@recipe.account, @recipe)
assert_response :success
Expand Down

0 comments on commit be55c4a

Please sign in to comment.