diff --git a/lib/aasm.rb b/lib/aasm.rb index 2dc48d7..e90e9b5 100644 --- a/lib/aasm.rb +++ b/lib/aasm.rb @@ -18,15 +18,14 @@ module AASM base.extend AASM::ClassMethods AASM::Persistence.set_persistence(base) AASM::StateMachine[base] = AASM::StateMachine.new('') - - base.class_eval do - def base.inherited(klass) - AASM::StateMachine[klass] = AASM::StateMachine[self].dup - end - end end module ClassMethods + def inherited(klass) + AASM::StateMachine[klass] = AASM::StateMachine[self].dup + super + end + def aasm_initial_state(set_state=nil) if set_state AASM::StateMachine[self].initial_state = set_state diff --git a/spec/unit/aasm_spec.rb b/spec/unit/aasm_spec.rb index 12bc57f..14ac92e 100644 --- a/spec/unit/aasm_spec.rb +++ b/spec/unit/aasm_spec.rb @@ -70,6 +70,16 @@ describe AASM, '- class level definitions' do end +describe AASM, '- when included' do + it 'should invoke the original inherited callback when subclassed' do + parent = Class.new + parent.should_receive(:inherited) + parent.send(:include, AASM) + child = Class.new(parent) + end +end + + describe AASM, '- aasm_states_for_select' do it "should return a select friendly array of states in the form of [['Friendly name', 'state_name']]" do Foo.aasm_states_for_select.should == [['Open', 'open'], ['Closed', 'closed']]