From 216b48e519e25eed949094970f135e741be684fe Mon Sep 17 00:00:00 2001 From: Scott Barron Date: Sun, 1 Jun 2008 14:48:17 -0700 Subject: [PATCH] Get rid of class vars added to classes including AASM, support inheritance on AASMs --- lib/aasm.rb | 6 ++++++ spec/unit/aasm_spec.rb | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/lib/aasm.rb b/lib/aasm.rb index 429e6e8..bbf868d 100644 --- a/lib/aasm.rb +++ b/lib/aasm.rb @@ -11,6 +11,12 @@ 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 diff --git a/spec/unit/aasm_spec.rb b/spec/unit/aasm_spec.rb index 829e873..7d7bf90 100644 --- a/spec/unit/aasm_spec.rb +++ b/spec/unit/aasm_spec.rb @@ -29,8 +29,16 @@ end class Bar include AASM + aasm_state :read aasm_state :ended + + aasm_event :foo do + transitions :to => :ended, :from => [:read] + end +end + +class Baz < Bar end @@ -251,3 +259,14 @@ describe AASM, '- state actions' do foo.close end end + + +describe Baz do + it "should have the same states as it's parent" do + Baz.aasm_states.should == Bar.aasm_states + end + + it "should have the same events as it's parent" do + Baz.aasm_events.should == Bar.aasm_events + end +end