2012-10-26 05:27:17 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2012-12-02 02:55:16 -05:00
|
|
|
describe 'on initialization' do
|
2015-05-15 06:43:36 -04:00
|
|
|
let(:auth) {ComplexExample.new}
|
2012-10-26 05:27:17 -04:00
|
|
|
|
|
|
|
it 'should be in the pending state' do
|
2014-01-07 13:35:51 -05:00
|
|
|
expect(auth.aasm.current_state).to eq(:pending)
|
2012-10-26 05:27:17 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should have an activation code' do
|
2014-12-14 08:53:57 -05:00
|
|
|
expect(auth.has_activation_code?).to be_truthy
|
2014-01-07 13:35:51 -05:00
|
|
|
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
|
2015-05-15 06:43:36 -04:00
|
|
|
let(:auth) {ComplexExample.new}
|
2012-10-26 05:27:17 -04:00
|
|
|
|
|
|
|
it 'should be able to be unsuspended' do
|
|
|
|
auth.activate!
|
|
|
|
auth.suspend!
|
2014-12-31 06:13:48 -05:00
|
|
|
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!
|
2014-12-31 06:13:48 -05:00
|
|
|
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!
|
2014-12-31 06:13:48 -05:00
|
|
|
expect(auth.may_wait?(:waiting, :please)).to be true
|
2017-07-26 09:09:31 -04:00
|
|
|
auth.wait!(:please)
|
2012-10-26 05:27:17 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not be able to be unsuspended into active if not polite' do
|
|
|
|
auth.suspend!
|
2014-12-31 06:13:48 -05:00
|
|
|
expect(auth.may_wait?(:waiting)).not_to be true
|
|
|
|
expect(auth.may_wait?(:waiting, :rude)).not_to be true
|
2017-07-26 09:09:31 -04:00
|
|
|
expect {auth.wait!(:rude)}.to raise_error(AASM::InvalidTransition)
|
2014-01-07 13:35:51 -05:00
|
|
|
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!
|
|
|
|
|
2014-12-31 06:13:48 -05:00
|
|
|
expect(auth.may_unpassify?).not_to be true
|
2014-01-07 13:35:51 -05:00
|
|
|
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!
|
|
|
|
|
2014-01-07 13:35:51 -05:00
|
|
|
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!
|
|
|
|
|
2014-01-07 13:35:51 -05:00
|
|
|
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!
|
|
|
|
|
2014-01-07 13:35:51 -05:00
|
|
|
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
|
2014-12-31 06:13:48 -05:00
|
|
|
expect(auth.aasm.may_fire_event?(:activate)).to be true
|
2014-05-16 15:57:18 -04:00
|
|
|
end
|
|
|
|
|
2017-08-08 13:20:58 -04:00
|
|
|
it "should be able to fire event by name" do
|
|
|
|
expect(auth.aasm.fire(:activate)).to be true
|
|
|
|
expect(auth.aasm.current_state).to eq(:active)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should be able to fire! event by name" do
|
|
|
|
expect(auth.aasm.fire!(:activate)).to be true
|
|
|
|
expect(auth.aasm.current_state).to eq(:active)
|
|
|
|
end
|
|
|
|
|
2014-05-16 15:57:18 -04:00
|
|
|
it "should not be able to fire unknown events" do
|
2014-12-31 06:13:48 -05:00
|
|
|
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
|