diff --git a/spec/models/father.rb b/spec/models/father.rb new file mode 100644 index 0000000..00eadf9 --- /dev/null +++ b/spec/models/father.rb @@ -0,0 +1,21 @@ +require 'active_record' + +class Father < ActiveRecord::Base + include AASM + + aasm do + state :missing_details, :initial => true + state :pending_details_confirmation + + event :add_details do + transitions :from => :missing_details, :to => :pending_details_confirmation + end + end + + def update_state + if may_add_details? + add_details! + end + end + +end diff --git a/spec/models/son.rb b/spec/models/son.rb new file mode 100644 index 0000000..fbaef48 --- /dev/null +++ b/spec/models/son.rb @@ -0,0 +1,3 @@ +class Son < Father + include AASM +end diff --git a/spec/schema.rb b/spec/schema.rb index 3f1f110..7ddf433 100644 --- a/spec/schema.rb +++ b/spec/schema.rb @@ -27,4 +27,9 @@ ActiveRecord::Schema.define(:version => 0) do t.string "status" end + create_table "fathers", :force => true do |t| + t.string "aasm_state" + t.string "type" + end + end diff --git a/spec/unit/subclassing_spec.rb b/spec/unit/subclassing_spec.rb index b71d9f0..7ceb44d 100644 --- a/spec/unit/subclassing_spec.rb +++ b/spec/unit/subclassing_spec.rb @@ -1,6 +1,8 @@ require 'spec_helper' describe 'subclassing' do + let(:son) {Son.new} + it 'should have the parent states' do Foo.aasm_states.each do |state| FooTwo.aasm_states.should include(state) @@ -15,5 +17,15 @@ describe 'subclassing' do it "should have the same events as its parent" do Baz.aasm_events.should == Bar.aasm_events end + + it 'should know how to respond to `may_add_details?`' do + son.may_add_details?.should be_true + end + + it 'should not break if I call Son#update_state' do + son.update_state + son.aasm_current_state.should == :pending_details_confirmation + end + end