Skip to content

Commit

Permalink
Allow passing an empty hash to :after transition methods
Browse files Browse the repository at this point in the history
Since Ruby 2.7, a double splat with an empty hash passes no arguments.
So if an argument is an empty hash we should avoid it.
Ref: https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/#other-minor-changes-empty-hash

Fix aasm#829.
  • Loading branch information
y-yagi committed Jun 11, 2023
1 parent 2e952ff commit 0632dc3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/aasm/core/invokers/literal_invoker.rb
Expand Up @@ -31,7 +31,7 @@ def exec_subject
return record.__send__(subject) if subject_arity.zero?
return record.__send__(subject, *args) if subject_arity < 0
req_args = args[0..(subject_arity - 1)]
return record.__send__(subject, **req_args[0]) if req_args[0].is_a?(Hash)
return record.__send__(subject, **req_args[0]) if req_args[0].is_a?(Hash) && !req_args[0].empty?
record.__send__(subject, *req_args)
end
# rubocop:enable Metrics/AbcSize
Expand Down
5 changes: 5 additions & 0 deletions spec/unit/rspec_matcher_spec.rb
Expand Up @@ -72,6 +72,11 @@
expect(example).to_not allow_event(:fill_out_with_args).with(false)
end

it "works with empty hash argument" do
pe = ParametrisedEvent.new
expect(pe).to transition_from(:sleeping).to(:showering).on_event(:shower, {})
end

it "works for multiple state machines" do
expect(multiple).to allow_event(:walk).on(:move)
expect(multiple).to_not allow_event(:hold).on(:move)
Expand Down

0 comments on commit 0632dc3

Please sign in to comment.