ruote-kit 2.2.0.3 → 2.3.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. data/CHANGELOG.txt +28 -1
  2. data/CREDITS.txt +8 -2
  3. data/LICENSE.txt +1 -1
  4. data/Rakefile +21 -9
  5. data/lib/ruote-kit.rb +13 -4
  6. data/lib/ruote-kit/core_ext.rb +15 -0
  7. data/lib/ruote-kit/helpers/json_helpers.rb +22 -7
  8. data/lib/ruote-kit/helpers/link_helpers.rb +9 -7
  9. data/lib/ruote-kit/helpers/pagination_helpers.rb +1 -2
  10. data/lib/ruote-kit/helpers/render_helpers.rb +1 -1
  11. data/lib/ruote-kit/public/_ruote/images/favicon.png +0 -0
  12. data/lib/ruote-kit/public/_ruote/images/{ruote_buttons.png → ruote-buttons.png} +0 -0
  13. data/lib/ruote-kit/public/_ruote/images/ruote.png +0 -0
  14. data/lib/ruote-kit/public/_ruote/javascripts/foolbox-all.min.js +3 -0
  15. data/lib/ruote-kit/public/_ruote/javascripts/jquery-1.9.1.min.js +5 -0
  16. data/lib/ruote-kit/public/_ruote/javascripts/rk.js +68 -17
  17. data/lib/ruote-kit/public/_ruote/javascripts/ruote-fluo-all.min.js +3 -0
  18. data/lib/ruote-kit/public/_ruote/stylesheets/rk.css +82 -12
  19. data/lib/ruote-kit/public/_ruote/stylesheets/ruote-buttons.png +0 -0
  20. data/lib/ruote-kit/public/_ruote/stylesheets/ruote-fluo-editor.css +9 -6
  21. data/lib/ruote-kit/public/_ruote/stylesheets/ruote-fluo.css +62 -0
  22. data/lib/ruote-kit/resources/errors.rb +8 -3
  23. data/lib/ruote-kit/resources/expressions.rb +38 -35
  24. data/lib/ruote-kit/resources/participants.rb +1 -1
  25. data/lib/ruote-kit/resources/processes.rb +61 -4
  26. data/lib/ruote-kit/resources/workitems.rb +4 -4
  27. data/lib/ruote-kit/version.rb +1 -1
  28. data/lib/ruote-kit/views/_pagination.html.haml +2 -2
  29. data/lib/ruote-kit/views/_tree_editor.html.haml +63 -30
  30. data/lib/ruote-kit/views/error.html.haml +50 -9
  31. data/lib/ruote-kit/views/errors.html.haml +1 -1
  32. data/lib/ruote-kit/views/expression.html.haml +83 -33
  33. data/lib/ruote-kit/views/expressions.html.haml +23 -8
  34. data/lib/ruote-kit/views/http_error.html.haml +9 -2
  35. data/lib/ruote-kit/views/layout.html.haml +14 -13
  36. data/lib/ruote-kit/views/process.html.haml +75 -20
  37. data/lib/ruote-kit/views/processes.html.haml +9 -3
  38. data/lib/ruote-kit/views/processes_new.html.haml +19 -2
  39. data/lib/ruote-kit/views/schedules.html.haml +2 -2
  40. data/lib/ruote-kit/views/workitem.html.haml +17 -6
  41. data/ruote-kit.gemspec +9 -7
  42. data/spec/cases/orphan_workitem_spec.rb +141 -0
  43. data/spec/core_ext_spec.rb +19 -0
  44. data/spec/resources/errors_spec.rb +182 -156
  45. data/spec/resources/expressions_spec.rb +497 -379
  46. data/spec/resources/index_spec.rb +5 -5
  47. data/spec/resources/participants_spec.rb +64 -75
  48. data/spec/resources/processes_spec.rb +396 -277
  49. data/spec/resources/schedules_spec.rb +92 -76
  50. data/spec/resources/workitems_spec.rb +352 -343
  51. data/spec/ruote-kit_configure_spec.rb +41 -13
  52. data/spec/spec_helper.rb +6 -8
  53. data/spec/support/link_helper.rb +11 -0
  54. data/spec/webapp_helpers_spec.rb +29 -23
  55. metadata +161 -180
  56. data/README.rdoc +0 -313
  57. data/lib/ruote-kit/public/_ruote/images/favicon.ico +0 -0
  58. data/lib/ruote-kit/public/_ruote/javascripts/jquery-1.4.2.min.js +0 -154
  59. data/lib/ruote-kit/public/_ruote/javascripts/ruote-fluo-editor.js +0 -548
  60. data/lib/ruote-kit/public/_ruote/javascripts/ruote-fluo.js +0 -1118
@@ -1,10 +1,10 @@
1
1
 
2
- require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
2
+ require 'spec_helper'
3
3
 
4
4
 
5
5
  describe 'GET /' do
6
6
 
7
- it 'should return a welcome message in HTML be default' do
7
+ it 'returns a welcome message in HTML be default' do
8
8
 
9
9
  get '/_ruote'
10
10
 
@@ -15,7 +15,7 @@ describe 'GET /' do
15
15
  last_response.should match(/<title>/)
16
16
  end
17
17
 
