2015-05-18 05:36:31 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe 'on initialization' do
|
2015-06-26 03:46:58 -04:00
|
|
|
let(:auth) {ComplexExampleMultiple.new}
|
2015-05-18 05:36:31 -04:00
|
|
|
|
2015-07-20 04:55:47 -04:00
|
|
|
it 'should be in the initial state' do
|
2015-05-18 05:36:31 -04:00
|
|
|
expect(auth.aasm(:left).current_state).to eq(:pending)
|
2015-05-18 06:05:18 -04:00
|
|
|
expect(auth.aasm(:right).current_state).to eq(:pending)
|
2015-05-18 05:36:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should have an activation code' do
|
2015-05-18 05:52:36 -04:00
|
|
|
expect(auth.has_activation_code?).to be_truthy
|
2015-05-18 06:05:18 -04:00
|
|
|
expect(auth.activation_code).to eq '12'
|
2015-05-18 05:36:31 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'when being unsuspended' do
|
2015-06-26 03:46:58 -04:00
|
|
|
let(:auth) {ComplexExampleMultiple.new}
|
2015-05-18 05:36:31 -04:00
|
|
|
|
2015-05-18 06:05:18 -04:00
|
|
|
it 'should be able to unsuspend' do
|
2015-05-18 05:43:18 -04:00
|
|
|
auth.left_activate!
|
|
|
|
auth.left_suspend!
|
|
|
|
expect(auth.may_left_unsuspend?).to be true
|
2015-05-18 06:05:18 -04:00
|
|
|
|
|
|
|
auth.right_activate!
|
|
|
|
auth.right_suspend!
|
|
|
|
expect(auth.may_right_unsuspend?).to be true
|
2015-05-18 05:36:31 -04:00
|
|
|
end
|
|
|
|
|
2015-05-18 06:05:18 -04:00
|
|
|
it 'should not be able to unsuspend into active' do
|
2015-05-18 05:43:18 -04:00
|
|
|
auth.left_suspend!
|
|
|
|
expect(auth.may_left_unsuspend?(:active)).not_to be true
|
2015-05-18 06:05:18 -04:00
|
|
|
|
|
|
|
auth.right_activate!
|
|
|
|
auth.right_suspend!
|
|
|
|
expect(auth.may_right_unsuspend?(:active)).to be true
|
2015-05-18 05:36:31 -04:00
|
|
|
end
|
|
|
|
|
2015-05-18 06:05:18 -04:00
|
|
|
it 'should be able to wait into waiting if polite' do
|
2015-05-18 05:43:18 -04:00
|
|
|
auth.left_suspend!
|
|
|
|
expect(auth.may_left_wait?(:waiting, :please)).to be true
|
|
|
|
auth.left_wait!(nil, :please)
|
2015-05-18 06:05:18 -04:00
|
|
|
|
|
|
|
auth.right_suspend!
|
|
|
|
expect(auth.may_right_wait?(:waiting)).to be false
|
|
|
|
auth.right_wait!(nil, :please)
|
2015-05-18 05:36:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not be able to be unsuspended into active if not polite' do
|
2015-05-18 05:43:18 -04:00
|
|
|
auth.left_suspend!
|
|
|
|
expect(auth.may_left_wait?(:waiting)).not_to be true
|
|
|
|
expect(auth.may_left_wait?(:waiting, :rude)).not_to be true
|
|
|
|
expect {auth.left_wait!(nil, :rude)}.to raise_error(AASM::InvalidTransition)
|
|
|
|
expect {auth.left_wait!}.to raise_error(AASM::InvalidTransition)
|
2015-05-18 05:36:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not be able to be unpassified' do
|
2015-05-18 05:43:18 -04:00
|
|
|
auth.left_activate!
|
|
|
|
auth.left_suspend!
|
|
|
|
auth.left_unsuspend!
|
2015-05-18 05:36:31 -04:00
|
|
|
|
2015-05-18 05:43:18 -04:00
|
|
|
expect(auth.may_left_unpassify?).not_to be true
|
|
|
|
expect {auth.left_unpassify!}.to raise_error(AASM::InvalidTransition)
|
2015-05-18 05:36:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be active if previously activated' do
|
2015-05-18 05:43:18 -04:00
|
|
|
auth.left_activate!
|
|
|
|
auth.left_suspend!
|
|
|
|
auth.left_unsuspend!
|
2015-05-18 05:36:31 -04:00
|
|
|
|
|
|
|
expect(auth.aasm(:left).current_state).to eq(:active)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be pending if not previously activated, but an activation code is present' do
|
2015-05-18 05:43:18 -04:00
|
|
|
auth.left_suspend!
|
|
|
|
auth.left_unsuspend!
|
2015-05-18 05:36:31 -04:00
|
|
|
|
|
|
|
expect(auth.aasm(:left).current_state).to eq(:pending)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be passive if not previously activated and there is no activation code' do
|
2015-05-18 05:52:36 -04:00
|
|
|
auth.activation_code = nil
|
2015-05-18 05:43:18 -04:00
|
|
|
auth.left_suspend!
|
|
|
|
auth.left_unsuspend!
|
2015-05-18 05:36:31 -04:00
|
|
|
|
|
|
|
expect(auth.aasm(:left).current_state).to eq(:passive)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should be able to fire known events" do
|
2015-05-18 05:43:18 -04:00
|
|
|
expect(auth.aasm(:left).may_fire_event?(:left_activate)).to be true
|
2015-05-18 06:05:18 -04:00
|
|
|
expect(auth.aasm(:right).may_fire_event?(:right_activate)).to be true
|
2015-05-18 05:36:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should not be able to fire unknown events" do
|
|
|
|
expect(auth.aasm(:left).may_fire_event?(:unknown)).to be false
|
2015-05-18 06:05:18 -04:00
|
|
|
expect(auth.aasm(:right).may_fire_event?(:unknown)).to be false
|
2015-05-18 05:36:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|