let class names reflect its purpose (in tests)
This commit is contained in:
parent
d0d0bea90f
commit
4c23e288db
|
@ -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
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
require_relative 'super_class'
|
||||||
|
class SubClass < SuperClass
|
||||||
|
end
|
|
@ -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
|
include AASM
|
||||||
|
|
||||||
aasm do
|
aasm do
|
||||||
|
@ -9,7 +9,10 @@ class Bar
|
||||||
transitions :to => :ended, :from => [:read]
|
transitions :to => :ended, :from => [:read]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
class Baz < Bar
|
def update_state
|
||||||
|
if may_foo?
|
||||||
|
foo!
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
|
@ -1,30 +1,30 @@
|
||||||
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|
|
SuperClass.aasm.states.each do |state|
|
||||||
expect(FooTwo.aasm.states).to include(state)
|
expect(SubClassWithMoreStates.aasm.states).to include(state)
|
||||||
end
|
end
|
||||||
expect(Baz.aasm.states).to eq(Bar.aasm.states)
|
expect(SubClass.aasm.states).to eq(SuperClass.aasm.states)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not add the child states to the parent machine' do
|
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
|
end
|
||||||
|
|
||||||
it "should have the same events as its parent" do
|
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
|
end
|
||||||
|
|
||||||
it 'should know how to respond to `may_add_details?`' do
|
it 'should know how to respond to question methods' do
|
||||||
expect(son.may_add_details?).to be_truthy
|
expect(SubClass.new.may_foo?).to be_truthy
|
||||||
end
|
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
|
son.update_state
|
||||||
expect(son.aasm.current_state).to eq(:pending_details_confirmation)
|
expect(son.aasm.current_state).to eq(:ended)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue