Skip to content

Commit

Permalink
Merge pull request #25 from frodsan/adding-event-name
Browse files Browse the repository at this point in the history
Adding the event name to the callback call
  • Loading branch information
soveran committed Mar 3, 2015
2 parents 85b5161 + 7cf82af commit fc9635c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/micromachine.rb
Expand Up @@ -23,7 +23,7 @@ def trigger(event)
if trigger?(event)
@state = transitions_for[event][@state]
callbacks = @callbacks[@state] + @callbacks[:any]
callbacks.each { |callback| callback.call }
callbacks.each { |callback| callback.call(event) }
true
else
false
Expand Down
15 changes: 15 additions & 0 deletions test/callbacks.rb
Expand Up @@ -27,3 +27,18 @@
machine.trigger(:reset)
assert_equal "Pending", @current
end

test "passing the event name to the callbacks" do
event_name = nil

machine = MicroMachine.new(:pending)
machine.when(:confirm, pending: :confirmed)

machine.on(:confirmed) do |event|
event_name = event
end

machine.trigger(:confirm)

assert_equal(:confirm, event_name)
end

0 comments on commit fc9635c

Please sign in to comment.