mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
moved all test models into their own file to improve readibility
This commit is contained in:
parent
43cc51c9a5
commit
3458f17f06
3 changed files with 59 additions and 58 deletions
|
@ -14,3 +14,6 @@ def load_schema
|
|||
ActiveRecord::Base.establish_connection(config['sqlite3'])
|
||||
load(File.dirname(__FILE__) + "/schema.rb")
|
||||
end
|
||||
|
||||
# Requiring custom spec helpers
|
||||
Dir[File.dirname(__FILE__) + "/spec_helpers/**/*.rb"].sort.each { |f| require File.expand_path(f) }
|
||||
|
|
56
spec/spec_helpers/models_test_helper.rb
Normal file
56
spec/spec_helpers/models_test_helper.rb
Normal file
|
@ -0,0 +1,56 @@
|
|||
class Foo
|
||||
include AASM
|
||||
aasm_initial_state :open
|
||||
aasm_state :open, :exit => :exit
|
||||
aasm_state :closed, :enter => :enter
|
||||
|
||||
aasm_event :close, :success => :success_callback do
|
||||
transitions :to => :closed, :from => [:open]
|
||||
end
|
||||
|
||||
aasm_event :null do
|
||||
transitions :to => :closed, :from => [:open], :guard => :always_false
|
||||
end
|
||||
|
||||
def always_false
|
||||
false
|
||||
end
|
||||
|
||||
def success_callback
|
||||
end
|
||||
|
||||
def enter
|
||||
end
|
||||
def exit
|
||||
end
|
||||
end
|
||||
|
||||
class FooTwo < Foo
|
||||
include AASM
|
||||
aasm_state :foo
|
||||
end
|
||||
|
||||
class Bar
|
||||
include AASM
|
||||
|
||||
aasm_state :read
|
||||
aasm_state :ended
|
||||
|
||||
aasm_event :foo do
|
||||
transitions :to => :ended, :from => [:read]
|
||||
end
|
||||
end
|
||||
|
||||
class Baz < Bar
|
||||
end
|
||||
|
||||
class Banker
|
||||
include AASM
|
||||
aasm_initial_state Proc.new { |banker| banker.rich? ? :retired : :selling_bad_mortgages }
|
||||
aasm_state :retired
|
||||
aasm_state :selling_bad_mortgages
|
||||
RICH = 1_000_000
|
||||
attr_accessor :balance
|
||||
def initialize(balance = 0); self.balance = balance; end
|
||||
def rich?; self.balance >= RICH; end
|
||||
end
|
|
@ -1,63 +1,5 @@
|
|||
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
||||
|
||||
class Foo
|
||||
include AASM
|
||||
aasm_initial_state :open
|
||||
aasm_state :open, :exit => :exit
|
||||
aasm_state :closed, :enter => :enter
|
||||
|
||||
aasm_event :close, :success => :success_callback do
|
||||
transitions :to => :closed, :from => [:open]
|
||||
end
|
||||
|
||||
aasm_event :null do
|
||||
transitions :to => :closed, :from => [:open], :guard => :always_false
|
||||
end
|
||||
|
||||
def always_false
|
||||
false
|
||||
end
|
||||
|
||||
def success_callback
|
||||
end
|
||||
|
||||
def enter
|
||||
end
|
||||
def exit
|
||||
end
|
||||
end
|
||||
|
||||
class FooTwo < Foo
|
||||
include AASM
|
||||
aasm_state :foo
|
||||
end
|
||||
|
||||
class Bar
|
||||
include AASM
|
||||
|
||||
aasm_state :read
|
||||
aasm_state :ended
|
||||
|
||||
aasm_event :foo do
|
||||
transitions :to => :ended, :from => [:read]
|
||||
end
|
||||
end
|
||||
|
||||
class Baz < Bar
|
||||
end
|
||||
|
||||
class Banker
|
||||
include AASM
|
||||
aasm_initial_state Proc.new { |banker| banker.rich? ? :retired : :selling_bad_mortgages }
|
||||
aasm_state :retired
|
||||
aasm_state :selling_bad_mortgages
|
||||
RICH = 1_000_000
|
||||
attr_accessor :balance
|
||||
def initialize(balance = 0); self.balance = balance; end
|
||||
def rich?; self.balance >= RICH; end
|
||||
end
|
||||
|
||||
|
||||
describe AASM, '- class level definitions' do
|
||||
it 'should define a class level aasm_initial_state() method on its including class' do
|
||||
Foo.should respond_to(:aasm_initial_state)
|
||||
|
|
Loading…
Reference in a new issue