From fddec5e6a7f145268e37728e5570ce346f6b6162 Mon Sep 17 00:00:00 2001 From: smudge Date: Mon, 29 Nov 2021 12:49:17 -0500 Subject: [PATCH] Add back-compat coverage for 2.6 --- lib/delayed/performable_method.rb | 2 +- spec/performable_method_spec.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/delayed/performable_method.rb b/lib/delayed/performable_method.rb index 26686c4..8b6d46d 100644 --- a/lib/delayed/performable_method.rb +++ b/lib/delayed/performable_method.rb @@ -26,7 +26,7 @@ def display_name def perform return unless object - if kwargs.nil? # TODO: Remove this branch in the next major release. (It will be 'nil' for jobs enqueued before we split out kwargs.) + if kwargs.nil? || (RUBY_VERSION < '2.7' && kwargs.empty?) object.send(method_name, *args) else object.send(method_name, *args, **kwargs) diff --git a/spec/performable_method_spec.rb b/spec/performable_method_spec.rb index 135e492..a37fae2 100644 --- a/spec/performable_method_spec.rb +++ b/spec/performable_method_spec.rb @@ -31,6 +31,20 @@ def foo(arg, kwarg:) .to change { test_class.result } .from(nil).to %w(a b) end + + if RUBY_VERSION < '3.0' + context 'when kwargs are nil (job was delayed via prior gem version)' do + before do + @method = described_class.new(test_class.new, :foo, ['a', { kwarg: 'b' }], nil) + end + + it 'calls the method on the object' do + expect { @method.perform } + .to change { test_class.result } + .from(nil).to %w(a b) + end + end + end end it "raises a NoMethodError if target method doesn't exist" do