18
- it 'should return a version string if JSON is requested' do
18
+ it 'returns a version string if JSON is requested' do
19
19
 
20
20
  header 'Accept', 'application/json'
21
21
 
@@ -32,7 +32,7 @@ end
32
32
 
33
33
  describe 'Generic error handling' do
34
34
 
35
- it 'should give our own 404 page (HTML)' do
35
+ it 'gives our own 404 page (HTML)' do
36
36
 
37
37
  get '/kenneth'
38
38
 
@@ -43,7 +43,7 @@ describe 'Generic error handling' do
43
43
  last_response.should match(/resource not found/)
44
44
  end
45
45
 
46
- it 'should give our own 404 data (JSON)' do
46
+ it 'gives our own 404 data (JSON)' do
47
47
 
48
48
  get '/kenneth.json'
49
49
 
@@ -1,119 +1,108 @@
1
1
 
2
- require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
2
+ require 'spec_helper'
3
3
 
4
4
 
5
- describe 'GET /_ruote/participants' do
5
+ describe '/_ruote/participants' do
6
6
 
7
7
  before(:each) do
8
-
9
8
  prepare_engine
10
9
  end
11
-
12
10
  after(:each) do
13
-
14
11
  shutdown_and_purge_engine
15
12
  end
16
13
 
17
- describe 'without any participant' do
14
+ describe 'GET /_ruote/participants' do
18
15
 
19
- it 'should give an empty list (HTML)' do
16
+ context 'without any participant' do
20
17
 
21
- get '/_ruote/participants'
18
+ it 'gives an empty list (HTML)' do
22
19
 
23
- last_response.status.should be(200)
24
- end
20
+ get '/_ruote/participants'
25
21
 
26
- it 'should give an empty array (JSON)' do
22
+ last_response.status.should be(200)
23
+ end
27
24
 
28
- get '/_ruote/participants.json'
25
+ it 'gives an empty array (JSON)' do
29
26
 
30
- last_response.status.should be(200)
27
+ get '/_ruote/participants.json'
31
28
 
32
- body = last_response.json_body
33
- body.should have_key('participants')
29
+ last_response.status.should be(200)
34
30
 
35
- body['participants'].should be_empty
36
- end
37
- end
31
+ body = last_response.json_body
32
+ body.should have_key('participants')
38
33
 
39
- describe 'with participant' do
34
+ body['participants'].should be_empty
35
+ end
36
+ end
40
37
 
41
- before(:each) do
38
+ context 'with participant' do
42
39
 
43
- register_participants
44
- end
40
+ before(:each) do
41
+ register_participants
42
+ end
45
43
 
46
- it 'should give participant information back (HTML)' do
44
+ it 'gives participant information back (HTML)' do
47
45
 
48
- get '/_ruote/participants'
46
+ get '/_ruote/participants'
49
47
 
50
- last_response.status.should be(200)
51
- end
48
+ last_response.status.should be(200)
49
+ end
52
50
 
53
- it 'should give participant information back (JSON)' do
51
+ it 'gives participant information back (JSON)' do
54
52
 
55
- get '/_ruote/participants.json'
53
+ get '/_ruote/participants.json'
56
54
 
57
- last_response.status.should be(200)
58
- last_response.json_body['participants'].should_not be_empty
55
+ last_response.status.should be(200)
56
+ last_response.json_body['participants'].should_not be_empty
57
+ end
59
58
  end
60
59
  end
61
- end
62
60
 
63
- describe 'PUT /_ruote/participants' do
61
+ describe 'PUT /_ruote/participants' do
64
62
 
65
- before(:each) do
63
+ it 'updates the list (HTML)' do
66
64
 
67
- prepare_engine
68
- end
65
+ put(
66
+ '/_ruote/participants',
67
+ 'regex_0' => '^alice$',
68
+ 'classname_0' => 'Ruote::StorageParticipant',
69
+ 'options_0' => '{}',
70
+ 'regex_1' => '^bravo$',
71
+ 'classname_1' => 'Ruote::StorageParticipant',
72
+ 'options_1' => '{}')
69
73
 
70
- after(:each) do
74
+ last_response.should be_redirect
75
+ last_response['Location'].should == 'http://example.org/_ruote/participants'
71
76
 
72
- shutdown_and_purge_engine
73
- end
74
-
75
- it 'should update the list (HTML)' do
77
+ RuoteKit.engine.participant_list.collect { |pe| pe.regex }.should == [
78
+ '^alice$', '^bravo$'
79
+ ]
80
+ end
76
81
 
77
- put(
78
- '/_ruote/participants',
79
- 'regex_0' => '^alice$',
80
- 'classname_0' => 'Ruote::StorageParticipant',
81
- 'options_0' => '{}',
82
- 'regex_1' => '^bravo$',
83
- 'classname_1' => 'Ruote::StorageParticipant',
84
- 'options_1' => '{}')
82
+ it 'updates the list (JSON)' do
85
83
 
86
- last_response.should be_redirect
87
- last_response['Location'].should == '/_ruote/participants'
84
+ list = {
85
+ 'participants' => [
86
+ { 'regex' => '^alice$',
87
+ 'classname' => 'Ruote::StorageParticipant',
88
+ 'options' => {} },
89
+ { 'regex' => '^bravo$',
90
+ 'classname' => 'Ruote::StorageParticipant',
91
+ 'options' => {} }
92
+ ]
93
+ }
88
94
 
89
- RuoteKit.engine.participant_list.collect { |pe| pe.regex }.should == [
90
- '^alice$', '^bravo$'
91
- ]
92
- end
95
+ put(
96
+ '/_ruote/participants.json',
97
+ Rufus::Json.encode(list),
98
+ { 'CONTENT_TYPE' => 'application/json' })
93
99
 
94
- it 'should update the list (JSON)' do
100
+ last_response.status.should be(200)
95
101
 
96
- list = {
97
- 'participants' => [
98
- { 'regex' => '^alice$',
99
- 'classname' => 'Ruote::StorageParticipant',
100
- 'options' => {} },
101
- { 'regex' => '^bravo$',
102
- 'classname' => 'Ruote::StorageParticipant',
103
- 'options' => {} }
102
+ RuoteKit.engine.participant_list.collect { |pe| pe.regex }.should == [
103
+ '^alice$', '^bravo$'
104
104
  ]
105
- }
106
-
107
- put(
108
- '/_ruote/participants.json',
109
- Rufus::Json.encode(list),
110
- { 'CONTENT_TYPE' => 'application/json' })
111
-
112
- last_response.status.should be(200)
113
-
114
- RuoteKit.engine.participant_list.collect { |pe| pe.regex }.should == [
115
- '^alice$', '^bravo$'
116
- ]
105
+ end
117
106
  end
118
107
  end
119
108
 
@@ -1,436 +1,555 @@
1
1
 
2
- require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
3
-
4
-
5
- def process_links(wfid)
6
- [
7
- { 'href' => "/_ruote/processes/#{wfid}",
8
- 'rel' => 'self' },
9
- { 'href' => "/_ruote/processes/#{wfid}",
10
- 'rel' => 'http://ruote.rubyforge.org/rels.html#process' },
11
- { 'href' => "/_ruote/expressions/#{wfid}",
12
- 'rel' => 'http://ruote.rubyforge.org/rels.html#process_expressions' },
13
- { 'href' => "/_ruote/workitems/#{wfid}",
14
- 'rel' => 'http://ruote.rubyforge.org/rels.html#process_workitems' },
15
- { 'href' => "/_ruote/errors/#{wfid}",
16
- 'rel' => 'http://ruote.rubyforge.org/rels.html#process_errors' },
17
- { 'href' => "/_ruote/schedules/#{wfid}",
18
- 'rel' => 'http://ruote.rubyforge.org/rels.html#process_schedules' }
19
- ]
20
- end
2
+ require 'spec_helper'
21
3
 
22
4
 
23
- describe 'GET /_ruote/processes' do
5
+ describe '/_ruote/processes' do
24
6
 
25
7
  before(:each) do
26
-
27
8
  prepare_engine_with_participants
28
9
  end
29
-
30
10
  after(:each) do
31
-
32
11
  shutdown_and_purge_engine
33
12
  end
34
13
 
35
- describe 'without any running processes' do
14
+ def process_links(wfid)
15
+ [
16
+ { 'href' => "/_ruote/processes/#{wfid}",
17
+ 'rel' => 'self' },
18
+ { 'href' => "/_ruote/processes/#{wfid}",
19
+ 'rel' => 'http://ruote.rubyforge.org/rels.html#process' },
20
+ { 'href' => "/_ruote/expressions/#{wfid}",
21
+ 'rel' => 'http://ruote.rubyforge.org/rels.html#process_expressions' },
22
+ { 'href' => "/_ruote/workitems/#{wfid}",
23
+ 'rel' => 'http://ruote.rubyforge.org/rels.html#process_workitems' },
24
+ { 'href' => "/_ruote/errors/#{wfid}",
25
+ 'rel' => 'http://ruote.rubyforge.org/rels.html#process_errors' },
26
+ { 'href' => "/_ruote/schedules/#{wfid}",
27
+ 'rel' => 'http://ruote.rubyforge.org/rels.html#process_schedules' }
28
+ ]
29
+ end
30
+
31
+ describe 'GET /_ruote/processes' do
36
32
 
37
- it 'should give no processes back (HTML)' do
33
+ context 'without any running processes' do
38
34
 
39
- get '/_ruote/processes?limit=100&skip=0'
35
+ it 'gives no processes back (HTML)' do
40
36
 
41
- last_response.status.should == 200
37
+ get '/_ruote/processes?limit=100&skip=0'
38
+
39
+ last_response.status.should == 200
40
+
41
+ last_response.should have_selector(
42
+ 'a', :content => 'as JSON')
43
+ last_response.should have_selector(
44
+ 'a', :href => '/_ruote/processes.json?limit=100&skip=0')
45
+ end
42
46
 
43
- last_response.should have_selector(
44
- 'a', :content => 'as JSON')
45
- last_response.should have_selector(
46
- 'a', :href => '/_ruote/processes.json?limit=100&skip=0')
47
+ it 'gives an empty array (JSON)' do
48
+
49
+ get '/_ruote/processes.json'
50
+
51
+ last_response.status.should == 200
52
+
53
+ body = last_response.json_body
54
+ body.should have_key('processes')
55
+
56
+ body['processes'].should be_empty
57
+ end
47
58
  end
48
59
 
49
- it 'should give an empty array (JSON)' do
60
+ context 'with running processes' do
50
61
 
51
- get '/_ruote/processes.json'
62
+ before(:each) do
63
+ @wfid = launch_nada_process
64
+ end
52
65
 
53
- last_response.status.should == 200
66
+ it 'gives process information back (HTML)' do
54
67
 
55
- body = last_response.json_body
56
- body.should have_key('processes')
68
+ get '/_ruote/processes'
69
+
70
+ last_response.status.should == 200
71
+ end
57
72
 
58
- body['processes'].should be_empty
73
+ it 'gives process information back (JSON)' do
74
+
75
+ get '/_ruote/processes.json'
76
+
77
+ last_response.status.should == 200
78
+
79
+ body = last_response.json_body
80
+
81
+ body['processes'].should_not be_empty
82
+
83
+ body['links'].should == [
84
+ { 'href' => '/_ruote',
85
+ 'rel' => 'http://ruote.rubyforge.org/rels.html#root' },
86
+ { 'href' => '/_ruote/processes',
87
+ 'rel' => 'http://ruote.rubyforge.org/rels.html#processes' },
88
+ { 'href' => '/_ruote/workitems',
89
+ 'rel' => 'http://ruote.rubyforge.org/rels.html#workitems' },
90
+ { 'href' => '/_ruote/errors',
91
+ 'rel' => 'http://ruote.rubyforge.org/rels.html#errors' },
92
+ { 'href' => '/_ruote/participants',
93
+ 'rel' => 'http://ruote.rubyforge.org/rels.html#participants' },
94
+ { 'href' => '/_ruote/schedules',
95
+ 'rel' => 'http://ruote.rubyforge.org/rels.html#schedules' },
96
+ { 'href' => '/_ruote/history',
97
+ 'rel' => 'http://ruote.rubyforge.org/rels.html#history' },
98
+ { 'href' => '/_ruote/processes',
99
+ 'rel' => 'self' },
100
+ { 'href' => '/_ruote/processes',
101
+ 'rel' => 'all' },
102
+ { 'href' => '/_ruote/processes?limit=100&skip=0',
103
+ 'rel' => 'first' },
104
+ { 'href' => '/_ruote/processes?limit=100&skip=0',
105
+ 'rel' => 'last' },
106
+ { 'href' => '/_ruote/processes?limit=100&skip=0',
107
+ 'rel' => 'previous' },
108
+ { 'href' => '/_ruote/processes?limit=100&skip=0',
109
+ 'rel' => 'next' } ]
110
+
111
+ body['processes'].first['links'].should == process_links(@wfid)
112
+ end
59
113
  end
60
114
  end
61
115
 
62
- describe 'with running processes' do
116
+ describe 'GET /_ruote/processes/:wfid' do
63
117
 
64
- before(:each) do
65
- @wfid = launch_nada_process
66
- end
118
+ context 'with a running process' do
67
119
 
68
- it 'should give process information back (HTML)' do
120
+ before(:each) do
121
+ @wfid = launch_nada_process
122
+ end
69
123
 
70
- get '/_ruote/processes'
124
+ it 'gives process information back (HTML)' do
71
125
 
72
- last_response.status.should == 200
73
- end
126
+ get "/_ruote/processes/#{@wfid}"
74
127
 
75
- it 'should give process information back (JSON)' do
128
+ last_response.status.should == 200
76
129
 
77
- get '/_ruote/processes.json'
130
+ last_response.should have_selector(
131
+ 'a[rel="http://ruote.rubyforge.org/rels.html#process_schedules"]')
78
132
 
79
- last_response.status.should == 200
133
+ last_response.should have_selector(
134
+ 'td')
135
+ last_response.should have_selector(
136
+ 'input[name="_method"][type="hidden"][value="DELETE"]')
137
+ last_response.should have_selector(
138
+ 'input[name="_method"][type="hidden"][value="PUT"]')
139
+ end
140
+
141
+ it 'gives process information back (JSON)' do
80
142
 
81
- body = last_response.json_body
82
-
83
- body['processes'].should_not be_empty
84
-
85
- body['links'].should == [
86
- { 'href' => '/_ruote',
87
- 'rel' => 'http://ruote.rubyforge.org/rels.html#root' },
88
- { 'href' => '/_ruote/processes',
89
- 'rel' => 'http://ruote.rubyforge.org/rels.html#processes' },
90
- { 'href' => '/_ruote/workitems',
91
- 'rel' => 'http://ruote.rubyforge.org/rels.html#workitems' },
92
- { 'href' => '/_ruote/errors',
93
- 'rel' => 'http://ruote.rubyforge.org/rels.html#errors' },
94
- { 'href' => '/_ruote/participants',
95
- 'rel' => 'http://ruote.rubyforge.org/rels.html#participants' },
96
- { 'href' => '/_ruote/schedules',
97
- 'rel' => 'http://ruote.rubyforge.org/rels.html#schedules' },
98
- { 'href' => '/_ruote/history',
99
- 'rel' => 'http://ruote.rubyforge.org/rels.html#history' },
100
- { 'href' => '/_ruote/processes',
101
- 'rel' => 'self' },
102
- { 'href' => '/_ruote/processes',
103
- 'rel' => 'all' },
104
- { 'href' => '/_ruote/processes?limit=100&skip=0',
105
- 'rel' => 'first' },
106
- { 'href' => '/_ruote/processes?limit=100&skip=0',
107
- 'rel' => 'last' },
108
- { 'href' => '/_ruote/processes?limit=100&skip=0',
109
- 'rel' => 'previous' },
110
- { 'href' => '/_ruote/processes?limit=100&skip=0',
111
- 'rel' => 'next' } ]
112
-
113
- body['processes'].first['links'].should == process_links(@wfid)
143
+ get "/_ruote/processes/#{@wfid}.json"
144
+
145
+ last_response.status.should == 200
146
+
147
+ body = last_response.json_body
148
+
149
+ body.should have_key('process')
150
+
151
+ body['process']['links'].should == process_links(@wfid)
152
+
153
+ body['process'].keys.sort.should == %w[
154
+ current_tree definition_name definition_revision detailed errors
155
+ expressions last_active launched_time links original_tree
156
+ root_expression_state stored_workitems tags type variables wfid
157
+ workitems
158
+ ]
159
+ end
114
160
  end
115
- end
116
- end
117
161
 
118
- describe 'GET /_ruote/processes/wfid' do
162
+ context 'without a running process' do
119
163
 
120
- before(:each) do
164
+ it 'goes 404 correctly (HTML)' do
121
165
 
122
- prepare_engine_with_participants
123
- end
166
+ get '/_ruote/processes/foo'
124
167
 
125
- after(:each) do
168
+ last_response.status.should == 404
126
169
 
127
- shutdown_and_purge_engine
128
- end
170
+ last_response.should match(/resource not found/)
171
+ end
129
172
 
130
- describe 'with a running process' do
173
+ it 'goes 404 correctly (JSON)' do
131
174
 
132
- before(:each) do
175
+ get '/_ruote/processes/foo.json'
176
+
177
+ last_response.status.should == 404
178
+
179
+ last_response.json_body.keys.should include('http_error')
133
180
 
134
- @wfid = launch_nada_process
181
+ last_response.json_body['http_error'].should == {
182
+ 'code' => 404, 'message' => 'resource not found', 'cause' => ''
183
+ }
184
+ end
135
185
  end
186
+ end
187
+
188
+ describe 'GET /_ruote/processes/new' do
136
189
 
137
- it 'should give process information back (HTML)' do
190
+ it 'returns a launch form' do
138
191
 
139
- get "/_ruote/processes/#{@wfid}"
192
+ get '/_ruote/processes/new'
140
193
 
141
194
  last_response.status.should == 200
142
195
 
143
- last_response.should have_selector(
144
- 'a[rel="http://ruote.rubyforge.org/rels.html#process_schedules"]')
196
+ last_response.should_not have_selector('a', :content => 'as JSON')
145
197
  end
198
+ end
146
199
 
147
- it 'should give process information back (JSON)' do
200
+ describe 'PUT /_ruote/processes/:wfid' do
148
201
 
149
- get "/_ruote/processes/#{@wfid}.json"
202
+ context 'without a valid process' do
150
203
 
151
- last_response.status.should == 200
204
+ it 'goes 404 (HTML)' do
152
205
 
153
- body = last_response.json_body
206
+ put('/_ruote/processes/123-nada', :state => 'paused')
154
207
 
155
- body.should have_key('process')
208
+ last_response.status.should == 404
209
+ end
210
+
211
+ it 'goes 404 (JSON)' do
156
212
 
157
- body['process']['links'].should == process_links(@wfid)
213
+ put(
214
+ '/_ruote/processes/456-nada.json',
215
+ Rufus::Json.encode({ 'state' => 'paused' }),
216
+ { 'CONTENT_TYPE' => 'application/json' })
217
+
218
+ last_response.status.should == 404
219
+ end
158
220
  end
159
- end
160
221
 
161
- describe 'without a running process' do
222
+ context 'with a valid process' do
162
223
 
163
- it 'should 404 correctly (HTML)' do
224
+ before(:each) do
225
+ @wfid = launch_nada_process
226
+ end
164
227
 
165
- get '/_ruote/processes/foo'
228
+ it 'pauses the process (HTML)' do
166
229
 
167
- last_response.status.should == 404
230
+ put(
231
+ "/_ruote/processes/#{@wfid}",
232
+ :state => 'paused')
168
233
 
169
- last_response.should match(/resource not found/)
170
- end
234
+ last_response.status.should == 200
235
+ last_response.content_type.should match(/^text\/html\b/)
171
236
 
172
- it 'should 404 correctly (JSON)' do
237
+ sleep 0.500
173
238
 
174
- get '/_ruote/processes/foo.json'
239
+ RuoteKit.engine.ps(@wfid).root_expression.state.should == 'paused'
240
+ end
175
241
 
176
- last_response.status.should == 404
242
+ it 'resumes the process if paused (HTML)' do
177
243
 
178
- last_response.json_body.keys.should include('http_error')
244
+ RuoteKit.engine.pause(@wfid)
179
245
 
180
- last_response.json_body['http_error'].should == {
181
- 'code' => 404, 'message' => 'resource not found', 'cause' => ''
182
- }
183
- end
184
- end
185
- end
246
+ sleep 0.500
186
247
 
187
- describe 'GET /_ruote/processes/new' do
248
+ RuoteKit.engine.ps(@wfid).root_expression.state.should == 'paused'
188
249
 
189
- before(:each) do
250
+ put(
251
+ "/_ruote/processes/#{@wfid}",
252
+ :state => 'resuming')
190
253
 
191
- prepare_engine
192
- end
254
+ last_response.status.should == 200
255
+ last_response.content_type.should match(/^text\/html\b/)
193
256
 
194
- after(:each) do
257
+ sleep 0.500
195
258
 
196
- shutdown_and_purge_engine
197
- end
259
+ RuoteKit.engine.ps(@wfid).root_expression.state.should == nil
260
+ end
198
261
 
199
- it 'should return a launch form' do
262
+ it 'pauses the process (JSON)' do
200
263
 
201
- get '/_ruote/processes/new'
264
+ put(
265
+ "/_ruote/processes/#{@wfid}.json",
266
+ Rufus::Json.encode({ 'state' => 'paused' }),
267
+ { 'CONTENT_TYPE' => 'application/json' })
202
268
 
203
- last_response.status.should == 200
269
+ last_response.status.should == 200
270
+ last_response.json_body['process'].should_not == nil
204
271
 
205
- last_response.should_not have_selector('a', :content => 'as JSON')
206
- end
207
- end
272
+ sleep 0.500
208
273
 
209
- describe 'POST /_ruote/processes' do
274
+ RuoteKit.engine.ps(@wfid).root_expression.state.should == 'paused'
275
+ end
210
276
 
211
- before(:each) do
277
+ it 'resumes the process if paused (JSON)' do
212
278
 
213
- prepare_engine
214
- end
279
+ RuoteKit.engine.pause(@wfid)
215
280
 
216
- after(:each) do
281
+ sleep 0.500
217
282
 
218
- shutdown_and_purge_engine
283
+ RuoteKit.engine.ps(@wfid).root_expression.state.should == 'paused'
284
+
285
+ put(
286
+ "/_ruote/processes/#{@wfid}.json",
287
+ Rufus::Json.encode({ 'state' => 'resuming' }),
288
+ { 'CONTENT_TYPE' => 'application/json' })
289
+
290
+ last_response.status.should == 200
291
+ last_response.json_body['process'].should_not == nil
292
+
293
+ sleep 0.500
294
+
295
+ RuoteKit.engine.ps(@wfid).root_expression.state.should == nil
296
+ end
297
+ end
219
298
  end
220
299
 
221
- it 'should launch a valid process definition (JSON)' do
300
+ describe 'POST /_ruote/processes' do
222
301
 
223
- params = {
224
- :definition => %q{
225
- Ruote.process_definition :name => 'test' do
226
- wait '1m'
227
- end
302
+ it 'launches a valid process definition (JSON)' do
303
+
304
+ params = {
305
+ :definition => %q{
306
+ Ruote.process_definition :name => 'test' do
307
+ wait '1m'
308
+ end
309
+ }
228
310
  }
229
- }
230
311
 
231
- post(
232
- '/_ruote/processes.json',
233
- Rufus::Json.encode(params),
234
- { 'CONTENT_TYPE' => 'application/json' })
312
+ post(
313
+ '/_ruote/processes.json',
314
+ Rufus::Json.encode(params),
315
+ { 'CONTENT_TYPE' => 'application/json' })
235
316
 
236
- last_response.status.should == 201
317
+ last_response.status.should == 201
237
318
 
238
- last_response.json_body['launched'].should match(/[0-9a-z\-]+/)
319
+ last_response.json_body['launched'].should match(/[0-9a-z\-]+/)
239
320
 
240
- sleep 0.4
321
+ sleep 0.4
241
322
 
242
- engine.processes.should_not be_empty
243
- end
323
+ engine.processes.should_not be_empty
324
+ end
244
325
 
245
- it 'should launch a valid process definition with fields (JSON)' do
326
+ it 'launches a process definition (radial) (JSON)' do
246
327
 
247
- params = {
248
- :definition => %q{
249
- Ruote.process_definition :name => 'test' do
250
- echo '${f:foo}'
251
- end
252
- },
253
- :fields => { :foo => 'bar' }
254
- }
328
+ params = {
329
+ :definition => %q{
330
+ define 'my process'
331
+ wait '1m'
332
+ }
333
+ }
255
334
 
256
- post(
257
- '/_ruote/processes.json',
258
- Rufus::Json.encode(params),
259
- { 'CONTENT_TYPE' => 'application/json' })
335
+ post(
336
+ '/_ruote/processes.json',
337
+ Rufus::Json.encode(params),
338
+ { 'CONTENT_TYPE' => 'application/json' })
260
339
 
261
- last_response.status.should == 201
262
- last_response.json_body['launched'].should match(/[0-9a-z\-]+/)
340
+ last_response.status.should == 201
263
341
 
264
- sleep 0.5
342
+ last_response.json_body['launched'].should match(/[0-9a-z\-]+/)
265
343
 
266
- @tracer.to_s.should == 'bar'
267
- end
344
+ sleep 0.4
268
345
 
269
- it 'should launch a valid process definition (HTML)' do
346
+ engine.processes.should_not be_empty
270
347
 
271
- params = {
272
- :definition => %q{
273
- Ruote.process_definition :name => 'test' do
274
- wait '1m'
275
- end
348
+ engine.processes.first.expressions.last.should be_a(
349
+ Ruote::Exp::WaitExpression)
350
+ end
351
+
352
+ it 'launches a valid process definition with fields (JSON)' do
353
+
354
+ params = {
355
+ :definition => %q{
356
+ Ruote.process_definition :name => 'test' do
357
+ echo '${f:foo}'
358
+ end
359
+ },
360
+ :fields => { :foo => 'bar' }
276
361
  }
277
- }
278
362
 
279
- post '/_ruote/processes', params
363
+ post(
364
+ '/_ruote/processes.json',
365
+ Rufus::Json.encode(params),
366
+ { 'CONTENT_TYPE' => 'application/json' })
280
367
 
281
- last_response.status.should == 201
368
+ last_response.status.should == 201
369
+ last_response.json_body['launched'].should match(/[0-9a-z\-]+/)
282
370
 
283
- sleep 0.4
371
+ sleep 0.5
284
372
 
285
- engine.processes.should_not be_empty
286
- end
373
+ @tracer.to_s.should == 'bar'
374
+ end
287
375
 
288
- it 'should launch a process definition with fields (HTML)' do
376
+ it 'launches a valid process definition (HTML)' do
289
377
 
290
- params = {
291
- :definition => %{
292
- Ruote.process_definition :name => 'test' do
293
- echo '${f:foo}'
294
- end
295
- },
296
- :fields => '{ "foo": "bar" }'
297
- }
378
+ params = {
379
+ :definition => %q{
380
+ Ruote.process_definition :name => 'test' do
381
+ wait '1m'
382
+ end
383
+ }
384
+ }
298
385
 
299
- post '/_ruote/processes', params
386
+ post '/_ruote/processes', params
300
387
 
301
- last_response.status.should == 201
388
+ last_response.status.should == 201
302
389
 
303
- sleep 0.5
390
+ sleep 0.4
304
391
 
305
- @tracer.to_s.should == 'bar'
306
- end
392
+ engine.processes.should_not be_empty
307
393
 
308
- it 'should correct for empty fields sent by browsers' do
394
+ engine.processes.first.expressions.last.should be_a(
395
+ Ruote::Exp::WaitExpression)
396
+ end
309
397
 
310
- params = {
311
- :definition => %q{
312
- Ruote.process_definition :name => 'test' do
313
- wait '5m'
314
- end
315
- },
316
- :fields => ''
317
- }
398
+ it 'launches a process definition (radial and CRLF) (HTML)' do
318
399
 
319
- post '/_ruote/processes', params
400
+ params = {
401
+ :definition => "define 'my process'\r\n wait '1m'\r\n"
402
+ }
320
403
 
321
- last_response.status.should == 201
404
+ post '/_ruote/processes', params
322
405
 
323
- sleep 0.4
406
+ last_response.status.should == 201
324
407
 
325
- engine.processes.should_not be_empty
326
- end
408
+ sleep 0.4
327
409
 
328
- it 'should 400 code when it fails to determine what to launch (JSON)' do
410
+ engine.processes.should_not be_empty
329
411
 
330
- params = { :definition => 'http://invalid.invalid' }
412
+ engine.processes.first.expressions.last.should be_a(
413
+ Ruote::Exp::WaitExpression)
414
+ end
331
415
 
332
- post(
333
- '/_ruote/processes.json',
334
- Rufus::Json.encode(params),
335
- { 'CONTENT_TYPE' => 'application/json' })
416
+ it 'launches a process definition with fields (HTML)' do
336
417
 
337
- last_response.status.should == 400
338
- last_response.json_body.keys.should include('http_error')
339
- end
418
+ params = {
419
+ :definition => %{
420
+ Ruote.process_definition :name => 'test' do
421
+ echo '${f:foo}'
422
+ end
423
+ },
424
+ :fields => '{ "foo": "bar" }'
425
+ }
340
426
 
341
- it 'should 400 when it fails to determine what to launch (HTML)' do
427
+ post '/_ruote/processes', params
342
428
 
343
- params = { :definition => %q{http://invalid.invalid} }
429
+ last_response.status.should == 201
344
430
 
345
- post '/_ruote/processes', params
431
+ sleep 0.5
346
432
 
347
- last_response.status.should == 400
348
- last_response.should match(/bad request/)
349
- end
433
+ @tracer.to_s.should == 'bar'
434
+ end
350
435
 
351
- end
436
+ it 'corrects empty fields sent by browsers' do
352
437
 
353
- describe 'DELETE /_ruote/processes/wfid' do
438
+ params = {
439
+ :definition => %q{
440
+ Ruote.process_definition :name => 'test' do
441
+ wait '5m'
442
+ end
443
+ },
444
+ :fields => ''
445
+ }
354
446
 
355
- before(:each) do
447
+ post '/_ruote/processes', params
356
448
 
357
- prepare_engine
358
- end
449
+ last_response.status.should == 201
359
450
 
360
- after(:each) do
451
+ sleep 0.4
361
452
 
362
- shutdown_and_purge_engine
363
- end
453
+ engine.processes.should_not be_empty
454
+ end
364
455
 
365
- before(:each) do
456
+ it 'goes 400 code when it fails to determine what to launch (JSON)' do
366
457
 
367
- @wfid = RuoteKit.engine.launch(Ruote.process_definition do
368
- sequence :on_cancel => 'bail_out' do
369
- echo 'in'
370
- wait '1d'
371
- echo 'done.'
372
- end
458
+ params = { :definition => 'http://invalid.invalid' }
373
459
 
374
- define :name => 'bail_out' do
375
- echo 'bailout.'
376
- end
377
- end)
460
+ post(
461
+ '/_ruote/processes.json',
462
+ Rufus::Json.encode(params),
463
+ { 'CONTENT_TYPE' => 'application/json' })
464
+
465
+ last_response.status.should == 400
466
+ last_response.json_body.keys.should include('http_error')
467
+ end
468
+
469
+ it 'goes 400 when it fails to determine what to launch (HTML)' do
470
+
471
+ params = { :definition => %q{http://invalid.invalid} }
472
+
473
+ post '/_ruote/processes', params
474
+
475
+ last_response.status.should == 400
476
+ last_response.should match(/bad request/)
477
+ end
378
478
 
379
- RuoteKit.engine.wait_for(3)
380
479
  end
381
480
 
382
- it 'should cancel processes (JSON)' do
481
+ describe 'DELETE /_ruote/processes/:wfid' do
383
482
 
384
- delete "/_ruote/processes/#{@wfid}.json"
483
+ before(:each) do
385
484
 
386
- last_response.status.should == 200
485
+ @wfid = RuoteKit.engine.launch(Ruote.process_definition do
486
+ sequence :on_cancel => 'bail_out' do
487
+ echo 'in'
488
+ wait '1d'
489
+ echo 'done.'
490
+ end
387
491
 
388
- wait_for(@wfid)
492
+ define :name => 'bail_out' do
493
+ echo 'bailout.'
494
+ end
495
+ end)
389
496
 
390
- engine.process(@wfid).should be_nil
497
+ RuoteKit.engine.wait_for(3)
498
+ end
391
499
 
392
- @tracer.to_s.should == "in\nbailout."
393
- end
500
+ it 'cancels processes (JSON)' do
394
501
 
395
- it 'should cancel processes (HMTL)' do
502
+ delete "/_ruote/processes/#{@wfid}.json"
396
503
 
397
- delete "/_ruote/processes/#{@wfid}"
504
+ last_response.status.should == 200
505
+
506
+ wait_for(@wfid)
398
507
 
399
- last_response.should be_redirect
400
- last_response['Location'].should == '/_ruote/processes'
508
+ engine.process(@wfid).should be_nil
401
509
 
402
- wait_for(@wfid)
510
+ @tracer.to_s.should == "in\nbailout."
511
+ end
403
512
 
404
- engine.process(@wfid).should be_nil
513
+ it 'cancels processes (HMTL)' do
405
514
 
406
- @tracer.to_s.should == "in\nbailout."
407
- end
515
+ delete "/_ruote/processes/#{@wfid}"
408
516
 
409
- it 'should kill processes (JSON)' do
517
+ last_response.should be_redirect
518
+ last_response['Location'].should == 'http://example.org/_ruote/processes'
410
519
 
411
- delete "/_ruote/processes/#{@wfid}.json?_kill=1"
520
+ wait_for(@wfid)
412
521
 
413
- last_response.status.should == 200
522
+ engine.process(@wfid).should be_nil
414
523
 
415
- wait_for(@wfid)
524
+ @tracer.to_s.should == "in\nbailout."
525
+ end
416
526
 
417
- engine.process(@wfid).should be_nil
527
+ it 'kills processes (JSON)' do
418
528
 
419
- @tracer.to_s.should == 'in'
420
- end
529
+ delete "/_ruote/processes/#{@wfid}.json?_kill=1"
421
530
 
422
- it 'should kill processes (HTML)' do
531
+ last_response.status.should == 200
423
532
 
424
- delete "/_ruote/processes/#{@wfid}?_kill=1"
533
+ wait_for(@wfid)
425
534
 
426
- last_response.should be_redirect
427
- last_response['Location'].should == '/_ruote/processes'
535
+ engine.process(@wfid).should be_nil
536
+
537
+ @tracer.to_s.should == 'in'
538
+ end
428
539
 
429
- wait_for(@wfid)
540
+ it 'kills processes (HTML)' do
430
541
 
431
- engine.process(@wfid).should be_nil
542
+ delete "/_ruote/processes/#{@wfid}?_kill=1"
432
543
 
433
- @tracer.to_s.should == 'in'
544
+ last_response.should be_redirect
545
+ last_response['Location'].should == 'http://example.org/_ruote/processes'
546
+
547
+ wait_for(@wfid)
548
+
549
+ engine.process(@wfid).should be_nil
550
+
551
+ @tracer.to_s.should == 'in'
552
+ end
434
553
  end
435
554
  end
436
555