1
0
Fork 0
mirror of https://github.com/aasm/aasm synced 2023-03-27 23:22:41 -04:00

Allow custom params for allow_event matcher

This commit is contained in:
Cedric ZH 2016-11-27 21:36:30 +08:00 committed by Anil Kumar Maurya
parent b3fec8a748
commit 0800c53363
3 changed files with 20 additions and 1 deletions

View file

@ -1,13 +1,17 @@
RSpec::Matchers.define :allow_event do |event|
match do |obj|
@state_machine_name ||= :default
obj.aasm(@state_machine_name).may_fire_event?(event)
obj.aasm(@state_machine_name).may_fire_event?(event, *@args)
end
chain :on do |state_machine_name|
@state_machine_name = state_machine_name
end
chain :with do |*args|
@args = args
end
description do
"allow event #{expected} (on :#{@state_machine_name})"
end

View file

@ -11,5 +11,15 @@ class SimpleExample
event :authorise do
transitions :from => :filled_out, :to => :authorised
end
event :fill_out_with_args do
transitions :guard => [:arg_is_valid?],
:from => :initialised,
:to => :filled_out
end
end
def arg_is_valid?(arg)
return arg
end
end

View file

@ -63,6 +63,11 @@ describe 'state machine' do
expect(simple).to allow_event :authorise
end
it "works with custom arguments" do
expect(simple).to allow_event(:fill_out_with_args).with(true)
expect(simple).to_not allow_event(:fill_out_with_args).with(false)
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)