mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
parent
ffc2bf7725
commit
cf21c8b583
3 changed files with 29 additions and 1 deletions
|
@ -96,7 +96,7 @@ module AASM::Core
|
||||||
@transitions << AASM::Core::Transition.new(self, attach_event_guards(definitions.merge(:from => s.to_sym)), &block)
|
@transitions << AASM::Core::Transition.new(self, attach_event_guards(definitions.merge(:from => s.to_sym)), &block)
|
||||||
end
|
end
|
||||||
# Create a transition if :to is specified without :from (transitions from ANY state)
|
# Create a transition if :to is specified without :from (transitions from ANY state)
|
||||||
if @transitions.empty? && definitions[:to]
|
if !definitions[:from] && definitions[:to]
|
||||||
@transitions << AASM::Core::Transition.new(self, attach_event_guards(definitions), &block)
|
@transitions << AASM::Core::Transition.new(self, attach_event_guards(definitions), &block)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
18
spec/models/guardian_without_from_specified.rb
Normal file
18
spec/models/guardian_without_from_specified.rb
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
class GuardianWithoutFromSpecified
|
||||||
|
include AASM
|
||||||
|
|
||||||
|
aasm do
|
||||||
|
state :alpha, :initial => true
|
||||||
|
state :beta
|
||||||
|
state :gamma
|
||||||
|
|
||||||
|
event :use_guards_where_the_first_fails do
|
||||||
|
transitions :to => :beta, :guard => :fail
|
||||||
|
transitions :to => :gamma, :guard => :succeed
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def fail; false; end
|
||||||
|
def succeed; true; end
|
||||||
|
end
|
10
spec/unit/guard_without_from_specified_spec.rb
Normal file
10
spec/unit/guard_without_from_specified_spec.rb
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe "transitions without from specified" do
|
||||||
|
let(:guardian) { GuardianWithoutFromSpecified.new }
|
||||||
|
|
||||||
|
it "allows the transitions if guard succeeds" do
|
||||||
|
expect { guardian.use_guards_where_the_first_fails! }.to_not raise_error
|
||||||
|
expect(guardian).to be_gamma
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Reference in a new issue