mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
Move Gaurd args rspec to simple_example_with_guard_args.rb
This commit is contained in:
parent
d40f08271f
commit
3f3b3f56a1
5 changed files with 26 additions and 12 deletions
|
@ -1,13 +1,17 @@
|
|||
RSpec::Matchers.define :allow_transition_to do |state|
|
||||
match do |obj|
|
||||
@state_machine_name ||= :default
|
||||
obj.aasm(@state_machine_name).states(:permitted => true).include?(state)
|
||||
obj.aasm(@state_machine_name).states({:permitted => true}, *@args).include?(state)
|
||||
end
|
||||
|
||||
chain :on do |state_machine_name|
|
||||
@state_machine_name = state_machine_name
|
||||
end
|
||||
|
||||
chain :with do |*args|
|
||||
@args = args
|
||||
end
|
||||
|
||||
description do
|
||||
"allow transition to #{expected} (on :#{@state_machine_name})"
|
||||
end
|
||||
|
|
|
@ -12,14 +12,6 @@ class SimpleExample
|
|||
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
|
||||
|
|
17
spec/models/simple_example_with_guard_args.rb
Normal file
17
spec/models/simple_example_with_guard_args.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
class SimpleExampleWithGuardArgs
|
||||
include AASM
|
||||
aasm do
|
||||
state :initialised, :initial => true
|
||||
state :filled_out_with_args
|
||||
|
||||
event :fill_out_with_args do
|
||||
transitions :guard => [:arg_is_valid?],
|
||||
:from => :initialised,
|
||||
:to => :filled_out_with_args
|
||||
end
|
||||
end
|
||||
|
||||
def arg_is_valid?(arg)
|
||||
return arg
|
||||
end
|
||||
end
|
|
@ -64,8 +64,9 @@ describe 'state machine' do
|
|||
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)
|
||||
example = SimpleExampleWithGuardArgs.new
|
||||
expect(example).to allow_event(:fill_out_with_args).with(true)
|
||||
expect(example).to_not allow_event(:fill_out_with_args).with(false)
|
||||
end
|
||||
|
||||
it "works for multiple state machines" do
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require 'minitest_helper'
|
||||
|
||||
class StateMachineTest < Minitest::Spec
|
||||
|
||||
|
||||
let(:simple) { SimpleExample.new }
|
||||
let(:multiple) { SimpleMultipleExample.new }
|
||||
|
||||
|
|
Loading…
Reference in a new issue