Permalink
Browse files

implement attach :fields and :merge_fields opts

  • Loading branch information...
1 parent bc5f3a9 commit 414e52099868d3c955adcbbf1b31d8760c7fb5bd @jmettraux committed Oct 4, 2012
Showing with 49 additions and 7 deletions.
  1. +16 −5 lib/ruote/dashboard.rb
  2. +33 −2 test/functional/ft_79_attach.rb
View
@@ -183,28 +183,39 @@ def launch_single(process_definition, fields={}, variables={}, root_stash=nil)
#
# Accepts the fei as a Hash or as a FlowExpressionId instance.
#
+ # By default, the workitem of the expression you attach to provides
+ # the initial workitem for the attached branch. By using the
+ # :fields/:workitem or :merge_fields options, one can change that.
+ #
# Returns the fei of the attached [root] expression
# (as a FlowExpressionId instance).
#
- def attach(fei, definition)
+ def attach(fei, definition, opts={})
fei = Ruote::FlowExpressionId.extract_h(fei)
+ fe = fetch_flow_expression(fei)
+
cfei = fei.merge(
'expid' => '0',
'subid' => Ruote.generate_subid(fei.inspect))
- fe = fetch_flow_expression(fei)
-
tree = @context.reader.read(definition)
tree[0] = 'sequence'
+ fields = fe.h.applied_workitem['fields']
+ if fs = opts[:fields] || opts[:workitem]
+ fields = fs
+ elsif fs = opts[:merge_fields]
+ fields.merge!(fs)
+ end
+
@context.storage.put_msg(
'launch', # "apply" is OK, but "launch" stands out better
- 'fei' => cfei,
'parent_id' => fei,
+ 'fei' => cfei,
'tree' => tree,
- 'workitem' => fe.h.applied_workitem,
+ 'workitem' => { 'fields' => fields },
'attached' => true)
Ruote::FlowExpressionId.new(cfei)
@@ -20,11 +20,12 @@ def test_attach
bravo
end
- wfid = @dashboard.launch(pdef)
+ wfid = @dashboard.launch(pdef, 'message' => 'hello planet')
r = @dashboard.wait_for('dispatched')
adef = Ruote.define do
echo '${v:message}'
+ echo '${f:message}'
end
fei = @dashboard.attach(r['fei'], adef)
@@ -35,11 +36,41 @@ def test_attach
assert_equal '0', fei.expid
assert_equal wfid, fei.wfid
- assert_equal 'hello world', @tracer.to_s
+ assert_equal "hello world\nhello planet", @tracer.to_s
assert_equal 0, ps.errors.size
assert_equal 2, ps.expressions.size
assert_equal 1, ps.stored_workitems.size
end
+
+ def test_attach_fields_option
+
+ @dashboard.register '.+', Ruote::StorageParticipant
+
+ pdef = Ruote.define do
+ set 'v:message' => 'hello world'
+ bravo
+ end
+
+ wfid = @dashboard.launch(pdef, 'message' => 'hello planet')
+ r = @dashboard.wait_for('dispatched')
+
+ adef = Ruote.define do
+ echo '${v:message}'
+ echo '${f:message}'
+ end
+
+ fei = @dashboard.attach(r['fei'], adef, :fields => { 'message' => 'nada' })
+ r = @dashboard.wait_for('ceased')
+
+ ps = @dashboard.ps(wfid)
+
+ assert_equal "hello world\nnada", @tracer.to_s
+ end
+
+ # Well, let's not test those 3 lines of code.
+ #
+ #def test_attach_merge_fields_option
+ #end
end

0 comments on commit 414e520

Please sign in to comment.