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

forward options when calling #promote_cached to promote_block #689

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading