Skip to content

Commit 2f2d77a

Browse files
authored
Merge pull request #2665 from SuperTux88/backport-kwargs-fix
[backport] fix: ruby 2.7 kwarg warning in uploader process
2 parents bdb0be0 + 52237f4 commit 2f2d77a

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/carrierwave/uploader/processing.rb

+11-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,17 @@ def process!(new_file=nil)
8080
next unless self.send(condition, new_file)
8181
end
8282
end
83-
self.send(method, *args)
83+
84+
if args.is_a? Array
85+
kwargs, args = args.partition { |arg| arg.is_a? Hash }
86+
end
87+
88+
if kwargs.present?
89+
kwargs = kwargs.reduce(:merge)
90+
self.send(method, *args, **kwargs)
91+
else
92+
self.send(method, *args)
93+
end
8494
end
8595
end
8696
end

spec/uploader/processing_spec.rb

+9
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,15 @@
8686
uploader.process!("test.jpg")
8787
end
8888

89+
context "when there are additional method key word arguments" do
90+
it "calls the processor if the condition method returns true" do
91+
uploader_class.process :resize => [200, 300, combine_options: { quality: 70 }], :if => :true?
92+
expect(uploader).to receive(:true?).with("test.jpg").once.and_return(true)
93+
expect(uploader).to receive(:resize).with(200, 300, combine_options: { quality: 70 })
94+
uploader.process!("test.jpg")
95+
end
96+
end
97+
8998
context "when using RMagick", :rmagick => true do
9099
before do
91100
def uploader.cover

0 commit comments

Comments
 (0)