Permalink
Browse files

return value when changing a model state

  • Loading branch information...
1 parent c908e64 commit 8bba8df1e24c9f15f3f32c102a6d1fe40b7f1d7e @indrekj indrekj committed with geekq Aug 3, 2010
Showing with 8 additions and 5 deletions.
  1. +6 −3 lib/workflow.rb
  2. +2 −2 test/main_test.rb
View
@@ -161,8 +161,10 @@ def process_event!(name, *args)
else
check_transition(event)
run_on_transition(current_state, spec.states[event.transitions_to], name, *args)
- transition(current_state, spec.states[event.transitions_to], name, *args)
- return_value
+ transition_value = transition(
+ current_state, spec.states[event.transitions_to], name, *args
+ )
+ return_value.nil? ? transition_value : return_value
end
end
@@ -206,8 +208,9 @@ def check_transition(event)
def transition(from, to, name, *args)
run_on_exit(from, to, name, *args)
- persist_workflow_state to.to_s
+ val = persist_workflow_state to.to_s
run_on_entry(to, from, name, *args)
+ val
end
def run_on_transition(from, to, event, *args)
View
@@ -96,13 +96,13 @@ def assert_state(title, expected_state, klass = Order)
test 'immediately save the new workflow_state on state machine transition' do
o = assert_state 'some order', 'accepted'
- o.ship!
+ assert o.ship!
assert_state 'some order', 'shipped'
end
test 'immediately save the new workflow_state on state machine transition with custom column name' do
o = assert_state 'some order', 'accepted', LegacyOrder
- o.ship!
+ assert o.ship!
assert_state 'some order', 'shipped', LegacyOrder
end

0 comments on commit 8bba8df

Please sign in to comment.