Skip to content
This repository has been archived by the owner on Mar 14, 2022. It is now read-only.

Commit

Permalink
Add tests that Memory#upload and Memory#open accept kwargs
Browse files Browse the repository at this point in the history
This is important when memory storage is used for tests, in which case
there might be some upload/download options passed by the application
code.

We also want to make sure there aren't any kwargs warnings being
triggered on Ruby 2.7, which could have been the case considering we
were using "*" instead of "**" (though it turns out it's not).
  • Loading branch information
janko committed Jan 16, 2020
1 parent fd813ed commit 4e13e09
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/shrine/storage/memory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ def initialize(store = {})
@store = store
end

def upload(io, id, *)
def upload(io, id, **)
store[id] = io.read
end

def open(id, *)
def open(id, **)
io = StringIO.new(store.fetch(id))
io.set_encoding(io.string.encoding) # Ruby 2.7.0 – https://bugs.ruby-lang.org/issues/16497
io
Expand Down
13 changes: 13 additions & 0 deletions test/storage/memory_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@
assert Shrine::Storage::Linter.call(@memory)
end

describe "#upload" do
it "accepts keyword arguments" do
@memory.upload(fakeio, "key", foo: "bar")
end
end

describe "#open" do
it "accepts keyword arguments" do
@memory.upload(fakeio, "key")
@memory.open("key", foo: "bar")
end
end

# work around apparent bug in ruby 2.7.0
# https://bugs.ruby-lang.org/issues/16497
it "preserves encoding despite Encoding.default_internal set" do
Expand Down

0 comments on commit 4e13e09

Please sign in to comment.