2012-12-03 22:54:15 +13:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe 'subclassing' do
|
2013-04-30 15:17:50 +02:00
|
|
|
|
2012-12-03 22:54:15 +13:00
|
|
|
it 'should have the parent states' do
|
2015-05-15 23:09:25 +12:00
|
|
|
SuperClass.aasm.states.each do |state|
|
|
|
|
expect(SubClassWithMoreStates.aasm.states).to include(state)
|
2012-12-03 22:54:15 +13:00
|
|
|
end
|
2015-05-15 23:09:25 +12:00
|
|
|
expect(SubClass.aasm.states).to eq(SuperClass.aasm.states)
|
2012-12-03 22:54:15 +13:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not add the child states to the parent machine' do
|
2015-05-15 23:09:25 +12:00
|
|
|
expect(SuperClass.aasm.states).not_to include(:foo)
|
2012-12-03 22:54:15 +13:00
|
|
|
end
|
|
|
|
|
2017-03-07 22:58:27 -08:00
|
|
|
it 'should have the same events as its parent' do
|
2015-05-15 23:09:25 +12:00
|
|
|
expect(SubClass.aasm.events).to eq(SuperClass.aasm.events)
|
2012-12-03 22:54:15 +13:00
|
|
|
end
|
2013-04-30 15:17:50 +02:00
|
|
|
|
2015-05-15 23:09:25 +12:00
|
|
|
it 'should know how to respond to question methods' do
|
|
|
|
expect(SubClass.new.may_foo?).to be_truthy
|
2013-04-30 15:17:50 +02:00
|
|
|
end
|
|
|
|
|
2015-05-15 23:09:25 +12:00
|
|
|
it 'should not break if I call methods from super class' do
|
|
|
|
son = SubClass.new
|
2013-04-30 15:17:50 +02:00
|
|
|
son.update_state
|
2015-05-15 23:09:25 +12:00
|
|
|
expect(son.aasm.current_state).to eq(:ended)
|
2013-04-30 15:17:50 +02:00
|
|
|
end
|
2013-11-30 20:46:36 +01:00
|
|
|
|
2017-03-07 22:58:27 -08:00
|
|
|
it 'should allow the child to modify its state machine' do
|
|
|
|
son = SubClass.new
|
|
|
|
expect(son.called_after).to eq(nil)
|
|
|
|
son.foo
|
|
|
|
expect(son.called_after).to eq(true)
|
|
|
|
global_callbacks = SubClass.aasm.state_machine.global_callbacks
|
|
|
|
expect(global_callbacks).to_not be_empty
|
|
|
|
expect(global_callbacks[:after_all_transitions]).to eq :after_all_event
|
|
|
|
end
|
2012-12-03 22:54:15 +13:00
|
|
|
|
2017-03-07 22:58:27 -08:00
|
|
|
it 'should not modify the parent state machine' do
|
|
|
|
super_class_event = SuperClass.aasm.events.select { |event| event.name == :foo }.first
|
|
|
|
expect(super_class_event.options).to be_empty
|
|
|
|
expect(SuperClass.aasm.state_machine.global_callbacks).to be_empty
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|