Skip to content

Commit

Permalink
forward options when calling #promote_cached to promote_block (#689)
Browse files Browse the repository at this point in the history
If `Shrine::Attacher.promote_block { |**options| ... }` is declared with
backgrounding plugin and we call `attacher.promote_cached(**options)`,
the options were not being forwarded to the `.promote_block`.
  • Loading branch information
4ndypanda committed Jun 14, 2024
1 parent ef636ce commit c5c0546
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/shrine/plugins/backgrounding.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def destroy_block(&block)
# Does a background promote if promote block was registered.
def promote_cached(**options)
if promote? && promote_block
promote_background
promote_background(**options)
else
super
end
Expand Down
16 changes: 16 additions & 0 deletions test/plugin/backgrounding_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,22 @@
assert @attacher.stored?
end

it "forwards additional options to the block" do
@attacher.promote_block do |attacher, **options|
@job = Fiber.new { attacher.promote(**options) }
end

@attacher.attach_cached(fakeio)
@attacher.promote_cached(location: "foo")

assert @attacher.cached?

@job.resume

assert @attacher.stored?
assert_equal "foo", @attacher.file.id
end

it "calls default promotion when no promote blocks are registered" do
@attacher.attach_cached(fakeio)
@attacher.promote_cached
Expand Down

0 comments on commit c5c0546

Please sign in to comment.