Skip to content

Commit

Permalink
Merge pull request #65 from etagwerker/master
Browse files Browse the repository at this point in the history
Added more test to the subclassing spec
  • Loading branch information
alto committed May 3, 2013
2 parents 29db910 + 816f5d1 commit b3bd8f9
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
21 changes: 21 additions & 0 deletions 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
3 changes: 3 additions & 0 deletions spec/models/son.rb
@@ -0,0 +1,3 @@
class Son < Father
include AASM
end
5 changes: 5 additions & 0 deletions spec/schema.rb
Expand Up @@ -27,4 +27,9 @@
t.string "status"
end

create_table "fathers", :force => true do |t|
t.string "aasm_state"
t.string "type"
end

end
12 changes: 12 additions & 0 deletions 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)
Expand All @@ -15,5 +17,15 @@
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

0 comments on commit b3bd8f9

Please sign in to comment.