From 7e9d86902deb8d59e8030cbe9fa62e635e556a85 Mon Sep 17 00:00:00 2001 From: Ernesto Tagwerker Date: Tue, 30 Apr 2013 15:09:35 +0200 Subject: [PATCH] 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 00000000..00eadf99 --- /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 00000000..fbaef48d --- /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 00000000..550caa40 --- /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