Skip to content

Commit

Permalink
Merge pull request #1757 from Shopify/active-job-block-fix
Browse files Browse the repository at this point in the history
Remove duplicate block parameter in ActiveJob#perform_later
  • Loading branch information
paracycle committed Jan 11, 2024
2 parents 317491d + 2fdd5ed commit a335947
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/tapioca/dsl/compilers/active_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def decorate
end
def perform_later_parameters(parameters, constant_name)
if ::Gem::Requirement.new(">= 7.0").satisfied_by?(::ActiveJob.gem_version)
parameters.reject! { |typed_param| RBI::BlockParam === typed_param.param }
parameters + [create_block_param(
"block",
type: "T.nilable(T.proc.params(job: #{constant_name}).void)",
Expand Down
30 changes: 30 additions & 0 deletions spec/tapioca/dsl/compilers/active_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,36 @@ def perform_now(user_id); end
RBI
assert_equal(expected, rbi_for(:NotifyJob))
end

it "generates correct RBI file for subclass with block argument" do
add_ruby_file("job.rb", <<~RUBY)
class NotifyJob < ActiveJob::Base
def perform(user_id, &blk)
# ...
end
end
RUBY

expected = template(<<~RBI)
# typed: strong
class NotifyJob
class << self
<% if rails_version(">= 7.0") %>
sig { params(user_id: T.untyped, block: T.nilable(T.proc.params(job: NotifyJob).void)).returns(T.any(NotifyJob, FalseClass)) }
def perform_later(user_id, &block); end
<% else %>
sig { params(user_id: T.untyped).returns(T.any(NotifyJob, FalseClass)) }
def perform_later(user_id); end
<% end %>
sig { params(user_id: T.untyped).returns(T.untyped) }
def perform_now(user_id); end
end
end
RBI
assert_equal(expected, rbi_for(:NotifyJob))
end
end
end
end
Expand Down

0 comments on commit a335947

Please sign in to comment.