Skip to content

Commit

Permalink
unified test and spec (using spec only now)
Browse files Browse the repository at this point in the history
  • Loading branch information
alto committed Oct 15, 2011
1 parent 04a71b8 commit 31258e7
Show file tree
Hide file tree
Showing 16 changed files with 416 additions and 669 deletions.
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ Rake::TestTask.new(:test) do |test|
test.verbose = true
end

task :default => :test

require 'rdoc/task'
require 'aasm/version'
require 'sdoc'
Expand All @@ -25,3 +23,5 @@ Rake::RDocTask.new do |rdoc|
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end

task :default => :spec
1 change: 1 addition & 0 deletions test/models/process.rb → spec/models/process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ class Process

end
end

117 changes: 117 additions & 0 deletions spec/spec_helpers/models_test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Dir[File.dirname(__FILE__) + "/models/**/*.rb"].each { |f| require File.expand_path(f) }

class Foo
include AASM
aasm_initial_state :open
Expand Down Expand Up @@ -65,3 +67,118 @@ class Argument
transitions :to => :valid, :from => [:invalid]
end
end

class AuthMachine
include AASM

attr_accessor :activation_code, :activated_at, :deleted_at

aasm_initial_state :pending

aasm_state :passive
aasm_state :pending, :enter => :make_activation_code
aasm_state :active, :enter => :do_activate
aasm_state :suspended
aasm_state :deleted, :enter => :do_delete, :exit => :do_undelete

aasm_event :register do
transitions :from => :passive, :to => :pending, :guard => Proc.new {|u| u.can_register? }
end

aasm_event :activate do
transitions :from => :pending, :to => :active
end

aasm_event :suspend do
transitions :from => [:passive, :pending, :active], :to => :suspended
end

aasm_event :delete do
transitions :from => [:passive, :pending, :active, :suspended], :to => :deleted
end

# a dummy event that can never happen
aasm_event :unpassify do
transitions :from => :passive, :to => :active, :guard => Proc.new {|u| false }
end

aasm_event :unsuspend do
transitions :from => :suspended, :to => :active, :guard => Proc.new {|u| u.has_activated? }
transitions :from => :suspended, :to => :pending, :guard => Proc.new {|u| u.has_activation_code? }
transitions :from => :suspended, :to => :passive
end

def initialize
# the AR backend uses a before_validate_on_create :aasm_ensure_initial_state
# lets do something similar here for testing purposes.
aasm_enter_initial_state
end

def make_activation_code
@activation_code = 'moo'
end

def do_activate
@activated_at = Time.now
@activation_code = nil
end

def do_delete
@deleted_at = Time.now
end

def do_undelete
@deleted_at = false
end

def can_register?
true
end

def has_activated?
!!@activated_at
end

def has_activation_code?
!!@activation_code
end
end

class ThisNameBetterNotBeInUse
include AASM

aasm_state :initial
aasm_state :symbol
aasm_state :string
aasm_state :array
aasm_state :proc
end

class ChetanPatil
include AASM
aasm_initial_state :sleeping
aasm_state :sleeping
aasm_state :showering
aasm_state :working
aasm_state :dating
aasm_state :prettying_up

aasm_event :wakeup do
transitions :from => :sleeping, :to => [:showering, :working]
end

aasm_event :dress do
transitions :from => :sleeping, :to => :working, :on_transition => :wear_clothes
transitions :from => :showering, :to => [:working, :dating], :on_transition => Proc.new { |obj, *args| obj.wear_clothes(*args) }
transitions :from => :showering, :to => :prettying_up, :on_transition => [:condition_hair, :fix_hair]
end

def wear_clothes(shirt_color, trouser_type)
end

def condition_hair
end

def fix_hair
end
end
29 changes: 0 additions & 29 deletions spec/unit/aasm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -333,35 +333,6 @@ def @foo.aasm_event_failed(event, from)
end


class ChetanPatil
include AASM
aasm_initial_state :sleeping
aasm_state :sleeping
aasm_state :showering
aasm_state :working
aasm_state :dating
aasm_state :prettying_up

aasm_event :wakeup do
transitions :from => :sleeping, :to => [:showering, :working]
end

aasm_event :dress do
transitions :from => :sleeping, :to => :working, :on_transition => :wear_clothes
transitions :from => :showering, :to => [:working, :dating], :on_transition => Proc.new { |obj, *args| obj.wear_clothes(*args) }
transitions :from => :showering, :to => :prettying_up, :on_transition => [:condition_hair, :fix_hair]
end

def wear_clothes(shirt_color, trouser_type)
end

def condition_hair
end

def fix_hair
end
end


describe ChetanPatil do
it 'should transition to specified next state (sleeping to showering)' do
Expand Down

0 comments on commit 31258e7

Please sign in to comment.