bugfix: may_<event>? should return true or false only #200

This commit is contained in:
Thorsten Böttger 2014-12-31 12:13:48 +01:00
parent cd0a88d3fa
commit 8c262aba96
3 changed files with 13 additions and 9 deletions

View File

@ -5,6 +5,10 @@
* `aasm_column` has been removed. Use `aasm.attribute_name` instead
* `aasm_human_event_name` has been removed. Use `aasm.human_event_name` instead
## 4.0.8
* bugfix: may_<event>? should return true or false only (see [issue #200](https://github.com/aasm/aasm/issues/200) for details)
## 4.0.7
* bugfix: take private methods into account when checking for callbacks (see [issue #197](https://github.com/aasm/aasm/issues/197) for details)

View File

@ -76,7 +76,7 @@ module AASM
def may_fire_event?(name, *args)
if event = @instance.class.aasm.state_machine.events[name]
event.may_fire?(@instance, *args)
!!event.may_fire?(@instance, *args)
else
false # unknown event
end

View File

@ -19,24 +19,24 @@ describe 'when being unsuspended' do
it 'should be able to be unsuspended' do
auth.activate!
auth.suspend!
expect(auth.may_unsuspend?).to be_truthy
expect(auth.may_unsuspend?).to be true
end
it 'should not be able to be unsuspended into active' do
auth.suspend!
expect(auth.may_unsuspend?(:active)).not_to be_truthy
expect(auth.may_unsuspend?(:active)).not_to be true
end
it 'should be able to be unsuspended into active if polite' do
auth.suspend!
expect(auth.may_wait?(:waiting, :please)).to be_truthy
expect(auth.may_wait?(:waiting, :please)).to be true
auth.wait!(nil, :please)
end
it 'should not be able to be unsuspended into active if not polite' do
auth.suspend!
expect(auth.may_wait?(:waiting)).not_to be_truthy
expect(auth.may_wait?(:waiting, :rude)).not_to be_truthy
expect(auth.may_wait?(:waiting)).not_to be true
expect(auth.may_wait?(:waiting, :rude)).not_to be true
expect {auth.wait!(nil, :rude)}.to raise_error(AASM::InvalidTransition)
expect {auth.wait!}.to raise_error(AASM::InvalidTransition)
end
@ -46,7 +46,7 @@ describe 'when being unsuspended' do
auth.suspend!
auth.unsuspend!
expect(auth.may_unpassify?).not_to be_truthy
expect(auth.may_unpassify?).not_to be true
expect {auth.unpassify!}.to raise_error(AASM::InvalidTransition)
end
@ -74,11 +74,11 @@ describe 'when being unsuspended' do
end
it "should be able to fire known events" do
expect(auth.aasm.may_fire_event?(:activate)).to be_truthy
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_falsey
expect(auth.aasm.may_fire_event?(:unknown)).to be false
end
end