Permalink
Browse files

specs are passing i think

  • Loading branch information...
1 parent c23bcfa commit bf2f16172d69ad205e3a31ba0f441c1c90acecc0 @ryan-allen committed Jan 16, 2009
Showing with 11 additions and 9 deletions.
  1. +5 −4 lib/workflow.rb
  2. +1 −0 specs/active_record_spec.rb
  3. +5 −5 specs/workflow_spec.rb
View
@@ -174,6 +174,7 @@ def initialize(msg = nil)
def initialize(states, on_transition, meta = {}, reconstitute_at = nil)
Workflow.logger.debug "Creating workflow instance"
@states, @on_transition, @meta = states, on_transition, meta
+ @context = self
if reconstitute_at.nil?
transition(nil, states.first, nil)
else
@@ -318,22 +319,22 @@ def transition(from, to, name, *args)
end
def run_on_transition(from, to, event, *args)
- self.instance_exec(from.name, to.name, event, *args, &on_transition) if on_transition
+ context.instance_exec(from.name, to.name, event, *args, &on_transition) if on_transition
end
def run_action(action, *args)
- self.instance_exec(*args, &action) if action
+ context.instance_exec(*args, &action) if action
end
def run_on_entry(state, prior_state, triggering_event, *args)
if state.on_entry
- self.instance_exec(prior_state.name, triggering_event, *args, &state.on_entry)
+ context.instance_exec(prior_state.name, triggering_event, *args, &state.on_entry)
@kofno
kofno Mar 27, 2009

This throws an nil exception if an on_entry block is added to the first state in a workflow.

end
end
def run_on_exit(state, new_state, triggering_event, *args)
if state and state.on_exit
- self.instance_exec(new_state.name, triggering_event, *args, &state.on_exit)
+ context.instance_exec(new_state.name, triggering_event, *args, &state.on_exit)
end
end
@@ -185,6 +185,7 @@ class EasyAccess < ActiveRecord::Base
name.upcase! unless name.nil?
end
end
+ state :second
end
end
@@ -191,22 +191,22 @@
before do
Workflow.specify do
- state(:first) { event(:next, :transitions_to => :second) {|i| context.record i }}
- state(:second) { event(:next, :transitions_to => :third) {|i| context.record i }}
+ state(:first) { event(:next, :transitions_to => :second) {|i| record i }}
+ state(:second) { event(:next, :transitions_to => :third) {|i| record i }}
state :third do
event(:next, :transitions_to => :fourth)
event(:back, :transitions_to => :second) {|i| record i }
on_entry do |prior_state, triggering_event, *event_args|
- context.record 'entered :third'
+ record 'entered :third'
end
on_exit do |new_state, triggering_event, *event_args|
- context.record 'exited :third'
+ record 'exited :third'
end
end
state :fourth
on_transition do |from, to, triggering_event, *args|
begin
- context.record "transitioned from #{from} to #{to}"
+ record "transitioned from #{from} to #{to}"
rescue
# ok ok shit fuck cunt arse motherfucker, nomethoderror
# TODO: reraising on our behalfs were casing this to bunk up

0 comments on commit bf2f161

Please sign in to comment.