Skip to content

Commit

Permalink
Fix rack_file not retaining Attacher#assign method signature
Browse files Browse the repository at this point in the history
  • Loading branch information
janko committed May 15, 2019
1 parent 924f40c commit f0fea5f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## HEAD

* `rack_file` – Fix overriden `Attacher#assign` not accepting second argument (@janko)

* `parsed_json` – Fix overriden `Attacher#assign` not accepting second argument (@janko)

## 2.17.0 (2019-05-06)
Expand Down
4 changes: 2 additions & 2 deletions lib/shrine/plugins/rack_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ def rack_file?(value)
module AttacherMethods
# Checks whether a file is a Rack file hash, and in that case wraps the
# hash in an IO-like object.
def assign(value)
def assign(value, **options)
if rack_file?(value)
assign(shrine_class.rack_file(value))
assign(shrine_class.rack_file(value), **options)
else
super
end
Expand Down
6 changes: 3 additions & 3 deletions test/plugin/parsed_json_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
end

it "accepts options" do
cached_file = @attacher.cache!(fakeio, metadata: { "foo" => "foo" })
assert_equal "foo", cached_file.metadata["foo"]
@attacher.assign(cached_file.data, foo: "bar")
cached_file = @attacher.cache!(fakeio, metadata: { "foo" => "bar" })
assert_equal "bar", cached_file.metadata["foo"]
@attacher.assign(cached_file.data, foo: :bar)
assert_equal cached_file, @attacher.get
end
end
7 changes: 7 additions & 0 deletions test/plugin/rack_file_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ def [](name)
assert_equal "image/jpeg", @attacher.get.mime_type
end

it "accepts assign options" do
@attacher.assign(@rack_hash, metadata: { "foo" => "bar" })
assert_equal "bar", @attacher.get.metadata["foo"]
@attacher.assign(fakeio, metadata: { "foo" => "bar" })
assert_equal "bar", @attacher.get.metadata["foo"]
end

deprecated "supports uploading Rack files directly" do
uploaded_file = @attacher.store.upload(@rack_hash)

Expand Down

0 comments on commit f0fea5f

Please sign in to comment.