mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
Merge pull request #65 from etagwerker/master
Added more test to the subclassing spec
This commit is contained in:
commit
b3bd8f9275
4 changed files with 41 additions and 0 deletions
21
spec/models/father.rb
Normal file
21
spec/models/father.rb
Normal file
|
@ -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
spec/models/son.rb
Normal file
3
spec/models/son.rb
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
class Son < Father
|
||||||
|
include AASM
|
||||||
|
end
|
|
@ -27,4 +27,9 @@ ActiveRecord::Schema.define(:version => 0) do
|
||||||
t.string "status"
|
t.string "status"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
create_table "fathers", :force => true do |t|
|
||||||
|
t.string "aasm_state"
|
||||||
|
t.string "type"
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe 'subclassing' do
|
describe 'subclassing' do
|
||||||
|
let(:son) {Son.new}
|
||||||
|
|
||||||
it 'should have the parent states' do
|
it 'should have the parent states' do
|
||||||
Foo.aasm_states.each do |state|
|
Foo.aasm_states.each do |state|
|
||||||
FooTwo.aasm_states.should include(state)
|
FooTwo.aasm_states.should include(state)
|
||||||
|
@ -15,5 +17,15 @@ describe 'subclassing' do
|
||||||
it "should have the same events as its parent" do
|
it "should have the same events as its parent" do
|
||||||
Baz.aasm_events.should == Bar.aasm_events
|
Baz.aasm_events.should == Bar.aasm_events
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue