Skip to content
This repository has been archived by the owner on Mar 5, 2020. It is now read-only.

Commit

Permalink
Naive filter by workitem fields
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethkalmer committed Dec 9, 2009
1 parent c1edfc6 commit 48ebf8a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/ruote-kit/resources/workitems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ class RuoteKit::Application
@workitems = @participants.inject([]) do |memo, part|
memo.concat store_participant.by_participant( part )
end

elsif params[:fields]
# TODO: Optimize this
@workitems = store_participant.all.inject([]) do |memo, wi|
params[:fields].each do |(f,v)|
if wi.fields.keys.include?( f ) && wi.fields[f] == v
memo << wi
end
end

memo
end

else
@workitems = store_participant.all
end
Expand Down
32 changes: 32 additions & 0 deletions spec/resources/workitems_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -303,4 +303,36 @@
last_response.should be_ok
end
end

describe "on fields" do
before(:each) do
@wfid_1 = launch_test_process do
Ruote.process_definition :name => 'one' do
set :field => 'foo', :value => 'bar'

sequence do
nada
end
end
end
@wfid_2 = launch_test_process do
Ruote.process_definition :name => 'one' do
set :field => 'foo', :value => 'baz'

sequence do
nada
end
end
end
end

it "should filter accordingly" do
get '/workitems.json', :fields => { 'foo' => 'bar' }

last_response.should be_ok

last_response.json_body['workitems'].size.should be(1)
last_response.json_body['workitems'].first['wfid'].should == @wfid_1
end
end
end

0 comments on commit 48ebf8a

Please sign in to comment.