rules_engine 0.1.10 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/rails_generators/manifests/rules_engine.rb +25 -18
- data/rails_generators/manifests/rules_engine.yml +10 -3
- data/rails_generators/templates/app/controllers/re_history_controller.rb +15 -0
- data/rails_generators/templates/app/controllers/re_plan_workflows_controller.rb +12 -23
- data/rails_generators/templates/app/controllers/re_plans_controller.rb +11 -11
- data/rails_generators/templates/app/controllers/re_workflow_rules_controller.rb +2 -1
- data/rails_generators/templates/app/controllers/re_workflows_controller.rb +7 -7
- data/rails_generators/templates/app/helpers/rules_engine_helper.rb +1 -1
- data/rails_generators/templates/app/models/re_plan.rb +1 -1
- data/rails_generators/templates/app/models/re_rule.rb +1 -2
- data/rails_generators/templates/app/models/re_workflow.rb +1 -9
- data/rails_generators/templates/app/views/re_history/_index_prepare.html.erb +12 -0
- data/rails_generators/templates/app/views/re_history/_index_update.html.erb +20 -0
- data/rails_generators/templates/app/views/re_history/_show.html.erb +30 -0
- data/rails_generators/templates/app/views/re_history/index.html.erb +11 -0
- data/rails_generators/templates/app/views/re_history/index.js.erb +4 -0
- data/rails_generators/templates/app/views/re_history/show.html.erb +8 -0
- data/rails_generators/templates/app/views/re_history/show.js.erb +4 -0
- data/rails_generators/templates/app/views/re_plans/_copy.html.erb +1 -1
- data/rails_generators/templates/app/views/re_plans/{re_process.html.erb → history.html.erb} +3 -3
- data/rails_generators/templates/app/views/re_plans/history.js.erb +4 -0
- data/rails_generators/templates/app/views/re_plans/index.html.erb +2 -2
- data/rails_generators/templates/app/views/re_plans/preview.html.erb +0 -1
- data/rails_generators/templates/app/views/re_plans/show.html.erb +2 -2
- data/rails_generators/templates/app/views/re_workflows/_copy.html.erb +1 -1
- data/rails_generators/templates/app/views/re_workflows/index.html.erb +2 -2
- data/rails_generators/templates/doc/README.rules_engine +1 -1
- data/rails_generators/templates/public/javascripts/rules_engine/re_history_index.js +43 -0
- data/rails_generators/templates/public/javascripts/rules_engine/{re_process_show.js → re_history_show.js} +3 -3
- data/rails_generators/templates/public/stylesheets/rules_engine/images/rules_engine/{re_process → re_history}/error-14.png +0 -0
- data/rails_generators/templates/public/stylesheets/rules_engine/images/rules_engine/{re_process → re_history}/info-14.png +0 -0
- data/rails_generators/templates/public/stylesheets/rules_engine/images/rules_engine/{re_process → re_history}/list-25.png +0 -0
- data/rails_generators/templates/public/stylesheets/rules_engine/images/rules_engine/{re_process → re_history}/success-14.png +0 -0
- data/rails_generators/templates/public/stylesheets/rules_engine/screen.css +19 -69
- data/rails_generators/templates/spec/controllers/re_application_controller_spec.rb +68 -0
- data/rails_generators/templates/spec/controllers/re_history_controller_spec.rb +41 -0
- data/rails_generators/templates/spec/controllers/re_plan_workflow_rules_controller_spec.rb +355 -0
- data/rails_generators/templates/spec/controllers/re_plan_workflows_controller_spec.rb +364 -0
- data/rails_generators/templates/spec/controllers/re_plans_controller_spec.rb +165 -223
- data/rails_generators/templates/spec/controllers/re_publications_controller_spec.rb +29 -0
- data/rails_generators/templates/spec/controllers/re_workflow_rules_controller_spec.rb +353 -0
- data/rails_generators/templates/spec/controllers/re_workflows_controller_spec.rb +326 -0
- data/rails_generators/templates/spec/helpers/rules_engine_helper_spec.rb +8 -8
- metadata +28 -21
- data/rails_generators/templates/app/controllers/re_processes_controller.rb +0 -15
- data/rails_generators/templates/app/views/re_plans/re_process.js.erb +0 -4
- data/rails_generators/templates/app/views/re_processes/_index_prepare.html.erb +0 -12
- data/rails_generators/templates/app/views/re_processes/_index_update.html.erb +0 -20
- data/rails_generators/templates/app/views/re_processes/_show.html.erb +0 -30
- data/rails_generators/templates/app/views/re_processes/index.html.erb +0 -11
- data/rails_generators/templates/app/views/re_processes/index.js.erb +0 -4
- data/rails_generators/templates/app/views/re_processes/show.html.erb +0 -8
- data/rails_generators/templates/app/views/re_processes/show.js.erb +0 -4
- data/rails_generators/templates/public/javascripts/rules_engine/re_process_index.js +0 -43
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe RePublicationsController do
|
4
|
+
extend RulesEngineMacros
|
5
|
+
|
6
|
+
integrate_views
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
controller.instance_eval { flash.stub!(:sweep) }
|
10
|
+
controller.stub!(:rules_engine_reader_access_required).and_return(true)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "show" do
|
14
|
+
it_should_require_rules_engine_reader_access(:show, :id => 123)
|
15
|
+
|
16
|
+
it "should get the audit history record with the process ID" do
|
17
|
+
re_plan = RePlan.make(:code => "mock_code")
|
18
|
+
|
19
|
+
publisher = mock('publisher')
|
20
|
+
RulesEngine::Publish.stub!(:publisher).and_return(publisher)
|
21
|
+
|
22
|
+
re_publications = {:history => "none"}
|
23
|
+
publisher.should_receive(:history).with("mock_code", anything).and_return(re_publications)
|
24
|
+
|
25
|
+
get :show, :id => re_plan.id
|
26
|
+
assigns[:re_publications].should == re_publications
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,353 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe ReWorkflowRulesController do
|
4
|
+
extend RulesEngineMacros
|
5
|
+
|
6
|
+
integrate_views
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
controller.instance_eval { flash.stub!(:sweep) }
|
10
|
+
controller.stub!(:rules_engine_reader_access_required).and_return(true)
|
11
|
+
controller.stub!(:rules_engine_editor_access_required).and_return(true)
|
12
|
+
|
13
|
+
@re_workflow = ReWorkflow.make
|
14
|
+
|
15
|
+
@rule_class = RulesEngine::Rule::Definition
|
16
|
+
@rule_class.options = {
|
17
|
+
:group => 'Mock',
|
18
|
+
:display_name => 'Mock Rule',
|
19
|
+
:help_partial => '/mock_rule/help',
|
20
|
+
:new_partial => '/mock_rule/new',
|
21
|
+
:edit_partial => '/mock_rule/edit'
|
22
|
+
}
|
23
|
+
|
24
|
+
RulesEngine::Discovery.stub!(:rule_class).and_return(@rule_class)
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "help" do
|
28
|
+
it_should_require_rules_engine_reader_access(:help, :re_workflow_id => 123, :rule_class_name => 'mock_rule')
|
29
|
+
|
30
|
+
before(:each) do
|
31
|
+
controller.stub!(:render).with('/mock_rule/help')
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "rule class exists" do
|
35
|
+
it "should get the rule record with the rule_class_name" do
|
36
|
+
get :help, :re_workflow_id => @re_workflow.id, :rule_class_name => 'mock_rule'
|
37
|
+
assigns[:re_workflow].should == @re_workflow
|
38
|
+
assigns[:rule_class].should == @rule_class
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should render the help partial" do
|
42
|
+
controller.should_receive(:render).with('/mock_rule/help')
|
43
|
+
get :help, :re_workflow_id => @re_workflow.id, :rule_class_name => 'mock_rule'
|
44
|
+
response.should render_template(:help)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "rule class does not exist" do
|
49
|
+
it "should render the error template" do
|
50
|
+
RulesEngine::Discovery.stub!(:rule_class).and_return(nil)
|
51
|
+
get :help, :re_workflow_id => @re_workflow.id, :rule_class_name => 'unknown'
|
52
|
+
response.should render_template(:error)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "error" do
|
58
|
+
it_should_require_rules_engine_reader_access(:error, :re_workflow_id => 123)
|
59
|
+
|
60
|
+
it "should render the error template" do
|
61
|
+
get :error, :re_workflow_id => @re_workflow.id
|
62
|
+
response.should render_template(:error)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "new" do
|
67
|
+
it_should_require_rules_engine_editor_access(:new, :re_workflow_id => 123)
|
68
|
+
|
69
|
+
before(:each) do
|
70
|
+
controller.stub!(:render).with('/mock_rule/new')
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should assign a new rule record" do
|
74
|
+
get :new, :re_workflow_id => @re_workflow.id
|
75
|
+
assigns[:re_rule].should be_instance_of(ReRule)
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "the rule class exists" do
|
79
|
+
it "should render the new partial" do
|
80
|
+
controller.should_receive(:render).with('/mock_rule/new')
|
81
|
+
get :new, :re_workflow_id => @re_workflow.id, :rule_class_name => 'mock_rule'
|
82
|
+
response.should render_template(:new)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "rule class does not exist" do
|
87
|
+
it "should render the error template" do
|
88
|
+
RulesEngine::Discovery.stub!(:rule_class).and_return(nil)
|
89
|
+
get :new, :re_workflow_id => @re_workflow.id, :rule_class_name => 'unknown'
|
90
|
+
response.should render_template(:error)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe "create" do
|
96
|
+
it_should_require_rules_engine_editor_access(:create, :re_workflow_id => 123, :rule_class_name => 'mock_rule')
|
97
|
+
|
98
|
+
before do
|
99
|
+
@re_rule = ReRule.make(:re_workflow => @re_workflow)
|
100
|
+
ReRule.stub!(:new).and_return(@re_rule)
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should assign the re_rule" do
|
104
|
+
ReRule.should_receive(:new).with(:re_workflow_id => @re_workflow.id, :rule_class_name => 'mock_rule')
|
105
|
+
post :create, :re_workflow_id => @re_workflow.id, :rule_class_name => 'mock_rule', :rule_attibutes => 'mock attributes'
|
106
|
+
end
|
107
|
+
|
108
|
+
describe "rule class does not exist" do
|
109
|
+
it "should render the error template" do
|
110
|
+
@re_rule.stub!(:rule).and_return(nil)
|
111
|
+
post :create, :re_workflow_id => @re_workflow.id, :rule_class_name => 'mock_rule', :rule_attibutes => 'mock attributes'
|
112
|
+
response.should render_template(:error)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe "rule class exists" do
|
117
|
+
it "should assign the re_rule attributess" do
|
118
|
+
@re_rule.should_receive(:rule_attributes=).with(hash_including(:rule_attibutes => 'mock attributes'))
|
119
|
+
post :create, :re_workflow_id => @re_workflow.id, :rule_class_name => 'mock_rule', :rule_attibutes => 'mock attributes'
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe "save failed" do
|
124
|
+
before(:each) do
|
125
|
+
@re_rule.stub!(:save).and_return(false)
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should render the 'new' template" do
|
129
|
+
controller.should_receive(:render).with('/mock_rule/new')
|
130
|
+
post :create, :re_workflow_id => @re_workflow.id, :rule_class_name => 'mock_rule', :rule_attibutes => 'mock attributes'
|
131
|
+
response.should render_template(:new)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
describe "the rule is valid" do
|
136
|
+
before(:each) do
|
137
|
+
@re_rule.stub!(:valid?).and_return(true)
|
138
|
+
@re_rule.stub!(:save).and_return(true)
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should add the rule to the workflow" do
|
142
|
+
post :create, :re_workflow_id => @re_workflow.id, :rule_class_name => 'mock_rule', :rule_attibutes => 'mock attributes'
|
143
|
+
@re_workflow.re_rules.should include(@re_rule)
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should display a flash success message" do
|
147
|
+
post :create, :re_workflow_id => @re_workflow.id, :rule_class_name => 'mock_rule', :rule_attibutes => 'mock attributes'
|
148
|
+
flash[:success].should_not be_blank
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should redirect to the change re_rule page for HTML" do
|
152
|
+
post :create, :re_workflow_id => @re_workflow.id, :rule_class_name => 'mock_rule', :rule_attibutes => 'mock attributes'
|
153
|
+
response.should redirect_to(change_re_workflow_path(@re_workflow))
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should render 'update' template for JAVASCRIPT" do
|
157
|
+
xhr :post, :create, :re_workflow_id => @re_workflow.id, :rule_class_name => 'mock_rule', :rule_attibutes => 'mock attributes'
|
158
|
+
response.should render_template(:update)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
describe "edit" do
|
164
|
+
it_should_require_rules_engine_editor_access(:edit, :re_workflow_id => 123)
|
165
|
+
|
166
|
+
before(:each) do
|
167
|
+
controller.stub!(:render).with('/mock_rule/edit')
|
168
|
+
@re_rule = ReRule.make(:re_workflow => @re_workflow)
|
169
|
+
end
|
170
|
+
|
171
|
+
it "should assign a the rule record" do
|
172
|
+
get :edit, :re_workflow_id => @re_workflow.id, :id => @re_rule.id
|
173
|
+
assigns[:re_rule].should == @re_rule
|
174
|
+
end
|
175
|
+
|
176
|
+
describe "the rule class exists" do
|
177
|
+
it "should render the edit partial" do
|
178
|
+
controller.should_receive(:render).with('/mock_rule/edit')
|
179
|
+
get :edit, :re_workflow_id => @re_workflow.id, :id => @re_rule.id
|
180
|
+
response.should render_template(:edit)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
describe "rule class does not exist" do
|
185
|
+
it "should render the error template" do
|
186
|
+
RulesEngine::Discovery.stub!(:rule_class).and_return(nil)
|
187
|
+
get :edit, :re_workflow_id => @re_workflow.id, :id => @re_rule.id
|
188
|
+
response.should render_template(:error)
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
describe "update" do
|
194
|
+
it_should_require_rules_engine_editor_access(:update, :re_workflow_id => 123, :id => 456, :rule_attibutes => 'mock attributes')
|
195
|
+
|
196
|
+
before do
|
197
|
+
@re_rule = ReRule.make(:re_workflow => @re_workflow)
|
198
|
+
end
|
199
|
+
|
200
|
+
it "should get the rule record with the ID" do
|
201
|
+
ReRule.should_receive(:find).with("123").and_return(@re_rule)
|
202
|
+
put :update, :re_workflow_id => @re_workflow.id, :id => 123, :rule_attibutes => 'mock attributes'
|
203
|
+
assigns[:re_rule].should == @re_rule
|
204
|
+
end
|
205
|
+
|
206
|
+
describe "rule class does not exist" do
|
207
|
+
it "should render the error template" do
|
208
|
+
ReRule.stub!(:find).and_return(@re_rule)
|
209
|
+
@re_rule.stub!(:rule).and_return(nil)
|
210
|
+
put :update, :re_workflow_id => @re_workflow.id, :id => @re_rule.id, :rule_attibutes => 'mock attributes'
|
211
|
+
response.should render_template(:error)
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
describe "rule class exists" do
|
216
|
+
it "should assign the re_rule attributess" do
|
217
|
+
ReRule.stub!(:find).and_return(@re_rule)
|
218
|
+
@re_rule.should_receive(:rule_attributes=).with(hash_including(:rule_attibutes => 'mock attributes'))
|
219
|
+
put :update, :re_workflow_id => @re_workflow.id, :id => @re_rule.id, :rule_attibutes => 'mock attributes'
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
describe "save failed" do
|
224
|
+
before(:each) do
|
225
|
+
ReRule.stub!(:find).and_return(@re_rule)
|
226
|
+
@re_rule.stub!(:save).and_return(false)
|
227
|
+
end
|
228
|
+
|
229
|
+
it "should render the 'edit' template" do
|
230
|
+
controller.should_receive(:render).with('/mock_rule/edit')
|
231
|
+
put :update, :re_workflow_id => @re_workflow.id, :id => @re_rule.id, :rule_attibutes => 'mock attributes'
|
232
|
+
response.should render_template(:edit)
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
describe "the rule is valid" do
|
237
|
+
it "should add the rule to the workflow" do
|
238
|
+
put :update, :re_workflow_id => @re_workflow.id, :id => @re_rule.id, :rule_attibutes => 'mock attributes'
|
239
|
+
@re_workflow.re_rules.should include(@re_rule)
|
240
|
+
end
|
241
|
+
|
242
|
+
it "should display a flash success message" do
|
243
|
+
put :update, :re_workflow_id => @re_workflow.id, :id => @re_rule.id, :rule_attibutes => 'mock attributes'
|
244
|
+
flash[:success].should_not be_blank
|
245
|
+
end
|
246
|
+
|
247
|
+
it "should redirect to the change re_rule page for HTML" do
|
248
|
+
put :update, :re_workflow_id => @re_workflow.id, :id => @re_rule.id, :rule_attibutes => 'mock attributes'
|
249
|
+
response.should redirect_to(change_re_workflow_path(@re_workflow))
|
250
|
+
end
|
251
|
+
|
252
|
+
it "should render 'update' template for JAVASCRIPT" do
|
253
|
+
xhr :put, :update, :re_workflow_id => @re_workflow.id, :id => @re_rule.id, :rule_attibutes => 'mock attributes'
|
254
|
+
response.should render_template(:update)
|
255
|
+
end
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
describe "destroy" do
|
260
|
+
it_should_require_rules_engine_editor_access(:destroy, :re_workflow_id => 123, :id => 456)
|
261
|
+
|
262
|
+
before do
|
263
|
+
@re_rule = ReRule.make(:re_workflow => @re_workflow)
|
264
|
+
ReRule.stub!(:find).and_return(@re_rule)
|
265
|
+
end
|
266
|
+
|
267
|
+
it "should get the rule record with the ID" do
|
268
|
+
ReRule.should_receive(:find).with("123").and_return(@re_rule)
|
269
|
+
delete :destroy, :re_workflow_id => @re_workflow.id, :id => 123
|
270
|
+
assigns[:re_rule].should == @re_rule
|
271
|
+
end
|
272
|
+
|
273
|
+
it "should destroy the re_rule" do
|
274
|
+
@re_rule.should_receive(:destroy)
|
275
|
+
delete :destroy, :re_workflow_id => @re_workflow.id, :id => 123
|
276
|
+
end
|
277
|
+
|
278
|
+
it "should display a flash success message" do
|
279
|
+
delete :destroy, :re_workflow_id => @re_workflow.id, :id => 123
|
280
|
+
flash[:success].should_not be_blank
|
281
|
+
end
|
282
|
+
|
283
|
+
it "should redirect to the change re_workflow page for HTML" do
|
284
|
+
delete :destroy, :re_workflow_id => @re_workflow.id, :id => 123
|
285
|
+
response.should redirect_to(change_re_workflow_path(@re_workflow))
|
286
|
+
end
|
287
|
+
|
288
|
+
it "should render the update template for JAVASCRIPT" do
|
289
|
+
xhr :delete, :destroy, :re_workflow_id => @re_workflow.id, :id => 123
|
290
|
+
response.should render_template(:update)
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
describe "move_up" do
|
295
|
+
it_should_require_rules_engine_editor_access(:move_up, :re_workflow_id => 123, :id => 456)
|
296
|
+
|
297
|
+
before(:each) do
|
298
|
+
@re_rule = ReRule.make(:re_workflow => @re_workflow)
|
299
|
+
end
|
300
|
+
|
301
|
+
it "should get the rule record with the ID" do
|
302
|
+
get :move_up, :re_workflow_id => @re_workflow.id, :id => @re_rule.id
|
303
|
+
assigns[:re_workflow].should == @re_workflow
|
304
|
+
assigns[:re_rule].should == @re_rule
|
305
|
+
end
|
306
|
+
|
307
|
+
it "should move the rule up" do
|
308
|
+
ReRule.stub!(:find).and_return(@re_rule)
|
309
|
+
@re_rule.should_receive(:move_higher)
|
310
|
+
put :move_up, :re_workflow_id => @re_workflow.id, :id => 123
|
311
|
+
end
|
312
|
+
|
313
|
+
it "should redirect to the change re_workflow page for HTML" do
|
314
|
+
put :move_up, :re_workflow_id => @re_workflow.id, :id => @re_rule.id
|
315
|
+
response.should redirect_to(change_re_workflow_path(@re_workflow))
|
316
|
+
end
|
317
|
+
|
318
|
+
it "should render the update template for JAVASCRIPT" do
|
319
|
+
xhr :put, :move_up, :re_workflow_id => @re_workflow.id, :id => @re_rule.id
|
320
|
+
response.should render_template(:update)
|
321
|
+
end
|
322
|
+
end
|
323
|
+
|
324
|
+
describe "move_down" do
|
325
|
+
it_should_require_rules_engine_editor_access(:move_down, :re_workflow_id => 123, :id => 456)
|
326
|
+
|
327
|
+
before(:each) do
|
328
|
+
@re_rule = ReRule.make(:re_workflow => @re_workflow)
|
329
|
+
end
|
330
|
+
|
331
|
+
it "should get the rule record with the ID" do
|
332
|
+
get :move_down, :re_workflow_id => @re_workflow.id, :id => @re_rule.id
|
333
|
+
assigns[:re_workflow].should == @re_workflow
|
334
|
+
assigns[:re_rule].should == @re_rule
|
335
|
+
end
|
336
|
+
|
337
|
+
it "should move the rule down" do
|
338
|
+
ReRule.stub!(:find).and_return(@re_rule)
|
339
|
+
@re_rule.should_receive(:move_lower)
|
340
|
+
put :move_down, :re_workflow_id => @re_workflow.id, :id => 123
|
341
|
+
end
|
342
|
+
|
343
|
+
it "should redirect to the change re_workflow page for HTML" do
|
344
|
+
put :move_down, :re_workflow_id => @re_workflow.id, :id => @re_rule.id
|
345
|
+
response.should redirect_to(change_re_workflow_path(@re_workflow))
|
346
|
+
end
|
347
|
+
|
348
|
+
it "should render the update template for JAVASCRIPT" do
|
349
|
+
xhr :put, :move_down, :re_workflow_id => @re_workflow.id, :id => @re_rule.id
|
350
|
+
response.should render_template(:update)
|
351
|
+
end
|
352
|
+
end
|
353
|
+
end
|
@@ -0,0 +1,326 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe ReWorkflowsController do
|
4
|
+
extend RulesEngineMacros
|
5
|
+
|
6
|
+
integrate_views
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
controller.instance_eval { flash.stub!(:sweep) }
|
10
|
+
controller.stub!(:rules_engine_reader_access_required).and_return(true)
|
11
|
+
controller.stub!(:rules_engine_editor_access_required).and_return(true)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "index" do
|
15
|
+
it_should_require_rules_engine_reader_access(:index)
|
16
|
+
|
17
|
+
it "should get the list of workflows" do
|
18
|
+
re_workflows = [ReWorkflow.make(:title => 'a'), ReWorkflow.make(:title => 'b')]
|
19
|
+
get :index
|
20
|
+
assigns[:re_workflows].should == re_workflows
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "show" do
|
25
|
+
it_should_require_rules_engine_reader_access(:show, :id => 123)
|
26
|
+
|
27
|
+
it "should get the workflow record with the ID" do
|
28
|
+
re_workflow = ReWorkflow.make
|
29
|
+
get :show, :id => re_workflow.id
|
30
|
+
assigns[:re_workflow].should == re_workflow
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "new" do
|
35
|
+
it_should_require_rules_engine_editor_access(:new, :id => 123)
|
36
|
+
|
37
|
+
it "should assign a new workflow record" do
|
38
|
+
get :new
|
39
|
+
assigns[:re_workflow].should be_instance_of(ReWorkflow)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should render the 'new' template" do
|
43
|
+
get :new
|
44
|
+
response.should render_template(:new)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "create" do
|
49
|
+
it_should_require_rules_engine_editor_access(:create, :re_workflow => {})
|
50
|
+
|
51
|
+
before do
|
52
|
+
@re_workflow = ReWorkflow.make
|
53
|
+
ReWorkflow.stub!(:new).and_return(@re_workflow)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should assign the re_workflow parameters" do
|
57
|
+
ReWorkflow.should_receive(:new).with("code" => "name", "title" => "value")
|
58
|
+
post :create, :re_workflow => { :code => "name", :title => "value" }
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should save the re_workflow" do
|
62
|
+
@re_workflow.should_receive(:save)
|
63
|
+
post :create, :re_workflow => { :title => "name" }
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "save failed" do
|
67
|
+
before(:each) do
|
68
|
+
@re_workflow.stub!(:save).and_return(false)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should render the 'new' template" do
|
72
|
+
post :create, :re_workflow => { :title => "name" }
|
73
|
+
response.should render_template(:new)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "save succeeded" do
|
78
|
+
before(:each) do
|
79
|
+
@re_workflow.stub!(:save).and_return(true)
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should display a flash success message" do
|
83
|
+
post :create, :re_workflow => { :title => "name" }
|
84
|
+
flash[:success].should_not be_blank
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should redirect to the change re_workflow page for HTML" do
|
88
|
+
post :create, :re_workflow => { :title => "name" }
|
89
|
+
response.should redirect_to(change_re_workflow_path(@re_workflow))
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should render 'create' template for JAVASCRIPT" do
|
93
|
+
xhr :post, :create, :re_workflow => { :title => "name" }
|
94
|
+
response.should render_template(:create)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe "edit" do
|
100
|
+
it_should_require_rules_engine_editor_access(:edit, :id => 123)
|
101
|
+
|
102
|
+
it "should get the workflow record with the ID" do
|
103
|
+
re_workflow = ReWorkflow.make
|
104
|
+
get :edit, :id => re_workflow.id
|
105
|
+
assigns[:re_workflow].should == re_workflow
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe "update" do
|
110
|
+
it_should_require_rules_engine_editor_access(:update, :id => 123, :re_workflow => {})
|
111
|
+
|
112
|
+
before do
|
113
|
+
@re_workflow = ReWorkflow.make
|
114
|
+
ReWorkflow.stub!(:find).and_return(@re_workflow)
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should get the workflow record with the ID" do
|
118
|
+
ReWorkflow.should_receive(:find).with("123").and_return(@re_workflow)
|
119
|
+
put :update, :id => 123, :re_workflow => { :title => "value" }
|
120
|
+
assigns[:re_workflow].should == @re_workflow
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should assign the re_workflow parameters" do
|
124
|
+
@re_workflow.should_receive(:attributes=).with("title" => "name")
|
125
|
+
put :update, :id => 123, :re_workflow => { :title => "name" }
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should not assign the re_workflow parameters :code" do
|
129
|
+
@re_workflow.should_receive(:attributes=).with("title" => "name")
|
130
|
+
put :update, :id => 123, :re_workflow => { :title => "name", :code => "code" }
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should save the re_workflow" do
|
134
|
+
@re_workflow.should_receive(:save)
|
135
|
+
put :update, :id => 123, :re_workflow => { :title => "name" }
|
136
|
+
end
|
137
|
+
|
138
|
+
describe "save failed" do
|
139
|
+
before(:each) do
|
140
|
+
@re_workflow.stub!(:save).and_return(false)
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should render the 'edit' template" do
|
144
|
+
put :update, :id => 123, :re_workflow => { :title => "name" }
|
145
|
+
response.should render_template(:edit)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
describe "save succeeded" do
|
150
|
+
before do
|
151
|
+
@re_workflow.stub!(:save).and_return(true)
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should display a flash success message" do
|
155
|
+
put :update, :id => 123, :re_workflow => { :title => "name" }
|
156
|
+
flash[:success].should_not be_blank
|
157
|
+
end
|
158
|
+
|
159
|
+
it "should redirect to the change re_workflow page for HTML" do
|
160
|
+
put :update, :id => 123, :re_workflow => { :title => "name" }
|
161
|
+
response.should redirect_to(change_re_workflow_path(@re_workflow))
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should render 'update' template for JAVASCRIPT" do
|
165
|
+
xhr :put, :update, :id => 123, :re_workflow => { :title => "name" }
|
166
|
+
response.should render_template(:update)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
describe "destroy" do
|
172
|
+
it_should_require_rules_engine_editor_access(:destroy, :id => 123)
|
173
|
+
|
174
|
+
before do
|
175
|
+
@re_workflow = ReWorkflow.make
|
176
|
+
ReWorkflow.stub!(:find).and_return(@re_workflow)
|
177
|
+
end
|
178
|
+
|
179
|
+
it "should get the workflow record with the ID" do
|
180
|
+
ReWorkflow.should_receive(:find).with("123").and_return(@re_workflow)
|
181
|
+
delete :destroy, :id => 123
|
182
|
+
assigns[:re_workflow].should == @re_workflow
|
183
|
+
end
|
184
|
+
|
185
|
+
it "should destroy the re_workflow" do
|
186
|
+
@re_workflow.should_receive(:destroy)
|
187
|
+
delete :destroy, :id => 123
|
188
|
+
end
|
189
|
+
|
190
|
+
it "should display a flash success message" do
|
191
|
+
delete :destroy, :id => 123
|
192
|
+
flash[:success].should_not be_blank
|
193
|
+
end
|
194
|
+
|
195
|
+
it "should redirect to the re_workflows page for HTML" do
|
196
|
+
delete :destroy, :id => 123
|
197
|
+
response.should redirect_to(re_workflows_path)
|
198
|
+
end
|
199
|
+
|
200
|
+
it "should redirect to the re_workflows page for JAVASCRIPT" do
|
201
|
+
xhr :delete, :destroy, :id => 123
|
202
|
+
response.body.should == "window.location.href = '#{re_workflows_path}';"
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
describe "change" do
|
207
|
+
it_should_require_rules_engine_editor_access(:change, :id => 123)
|
208
|
+
|
209
|
+
before(:each) do
|
210
|
+
@re_workflow = ReWorkflow.make
|
211
|
+
end
|
212
|
+
|
213
|
+
it "should rediscover all of the rules" do
|
214
|
+
RulesEngine::Discovery.should_receive(:discover!)
|
215
|
+
get :change, :id => @re_workflow.id
|
216
|
+
end
|
217
|
+
|
218
|
+
it "should get the workflow record with the ID" do
|
219
|
+
get :change, :id => @re_workflow.id
|
220
|
+
assigns[:re_workflow].should == @re_workflow
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
describe "preview" do
|
225
|
+
it_should_require_rules_engine_reader_access(:preview, :id => 123)
|
226
|
+
|
227
|
+
it "should get the workflow record with the ID" do
|
228
|
+
re_workflow = ReWorkflow.make
|
229
|
+
ReWorkflow.should_receive(:find).with("123").and_return(re_workflow)
|
230
|
+
get :preview, :id => 123
|
231
|
+
assigns[:re_workflow].should == re_workflow
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
describe "plan" do
|
236
|
+
it_should_require_rules_engine_reader_access(:plan, :id => 123)
|
237
|
+
|
238
|
+
it "should list the workflows" do
|
239
|
+
re_workflow = ReWorkflow.make(:title => 'a')
|
240
|
+
re_plan = RePlan.make
|
241
|
+
re_plan.re_workflows = [re_workflow]
|
242
|
+
|
243
|
+
get :plan, :id => re_workflow.id
|
244
|
+
assigns[:re_plan_workflows].should == re_workflow.re_plan_workflows
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
describe "add" do
|
249
|
+
it_should_require_rules_engine_reader_access(:add)
|
250
|
+
|
251
|
+
it "should list the workflows to add to a plan" do
|
252
|
+
re_workflows = [ReWorkflow.make(:title => 'a'), ReWorkflow.make(:title => 'b')]
|
253
|
+
get :add
|
254
|
+
assigns[:re_workflows].should == re_workflows
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
describe "copy" do
|
259
|
+
it_should_require_rules_engine_editor_access(:copy, :id => 123)
|
260
|
+
|
261
|
+
before(:each) do
|
262
|
+
@re_workflow = ReWorkflow.make
|
263
|
+
end
|
264
|
+
|
265
|
+
it "should assign an empty workflow copy" do
|
266
|
+
get :copy, :id => @re_workflow.id
|
267
|
+
assigns[:re_workflow].should == @re_workflow
|
268
|
+
assigns[:re_workflow_copy].should be_instance_of(ReWorkflow)
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
describe "duplicate" do
|
273
|
+
it_should_require_rules_engine_editor_access(:duplicate, :id => 123)
|
274
|
+
|
275
|
+
before(:each) do
|
276
|
+
@re_workflow = ReWorkflow.make
|
277
|
+
ReWorkflow.stub!(:find).and_return(@re_workflow)
|
278
|
+
|
279
|
+
@re_workflow_copy = ReWorkflow.make
|
280
|
+
ReWorkflow.stub!(:new).and_return(@re_workflow_copy)
|
281
|
+
end
|
282
|
+
|
283
|
+
it "should use the revert and publish method to copy the parameters" do
|
284
|
+
@re_workflow.should_receive(:publish).and_return({:published => "mock value"})
|
285
|
+
@re_workflow_copy.should_receive(:revert!).with({:published => "mock value"})
|
286
|
+
post :duplicate, :id => 1234, :re_workflow => {:title => 'new title'}
|
287
|
+
end
|
288
|
+
|
289
|
+
it "should update the attributes of the new workflow" do
|
290
|
+
post :duplicate, :id => 1234, :re_workflow => {:title => 'new title'}
|
291
|
+
@re_workflow_copy.title.should == 'new title'
|
292
|
+
end
|
293
|
+
|
294
|
+
describe "the copied workflow was saved" do
|
295
|
+
before(:each) do
|
296
|
+
@re_workflow_copy.stub!(:save).and_return(true)
|
297
|
+
end
|
298
|
+
|
299
|
+
it "should display a flash success message" do
|
300
|
+
post :duplicate, :id => 1234, :re_workflow => {:title => 'new title'}
|
301
|
+
flash[:success].should_not be_blank
|
302
|
+
end
|
303
|
+
|
304
|
+
it "should redirect to the change re_workflow page for HTML" do
|
305
|
+
post :duplicate, :id => 1234, :re_workflow => {:title => 'new title'}
|
306
|
+
response.should redirect_to(change_re_workflow_path(@re_workflow_copy))
|
307
|
+
end
|
308
|
+
|
309
|
+
it "should redirect to the change re_workflows page for JAVASCRIPT" do
|
310
|
+
xhr :post, :duplicate, :id => 1234, :re_workflow => {:title => 'new title'}
|
311
|
+
response.body.should == "window.location.href = '#{change_re_workflow_path(@re_workflow_copy)}';"
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
describe "the copied workflow was not saved" do
|
316
|
+
before(:each) do
|
317
|
+
@re_workflow_copy.stub!(:save).and_return(false)
|
318
|
+
end
|
319
|
+
|
320
|
+
it "should render the 'copy' template" do
|
321
|
+
post :duplicate, :id => 1234, :re_workflow => {:title => 'new title'}
|
322
|
+
response.should render_template(:copy)
|
323
|
+
end
|
324
|
+
end
|
325
|
+
end
|
326
|
+
end
|