mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
let class names reflect its purpose (in tests)
This commit is contained in:
parent
d0d0bea90f
commit
4c23e288db
6 changed files with 26 additions and 37 deletions
|
@ -1,21 +0,0 @@
|
|||
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
|
|
@ -1,3 +0,0 @@
|
|||
class Son < Father
|
||||
include AASM
|
||||
end
|
3
spec/models/sub_class.rb
Normal file
3
spec/models/sub_class.rb
Normal file
|
@ -0,0 +1,3 @@
|
|||
require_relative 'super_class'
|
||||
class SubClass < SuperClass
|
||||
end
|
7
spec/models/sub_class_with_more_states.rb
Normal file
7
spec/models/sub_class_with_more_states.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
require_relative 'super_class'
|
||||
class SubClassWithMoreStates < SuperClass
|
||||
include AASM
|
||||
aasm do
|
||||
state :foo
|
||||
end
|
||||
end
|
|
@ -1,4 +1,4 @@
|
|||
class Bar
|
||||
class SuperClass
|
||||
include AASM
|
||||
|
||||
aasm do
|
||||
|
@ -9,7 +9,10 @@ class Bar
|
|||
transitions :to => :ended, :from => [:read]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Baz < Bar
|
||||
def update_state
|
||||
if may_foo?
|
||||
foo!
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,30 +1,30 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'subclassing' do
|
||||
let(:son) {Son.new}
|
||||
|
||||
it 'should have the parent states' do
|
||||
Foo.aasm.states.each do |state|
|
||||
expect(FooTwo.aasm.states).to include(state)
|
||||
SuperClass.aasm.states.each do |state|
|
||||
expect(SubClassWithMoreStates.aasm.states).to include(state)
|
||||
end
|
||||
expect(Baz.aasm.states).to eq(Bar.aasm.states)
|
||||
expect(SubClass.aasm.states).to eq(SuperClass.aasm.states)
|
||||
end
|
||||
|
||||
it 'should not add the child states to the parent machine' do
|
||||
expect(Foo.aasm.states).not_to include(:foo)
|
||||
expect(SuperClass.aasm.states).not_to include(:foo)
|
||||
end
|
||||
|
||||
it "should have the same events as its parent" do
|
||||
expect(Baz.aasm.events).to eq(Bar.aasm.events)
|
||||
expect(SubClass.aasm.events).to eq(SuperClass.aasm.events)
|
||||
end
|
||||
|
||||
it 'should know how to respond to `may_add_details?`' do
|
||||
expect(son.may_add_details?).to be_truthy
|
||||
it 'should know how to respond to question methods' do
|
||||
expect(SubClass.new.may_foo?).to be_truthy
|
||||
end
|
||||
|
||||
it 'should not break if I call Son#update_state' do
|
||||
it 'should not break if I call methods from super class' do
|
||||
son = SubClass.new
|
||||
son.update_state
|
||||
expect(son.aasm.current_state).to eq(:pending_details_confirmation)
|
||||
expect(son.aasm.current_state).to eq(:ended)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue