mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
75 lines
2 KiB
Ruby
75 lines
2 KiB
Ruby
require 'spec_helper'
|
|
|
|
describe 'on initialization' do
|
|
let(:auth) {AuthMachine.new}
|
|
|
|
it 'should be in the pending state' do
|
|
expect(auth.aasm.current_state).to eq(:pending)
|
|
end
|
|
|
|
it 'should have an activation code' do
|
|
expect(auth.has_activation_code?).to be_true
|
|
expect(auth.activation_code).not_to be_nil
|
|
end
|
|
end
|
|
|
|
describe 'when being unsuspended' do
|
|
let(:auth) {AuthMachine.new}
|
|
|
|
it 'should be able to be unsuspended' do
|
|
auth.activate!
|
|
auth.suspend!
|
|
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_true
|
|
end
|
|
|
|
it 'should be able to be unsuspended into active if polite' do
|
|
auth.suspend!
|
|
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_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
|
|
|
|
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)
|
|
end
|
|
|
|
it 'should be active if previously activated' do
|
|
auth.activate!
|
|
auth.suspend!
|
|
auth.unsuspend!
|
|
|
|
expect(auth.aasm.current_state).to eq(:active)
|
|
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)
|
|
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)
|
|
end
|
|
end
|