+
Skip to content

Can't pass an empty hash as callback parameters to transition_from since 5.5.0 #829

@y-yagi

Description

@y-yagi

Describe the bug

Can't pass an empty hash as callback parameters to transition_from since 5.5.0

To Reproduce

Reproduce script is here.

# frozen_string_literal: true
# bug_report_aasm.rb 

require "bundler/inline"

gemfile(true) do
  source "https://rubygems.org"

  gem "aasm", "5.5.0"
  gem "rspec"
end

class Job
  include AASM

  aasm do
    state :sleeping, initial: true
    state :running, :cleaning

    event :run do
      transitions from: :sleeping, to: :running, after: :prepare_run!
    end

    event :clean do
      transitions from: :running, to: :cleaning
    end
  end

  def prepare_run!(params)
    puts params
  end
end

require "aasm/rspec"
require "rspec/autorun"

RSpec.describe Job do
  it "move to 'run' with parameters" do
    job = Job.new
    expect(job).to transition_from(:sleeping).to(:running).on_event(:run, {})
  end
end
$ ruby bug_report_aasm.rb   
F

Failures:

  1) Job move to 'run' with parameters
     Failure/Error:
       def prepare_run!(params)
         puts params
       end

     ArgumentError:
       wrong number of arguments (given 0, expected 1)
     # bug_report_aasm.rb:28:in `prepare_run!'
     # bug_report_aasm.rb:39:in `block (2 levels) in <main>'

Finished in 0.00177 seconds (files took 0.05501 seconds to load)
1 example, 1 failure

Failed examples:

rspec bug_report_aasm.rb:37 # Job move to 'run' with parameters

Expected behavior

Allow to pass an empty hash as callback parameters via transition_from

Additional context

This has happened since #808.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载