From 5433e6b5c163e52ba1b9809d3d1d36f0ac0e517e Mon Sep 17 00:00:00 2001 From: Andy Mok Date: Thu, 13 Jun 2024 18:10:39 -0700 Subject: [PATCH] forward options when calling #promote_cached to promote_block 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`. --- lib/shrine/plugins/backgrounding.rb | 2 +- test/plugin/backgrounding_test.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/shrine/plugins/backgrounding.rb b/lib/shrine/plugins/backgrounding.rb index 3fdc3755b..4e9be5999 100644 --- a/lib/shrine/plugins/backgrounding.rb +++ b/lib/shrine/plugins/backgrounding.rb @@ -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 diff --git a/test/plugin/backgrounding_test.rb b/test/plugin/backgrounding_test.rb index fd9742814..0406e8190 100644 --- a/test/plugin/backgrounding_test.rb +++ b/test/plugin/backgrounding_test.rb @@ -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