Move Gaurd args rspec to simple_example_with_guard_args.rb

This commit is contained in:
anilmaurya 2017-11-20 12:08:49 +05:30
parent d40f08271f
commit 3f3b3f56a1
5 changed files with 26 additions and 12 deletions

View File

@ -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

View File

@ -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

View 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

View File

@ -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

View File

@ -1,7 +1,7 @@
require 'minitest_helper'
class StateMachineTest < Minitest::Spec
let(:simple) { SimpleExample.new }
let(:multiple) { SimpleMultipleExample.new }