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

Update active storage monkey patch with latest rails code #22

Merged
merged 1 commit into from Dec 7, 2018
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
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
1 change: 1 addition & 0 deletions test/fixtures/files/README.md
@@ -0,0 +1 @@
burrito.jpg is taken from (https://pixabay.com/en/mexican-food-burrito-mexican-food-2456038/) and it's by samuelfernandezrivera
Binary file added test/fixtures/files/burrito.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.