Skip to content

Commit

Permalink
Merge pull request #2665 from SuperTux88/backport-kwargs-fix
Browse files Browse the repository at this point in the history
[backport] fix: ruby 2.7 kwarg warning in uploader process
  • Loading branch information
mshibuya authored Jun 10, 2023
2 parents bdb0be0 + 52237f4 commit 2f2d77a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/carrierwave/uploader/processing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,17 @@ def process!(new_file=nil)
next unless self.send(condition, new_file)
end
end
self.send(method, *args)

if args.is_a? Array
kwargs, args = args.partition { |arg| arg.is_a? Hash }
end

if kwargs.present?
kwargs = kwargs.reduce(:merge)
self.send(method, *args, **kwargs)
else
self.send(method, *args)
end
end
end
end
Expand Down
9 changes: 9 additions & 0 deletions spec/uploader/processing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@
uploader.process!("test.jpg")
end

context "when there are additional method key word arguments" do
it "calls the processor if the condition method returns true" do
uploader_class.process :resize => [200, 300, combine_options: { quality: 70 }], :if => :true?
expect(uploader).to receive(:true?).with("test.jpg").once.and_return(true)
expect(uploader).to receive(:resize).with(200, 300, combine_options: { quality: 70 })
uploader.process!("test.jpg")
end
end

context "when using RMagick", :rmagick => true do
before do
def uploader.cover
Expand Down

0 comments on commit 2f2d77a

Please sign in to comment.