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:
parent
b3fec8a748
commit
0800c53363
3 changed files with 20 additions and 1 deletions
|
@ -1,13 +1,17 @@
|
||||||
RSpec::Matchers.define :allow_event do |event|
|
RSpec::Matchers.define :allow_event do |event|
|
||||||
match do |obj|
|
match do |obj|
|
||||||
@state_machine_name ||= :default
|
@state_machine_name ||= :default
|
||||||
obj.aasm(@state_machine_name).may_fire_event?(event)
|
obj.aasm(@state_machine_name).may_fire_event?(event, *@args)
|
||||||
end
|
end
|
||||||
|
|
||||||
chain :on do |state_machine_name|
|
chain :on do |state_machine_name|
|
||||||
@state_machine_name = state_machine_name
|
@state_machine_name = state_machine_name
|
||||||
end
|
end
|
||||||
|
|
||||||
|
chain :with do |*args|
|
||||||
|
@args = args
|
||||||
|
end
|
||||||
|
|
||||||
description do
|
description do
|
||||||
"allow event #{expected} (on :#{@state_machine_name})"
|
"allow event #{expected} (on :#{@state_machine_name})"
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,5 +11,15 @@ class SimpleExample
|
||||||
event :authorise do
|
event :authorise do
|
||||||
transitions :from => :filled_out, :to => :authorised
|
transitions :from => :filled_out, :to => :authorised
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -63,6 +63,11 @@ describe 'state machine' do
|
||||||
expect(simple).to allow_event :authorise
|
expect(simple).to allow_event :authorise
|
||||||
end
|
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
|
it "works for multiple state machines" do
|
||||||
expect(multiple).to allow_event(:walk).on(:move)
|
expect(multiple).to allow_event(:walk).on(:move)
|
||||||
expect(multiple).to_not allow_event(:hold).on(:move)
|
expect(multiple).to_not allow_event(:hold).on(:move)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue