From 7f98b99f7d3ef6c18739b40c3ce079be62242d74 Mon Sep 17 00:00:00 2001 From: Ernesto Tagwerker Date: Tue, 30 Apr 2013 15:09:12 +0200 Subject: [PATCH 1/3] Added fathers table. --- spec/schema.rb | 5 +++++ 1 file changed, 5 insertions(+) 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 From 7e9d86902deb8d59e8030cbe9fa62e635e556a85 Mon Sep 17 00:00:00 2001 From: Ernesto Tagwerker Date: Tue, 30 Apr 2013 15:09:35 +0200 Subject: [PATCH 2/3] Added test for inheritance, to check issue #64 --- spec/models/father.rb | 21 +++++++++++++++++++++ spec/models/son.rb | 3 +++ spec/unit/inheritance_spec.rb | 18 ++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 spec/models/father.rb create mode 100644 spec/models/son.rb create mode 100644 spec/unit/inheritance_spec.rb 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/unit/inheritance_spec.rb b/spec/unit/inheritance_spec.rb new file mode 100644 index 0000000..550caa4 --- /dev/null +++ b/spec/unit/inheritance_spec.rb @@ -0,0 +1,18 @@ +require 'spec_helper' + +describe 'inheritance behavior' do + let(:son) {Son.new} + + it 'should be in the pending state' do + son.aasm_current_state.should == :missing_details + 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 \ No newline at end of file From 816f5d1dc59315f2f7abcaa119cfaa36e90f9d54 Mon Sep 17 00:00:00 2001 From: Ernesto Tagwerker Date: Tue, 30 Apr 2013 15:17:50 +0200 Subject: [PATCH 3/3] Moved inheritance_spec test to subclassing_spec. --- spec/unit/inheritance_spec.rb | 18 ------------------ spec/unit/subclassing_spec.rb | 12 ++++++++++++ 2 files changed, 12 insertions(+), 18 deletions(-) delete mode 100644 spec/unit/inheritance_spec.rb diff --git a/spec/unit/inheritance_spec.rb b/spec/unit/inheritance_spec.rb deleted file mode 100644 index 550caa4..0000000 --- a/spec/unit/inheritance_spec.rb +++ /dev/null @@ -1,18 +0,0 @@ -require 'spec_helper' - -describe 'inheritance behavior' do - let(:son) {Son.new} - - it 'should be in the pending state' do - son.aasm_current_state.should == :missing_details - 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 \ No newline at end of file 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