may not fire an unknown event #128
This commit is contained in:
parent
2f31a6ed9a
commit
c4b672046a
|
@ -75,8 +75,11 @@ module AASM
|
||||||
end
|
end
|
||||||
|
|
||||||
def may_fire_event?(name, *args)
|
def may_fire_event?(name, *args)
|
||||||
event = @instance.class.aasm.events[name]
|
if event = @instance.class.aasm.events[name]
|
||||||
event.may_fire?(@instance, *args)
|
event.may_fire?(@instance, *args)
|
||||||
|
else
|
||||||
|
false # unknown event
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_current_state_with_persistence(state)
|
def set_current_state_with_persistence(state)
|
||||||
|
|
|
@ -72,4 +72,13 @@ describe 'when being unsuspended' do
|
||||||
|
|
||||||
expect(auth.aasm.current_state).to eq(:passive)
|
expect(auth.aasm.current_state).to eq(:passive)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should be able to fire known events" do
|
||||||
|
expect(auth.aasm.may_fire_event?(:activate)).to be_true
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should not be able to fire unknown events" do
|
||||||
|
expect(auth.aasm.may_fire_event?(:unknown)).to be_false
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue