2015-09-22 16:22:05 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe 'state machine' do
|
|
|
|
let(:namespaced) { NamespacedMultipleExample.new }
|
|
|
|
|
|
|
|
it 'starts with an initial state' do
|
|
|
|
expect(namespaced.aasm(:status).current_state).to eq(:unapproved)
|
|
|
|
expect(namespaced).to respond_to(:unapproved?)
|
|
|
|
expect(namespaced).to be_unapproved
|
|
|
|
|
|
|
|
expect(namespaced.aasm(:review_status).current_state).to eq(:unapproved)
|
|
|
|
expect(namespaced).to respond_to(:review_unapproved?)
|
|
|
|
expect(namespaced).to be_review_unapproved
|
2017-06-13 19:20:25 -04:00
|
|
|
|
|
|
|
expect(namespaced.aasm(:car).current_state).to eq(:unsold)
|
|
|
|
expect(namespaced).to respond_to(:car_unsold?)
|
|
|
|
expect(namespaced).to be_car_unsold
|
2015-09-22 16:22:05 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows transitions to other states' do
|
|
|
|
expect(namespaced).to respond_to(:approve)
|
|
|
|
expect(namespaced).to respond_to(:approve!)
|
|
|
|
namespaced.approve!
|
|
|
|
expect(namespaced).to respond_to(:approved?)
|
|
|
|
expect(namespaced).to be_approved
|
|
|
|
|
|
|
|
expect(namespaced).to respond_to(:approve_review)
|
|
|
|
expect(namespaced).to respond_to(:approve_review!)
|
|
|
|
namespaced.approve_review!
|
|
|
|
expect(namespaced).to respond_to(:review_approved?)
|
|
|
|
expect(namespaced).to be_review_approved
|
2017-06-13 19:20:25 -04:00
|
|
|
|
|
|
|
expect(namespaced).to respond_to(:sell_car)
|
|
|
|
expect(namespaced).to respond_to(:sell_car!)
|
|
|
|
namespaced.sell_car!
|
|
|
|
expect(namespaced).to respond_to(:car_sold?)
|
|
|
|
expect(namespaced).to be_car_sold
|
2015-09-22 16:22:05 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'denies transitions to other states' do
|
|
|
|
expect {namespaced.unapprove}.to raise_error(AASM::InvalidTransition)
|
|
|
|
expect {namespaced.unapprove!}.to raise_error(AASM::InvalidTransition)
|
|
|
|
namespaced.approve
|
|
|
|
expect {namespaced.approve}.to raise_error(AASM::InvalidTransition)
|
|
|
|
expect {namespaced.approve!}.to raise_error(AASM::InvalidTransition)
|
|
|
|
namespaced.unapprove
|
|
|
|
|
|
|
|
expect {namespaced.unapprove_review}.to raise_error(AASM::InvalidTransition)
|
|
|
|
expect {namespaced.unapprove_review!}.to raise_error(AASM::InvalidTransition)
|
|
|
|
namespaced.approve_review
|
|
|
|
expect {namespaced.approve_review}.to raise_error(AASM::InvalidTransition)
|
|
|
|
expect {namespaced.approve_review!}.to raise_error(AASM::InvalidTransition)
|
|
|
|
namespaced.unapprove_review
|
2017-06-13 19:20:25 -04:00
|
|
|
|
|
|
|
expect {namespaced.return_car}.to raise_error(AASM::InvalidTransition)
|
|
|
|
expect {namespaced.return_car!}.to raise_error(AASM::InvalidTransition)
|
|
|
|
namespaced.sell_car
|
|
|
|
expect {namespaced.sell_car}.to raise_error(AASM::InvalidTransition)
|
|
|
|
expect {namespaced.sell_car!}.to raise_error(AASM::InvalidTransition)
|
|
|
|
namespaced.return_car
|
2015-09-22 16:22:05 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'defines constants for each state name' do
|
|
|
|
expect(NamespacedMultipleExample::STATE_UNAPPROVED).to eq(:unapproved)
|
|
|
|
expect(NamespacedMultipleExample::STATE_APPROVED).to eq(:approved)
|
|
|
|
|
|
|
|
expect(NamespacedMultipleExample::STATE_REVIEW_UNAPPROVED).to eq(:unapproved)
|
|
|
|
expect(NamespacedMultipleExample::STATE_REVIEW_APPROVED).to eq(:approved)
|
2017-06-13 19:20:25 -04:00
|
|
|
|
|
|
|
expect(NamespacedMultipleExample::STATE_CAR_UNSOLD).to eq(:unsold)
|
|
|
|
expect(NamespacedMultipleExample::STATE_CAR_SOLD).to eq(:sold)
|
2015-09-22 16:22:05 -04:00
|
|
|
end
|
2017-06-13 19:20:25 -04:00
|
|
|
|
|
|
|
|
2015-09-22 16:22:05 -04:00
|
|
|
end
|