1
0
Fork 0
mirror of https://github.com/aasm/aasm synced 2023-03-27 23:22:41 -04:00
aasm/spec/unit/complex_example_spec.rb

85 lines
2.2 KiB
Ruby
Raw Normal View History

2012-10-26 05:27:17 -04:00
require 'spec_helper'
2012-12-02 02:55:16 -05:00
describe 'on initialization' do
let(:auth) {ComplexExample.new}
2012-10-26 05:27:17 -04:00
it 'should be in the pending state' do
expect(auth.aasm.current_state).to eq(:pending)
2012-10-26 05:27:17 -04:00
end
it 'should have an activation code' do
expect(auth.has_activation_code?).to be_truthy
expect(auth.activation_code).not_to be_nil
2012-10-26 05:27:17 -04:00
end
end
2012-12-02 02:55:16 -05:00
describe 'when being unsuspended' do
let(:auth) {ComplexExample.new}
2012-10-26 05:27:17 -04:00
it 'should be able to be unsuspended' do
auth.activate!
auth.suspend!
expect(auth.may_unsuspend?).to be true
2012-10-26 05:27:17 -04:00
end
it 'should not be able to be unsuspended into active' do
auth.suspend!
expect(auth.may_unsuspend?(:active)).not_to be true
2012-10-26 05:27:17 -04:00
end
it 'should be able to be unsuspended into active if polite' do
auth.suspend!
expect(auth.may_wait?(:waiting, :please)).to be true
2012-10-26 05:27:17 -04:00
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 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)
2012-10-26 05:27:17 -04:00
end
it 'should not be able to be unpassified' do
auth.activate!
auth.suspend!
auth.unsuspend!
expect(auth.may_unpassify?).not_to be true
expect {auth.unpassify!}.to raise_error(AASM::InvalidTransition)
2012-10-26 05:27:17 -04:00
end
it 'should be active if previously activated' do
auth.activate!
auth.suspend!
auth.unsuspend!
expect(auth.aasm.current_state).to eq(:active)
2012-10-26 05:27:17 -04:00
end
it 'should be pending if not previously activated, but an activation code is present' do
auth.suspend!
auth.unsuspend!
expect(auth.aasm.current_state).to eq(:pending)
2012-10-26 05:27:17 -04:00
end
it 'should be passive if not previously activated and there is no activation code' do
auth.activation_code = nil
auth.suspend!
auth.unsuspend!
expect(auth.aasm.current_state).to eq(:passive)
2012-10-26 05:27:17 -04:00
end
2014-05-16 15:57:18 -04:00
it "should be able to fire known events" do
expect(auth.aasm.may_fire_event?(:activate)).to be true
2014-05-16 15:57:18 -04:00
end
it "should not be able to fire unknown events" do
expect(auth.aasm.may_fire_event?(:unknown)).to be false
2014-05-16 15:57:18 -04:00
end
2012-10-26 05:27:17 -04:00
end