Skip to content

Commit

Permalink
deal with orphan workitems. Closes kennethkalmergh-15
Browse files Browse the repository at this point in the history
  • Loading branch information
jmettraux committed Jan 17, 2012
1 parent 94c52c3 commit b8bf2fd
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
@@ -1,6 +1,6 @@
GIT
remote: git://github.com/jmettraux/ruote.git
revision: 2fc23b0a32fc382ddb4bc359584cb9fa16b4a018
revision: 7c27d58a718cda9d800eb235589d4484a32e8fe2
specs:
ruote (2.3.0)
parslet (= 1.2.3)
Expand Down
5 changes: 3 additions & 2 deletions lib/ruote-kit/resources/expressions.rb
Expand Up @@ -7,17 +7,18 @@ class RuoteKit::Application

@process, @expression, fei = fetch_pef

return http_error(404) unless @process

if fei

return http_error(404) unless @expression

etag @expression.to_h['_rev']

respond_with :expression

else

return http_error(404) if @process.nil? or @process.expressions.empty?

respond_with :expressions
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ruote-kit/resources/processes.rb
Expand Up @@ -24,7 +24,7 @@ class RuoteKit::Application

@process = RuoteKit.engine.process(params[:wfid])

return http_error(404) unless @process
return http_error(404) if @process.nil? or @process.expressions.empty?

@pins = @process.leaves.collect { |fexp|
label = if fexp.error
Expand Down
6 changes: 5 additions & 1 deletion lib/ruote-kit/views/process.html.haml
Expand Up @@ -57,12 +57,16 @@
%td
- if @process.launched_time
= Time.parse(@process.launched_time).localtime.strftime('%Y/%m/%d %H:%M:%S')
- else
?
%tr
%td
last active
%td
- if @process.last_active
= Time.parse(@process.last_active).localtime.strftime('%Y/%m/%d %H:%M:%S')
- else
?
%tr
%td
root exp state
Expand All @@ -72,7 +76,7 @@
%td
tags
%td
&= @process.tags.collect { |ta| ta.first }.join(', ')
&= (@process.tags || []).collect { |ta| ta.first }.join(', ')

%tr
%td.no_border{ :colspan => 2 }
Expand Down
141 changes: 141 additions & 0 deletions spec/cases/orphan_workitem_spec.rb
@@ -0,0 +1,141 @@

require 'spec_helper'


describe RuoteKit do

context 'with an orphan workitem' do

before(:all) do

prepare_engine_with_participants

pdef = Ruote.process_definition :name => 'test' do
toto
end

#RuoteKit.engine.noisy = true

@wfid = RuoteKit.engine.launch(pdef)
RuoteKit.engine.wait_for(:toto)
RuoteKit.engine.wait_for(1)

@wi = RuoteKit.engine.storage_participant.first

RuoteKit.engine.cancel(@wfid)
RuoteKit.engine.wait_for('terminated')

@wi.h.delete('_rev')
RuoteKit.engine.storage.put(@wi.h)
end

after(:all) do

shutdown_and_purge_engine
end

describe 'GET /_ruote/processes' do

it 'does not list the process' do

get '/_ruote/processes.json'

last_response.status.should == 200

last_response.json_body['processes'].should == []
end
end

describe 'GET /_ruote/workitems' do

it 'lists the orphan workitem' do

get '/_ruote/workitems.json'

last_response.status.should == 200

last_response.json_body['workitems'].size.should == 1
last_response.json_body['workitems'][0]['id'].should == @wi.sid

links = last_response.json_body['workitems'][0]['links']

link_for(links, 'self').should ==
"/_ruote/workitems/#{@wi.sid}"
link_for(links, '#expression').should ==
"/_ruote/expressions/#{@wi.sid}"
end
end

describe 'GET /_ruote/workitems/:wfid' do

it 'lists the orphan workitems' do

get "/_ruote/workitems/#{@wi.wfid}.json"

last_response.status.should == 200

last_response.json_body['workitems'].size.should == 1
last_response.json_body['workitems'][0]['id'].should == @wi.sid
end
end

describe 'GET /_ruote/workitems/:fei' do

it 'renders the workitem' do

get "/_ruote/workitems/#{@wi.sid}.json"

last_response.status.should == 200

links = last_response.json_body['links']

link_for(links, 'self').should == "/_ruote/workitems/#{@wi.sid}"
end
end

describe 'GET /_ruote/processes/:wfid' do

it 'goes 404 (HTML)' do

get "/_ruote/processes/#{@wi.wfid}"

last_response.status.should == 404
end

it 'goes 404 (JSON)' do

get "/_ruote/processes/#{@wi.wfid}.json"

last_response.status.should == 404
end
end

describe 'GET /_ruote/expressions/:fei' do

it 'goes 404' do

get "/_ruote/expressions/#{@wi.sid}.json"

last_response.status.should == 404
end
end

describe 'GET /_ruote/expressions/:wfid' do

it 'goes 404 (HTML)' do

get "/_ruote/expressions/#{@wi.wfid}"

last_response.status.should == 404
end

it 'goes 404 (JSON)' do

get "/_ruote/expressions/#{@wi.wfid}.json"

last_response.status.should == 404
end
end
end
end

0 comments on commit b8bf2fd

Please sign in to comment.