rules_engine 0.1.10 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,41 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe ReHistoryController 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 "index" do
|
14
|
+
it_should_require_rules_engine_reader_access(:index)
|
15
|
+
|
16
|
+
it "should get the process runner history from the rules engine process runner" do
|
17
|
+
runner = mock('runner')
|
18
|
+
RulesEngine::Process.stub!(:runner).and_return(runner)
|
19
|
+
|
20
|
+
re_history = {:history => "none"}
|
21
|
+
runner.should_receive(:history).with(nil, anything()).and_return(re_history)
|
22
|
+
get :index
|
23
|
+
assigns[:re_history].should == re_history
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "show" do
|
28
|
+
it_should_require_rules_engine_reader_access(:show, :id => 123)
|
29
|
+
|
30
|
+
it "should get the audit history record with the process ID" do
|
31
|
+
auditor = mock('auditor')
|
32
|
+
RulesEngine::Process.stub!(:auditor).and_return(auditor)
|
33
|
+
|
34
|
+
re_audit_history = {:history => "none"}
|
35
|
+
auditor.should_receive(:history).with("123").and_return(re_audit_history)
|
36
|
+
|
37
|
+
get :show, :id => 123
|
38
|
+
assigns[:re_audit_history].should == re_audit_history
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,355 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe RePlanWorkflowRulesController 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_plan = RePlan.make
|
14
|
+
@re_workflow = ReWorkflow.make(:re_plans => [@re_plan])
|
15
|
+
|
16
|
+
@rule_class = RulesEngine::Rule::Definition
|
17
|
+
@rule_class.options = {
|
18
|
+
:group => 'Mock',
|
19
|
+
:display_name => 'Mock Rule',
|
20
|
+
:help_partial => '/mock_rule/help',
|
21
|
+
:new_partial => '/mock_rule/new',
|
22
|
+
:edit_partial => '/mock_rule/edit'
|
23
|
+
}
|
24
|
+
|
25
|
+
RulesEngine::Discovery.stub!(:rule_class).and_return(@rule_class)
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "help" do
|
29
|
+
it_should_require_rules_engine_reader_access(:help, :re_plan_id => 123, :workflow_id => 456, :rule_class_name => 'mock_rule')
|
30
|
+
|
31
|
+
before(:each) do
|
32
|
+
controller.stub!(:render).with('/mock_rule/help')
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "rule class exists" do
|
36
|
+
it "should get the rule record with the rule_class_name" do
|
37
|
+
get :help, :re_plan_id => @re_plan.id, :workflow_id => @re_workflow.id, :rule_class_name => 'mock_rule'
|
38
|
+
assigns[:re_plan].should == @re_plan
|
39
|
+
assigns[:re_workflow].should == @re_workflow
|
40
|
+
assigns[:rule_class].should == @rule_class
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should render the help partial" do
|
44
|
+
controller.should_receive(:render).with('/mock_rule/help')
|
45
|
+
get :help, :re_plan_id => @re_plan.id, :workflow_id => @re_workflow.id, :rule_class_name => 'mock_rule'
|
46
|
+
response.should render_template(:help)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "rule class does not exist" do
|
51
|
+
it "should render the error template" do
|
52
|
+
RulesEngine::Discovery.stub!(:rule_class).and_return(nil)
|
53
|
+
get :help, :re_plan_id => @re_plan.id, :workflow_id => @re_workflow.id, :rule_class_name => 'unknown'
|
54
|
+
response.should render_template(:error)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "error" do
|
60
|
+
it_should_require_rules_engine_reader_access(:error, :re_plan_id => 123, :workflow_id => 456)
|
61
|
+
|
62
|
+
it "should render the error template" do
|
63
|
+
get :error, :re_plan_id => @re_plan.id, :workflow_id => @re_workflow.id
|
64
|
+
response.should render_template(:error)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "new" do
|
69
|
+
it_should_require_rules_engine_editor_access(:new, :re_plan_id => 123, :workflow_id => 456)
|
70
|
+
|
71
|
+
before(:each) do
|
72
|
+
controller.stub!(:render).with('/mock_rule/new')
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should assign a new rule record" do
|
76
|
+
get :new, :re_plan_id => @re_plan.id, :workflow_id => @re_workflow.id
|
77
|
+
assigns[:re_rule].should be_instance_of(ReRule)
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "the rule class exists" do
|
81
|
+
it "should render the new partial" do
|
82
|
+
controller.should_receive(:render).with('/mock_rule/new')
|
83
|
+
get :new, :re_plan_id => @re_plan.id, :workflow_id => @re_workflow.id, :rule_class_name => 'mock_rule'
|
84
|
+
response.should render_template(:new)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "rule class does not exist" do
|
89
|
+
it "should render the error template" do
|
90
|
+
RulesEngine::Discovery.stub!(:rule_class).and_return(nil)
|
91
|
+
get :new, :re_plan_id => @re_plan.id, :workflow_id => @re_workflow.id, :rule_class_name => 'unknown'
|
92
|
+
response.should render_template(:error)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "create" do
|
98
|
+
it_should_require_rules_engine_editor_access(:create, :re_plan_id => 123, :workflow_id => 456, :rule_class_name => 'mock_rule')
|
99
|
+
|
100
|
+
before do
|
101
|
+
@re_rule = ReRule.make(:re_workflow => @re_workflow)
|
102
|
+
ReRule.stub!(:new).and_return(@re_rule)
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should assign the re_rule" do
|
106
|
+
ReRule.should_receive(:new).with(:re_workflow_id => @re_workflow.id, :rule_class_name => 'mock_rule')
|
107
|
+
post :create, :re_plan_id => @re_plan.id, :workflow_id => @re_workflow.id, :rule_class_name => 'mock_rule', :rule_attibutes => 'mock attributes'
|
108
|
+
end
|
109
|
+
|
110
|
+
describe "rule class does not exist" do
|
111
|
+
it "should render the error template" do
|
112
|
+
@re_rule.stub!(:rule).and_return(nil)
|
113
|
+
post :create, :re_plan_id => @re_plan.id, :workflow_id => @re_workflow.id, :rule_class_name => 'mock_rule', :rule_attibutes => 'mock attributes'
|
114
|
+
response.should render_template(:error)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe "rule class exists" do
|
119
|
+
it "should assign the re_rule attributess" do
|
120
|
+
@re_rule.should_receive(:rule_attributes=).with(hash_including(:rule_attibutes => 'mock attributes'))
|
121
|
+
post :create, :re_plan_id => @re_plan.id, :workflow_id => @re_workflow.id, :rule_class_name => 'mock_rule', :rule_attibutes => 'mock attributes'
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
describe "save failed" do
|
126
|
+
before(:each) do
|
127
|
+
@re_rule.stub!(:save).and_return(false)
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should render the 'new' template" do
|
131
|
+
controller.should_receive(:render).with('/mock_rule/new')
|
132
|
+
post :create, :re_plan_id => @re_plan.id, :workflow_id => @re_workflow.id, :rule_class_name => 'mock_rule', :rule_attibutes => 'mock attributes'
|
133
|
+
response.should render_template(:new)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
describe "the rule is valid" do
|
138
|
+
before(:each) do
|
139
|
+
@re_rule.stub!(:valid?).and_return(true)
|
140
|
+
@re_rule.stub!(:save).and_return(true)
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should add the rule to the workflow" do
|
144
|
+
post :create, :re_plan_id => @re_plan.id, :workflow_id => @re_workflow.id, :rule_class_name => 'mock_rule', :rule_attibutes => 'mock attributes'
|
145
|
+
@re_workflow.re_rules.should include(@re_rule)
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should display a flash success message" do
|
149
|
+
post :create, :re_plan_id => @re_plan.id, :workflow_id => @re_workflow.id, :rule_class_name => 'mock_rule', :rule_attibutes => 'mock attributes'
|
150
|
+
flash[:success].should_not be_blank
|
151
|
+
end
|
152
|
+
|
153
|
+
it "should redirect to the change re_rule page for HTML" do
|
154
|
+
post :create, :re_plan_id => @re_plan.id, :workflow_id => @re_workflow.id, :rule_class_name => 'mock_rule', :rule_attibutes => 'mock attributes'
|
155
|
+
response.should redirect_to(change_re_plan_workflow_path(@re_plan, @re_workflow))
|
156
|
+
end
|
157
|
+
|
158
|
+
it "should render 'update' template for JAVASCRIPT" do
|
159
|
+
xhr :post, :create, :re_plan_id => @re_plan.id, :workflow_id => @re_workflow.id, :rule_class_name => 'mock_rule', :rule_attibutes => 'mock attributes'
|
160
|
+
response.should render_template(:update)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
describe "edit" do
|
166
|
+
it_should_require_rules_engine_editor_access(:edit, :re_plan_id => 123, :workflow_id => 456)
|
167
|
+
|
168
|
+
before(:each) do
|
169
|
+
controller.stub!(:render).with('/mock_rule/edit')
|
170
|
+
@re_rule = ReRule.make(:re_workflow => @re_workflow)
|
171
|
+
end
|
172
|
+
|
173
|
+
it "should assign a the rule record" do
|
174
|
+
get :edit, :re_plan_id => @re_plan.id, :workflow_id => @re_workflow.id, :id => @re_rule.id
|
175
|
+
assigns[:re_rule].should == @re_rule
|
176
|
+
end
|
177
|
+
|
178
|
+
describe "the rule class exists" do
|
179
|
+
it "should render the edit partial" do
|
180
|
+
controller.should_receive(:render).with('/mock_rule/edit')
|
181
|
+
get :edit, :re_plan_id => @re_plan.id, :workflow_id => @re_workflow.id, :id => @re_rule.id
|
182
|
+
response.should render_template(:edit)
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
describe "rule class does not exist" do
|
187
|
+
it "should render the error template" do
|
188
|
+
RulesEngine::Discovery.stub!(:rule_class).and_return(nil)
|
189
|
+
get :edit, :re_plan_id => @re_plan.id, :workflow_id => @re_workflow.id, :id => @re_rule.id
|
190
|
+
response.should render_template(:error)
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
describe "update" do
|
196
|
+
it_should_require_rules_engine_editor_access(:update, :re_plan_id => 123, :workflow_id => 456, :id => 456, :rule_attibutes => 'mock attributes')
|
197
|
+
|
198
|
+
before do
|
199
|
+
@re_rule = ReRule.make(:re_workflow => @re_workflow)
|
200
|
+
end
|
201
|
+
|
202
|
+
it "should get the rule record with the ID" do
|
203
|
+
ReRule.should_receive(:find).with("123").and_return(@re_rule)
|
204
|
+
put :update, :re_plan_id => @re_plan.id, :workflow_id => @re_workflow.id, :id => 123, :rule_attibutes => 'mock attributes'
|
205
|
+
assigns[:re_rule].should == @re_rule
|
206
|
+
end
|
207
|
+
|
208
|
+
describe "rule class does not exist" do
|
209
|
+
it "should render the error template" do
|
210
|
+
ReRule.stub!(:find).and_return(@re_rule)
|
211
|
+
@re_rule.stub!(:rule).and_return(nil)
|
212
|
+
put :update, :re_plan_id => @re_plan.id, :workflow_id => @re_workflow.id, :id => @re_rule.id, :rule_attibutes => 'mock attributes'
|
213
|
+
response.should render_template(:error)
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
describe "rule class exists" do
|
218
|
+
it "should assign the re_rule attributess" do
|
219
|
+
ReRule.stub!(:find).and_return(@re_rule)
|
220
|
+
@re_rule.should_receive(:rule_attributes=).with(hash_including(:rule_attibutes => 'mock attributes'))
|
221
|
+
put :update, :re_plan_id => @re_plan.id, :workflow_id => @re_workflow.id, :id => @re_rule.id, :rule_attibutes => 'mock attributes'
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
describe "save failed" do
|
226
|
+
before(:each) do
|
227
|
+
ReRule.stub!(:find).and_return(@re_rule)
|
228
|
+
@re_rule.stub!(:save).and_return(false)
|
229
|
+
end
|
230
|
+
|
231
|
+
it "should render the 'edit' template" do
|
232
|
+
controller.should_receive(:render).with('/mock_rule/edit')
|
233
|
+
put :update, :re_plan_id => @re_plan.id, :workflow_id => @re_workflow.id, :id => @re_rule.id, :rule_attibutes => 'mock attributes'
|
234
|
+
response.should render_template(:edit)
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
describe "the rule is valid" do
|
239
|
+
it "should add the rule to the workflow" do
|
240
|
+
put :update, :re_plan_id => @re_plan.id, :workflow_id => @re_workflow.id, :id => @re_rule.id, :rule_attibutes => 'mock attributes'
|
241
|
+
@re_workflow.re_rules.should include(@re_rule)
|
242
|
+
end
|
243
|
+
|
244
|
+
it "should display a flash success message" do
|
245
|
+
put :update, :re_plan_id => @re_plan.id, :workflow_id => @re_workflow.id, :id => @re_rule.id, :rule_attibutes => 'mock attributes'
|
246
|
+
flash[:success].should_not be_blank
|
247
|
+
end
|
248
|
+
|
249
|
+
it "should redirect to the change re_rule page for HTML" do
|
250
|
+
put :update, :re_plan_id => @re_plan.id, :workflow_id => @re_workflow.id, :id => @re_rule.id, :rule_attibutes => 'mock attributes'
|
251
|
+
response.should redirect_to(change_re_plan_workflow_path(@re_plan, @re_workflow))
|
252
|
+
end
|
253
|
+
|
254
|
+
it "should render 'update' template for JAVASCRIPT" do
|
255
|
+
xhr :put, :update, :re_plan_id => @re_plan.id, :workflow_id => @re_workflow.id, :id => @re_rule.id, :rule_attibutes => 'mock attributes'
|
256
|
+
response.should render_template(:update)
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
describe "destroy" do
|
262
|
+
it_should_require_rules_engine_editor_access(:destroy, :re_plan_id => 123, :workflow_id => 456, :id => 456)
|
263
|
+
|
264
|
+
before do
|
265
|
+
@re_rule = ReRule.make(:re_workflow => @re_workflow)
|
266
|
+
ReRule.stub!(:find).and_return(@re_rule)
|
267
|
+
end
|
268
|
+
|
269
|
+
it "should get the rule record with the ID" do
|
270
|
+
ReRule.should_receive(:find).with("123").and_return(@re_rule)
|
271
|
+
delete :destroy, :re_plan_id => @re_plan.id, :workflow_id => @re_workflow.id, :id => 123
|
272
|
+
assigns[:re_rule].should == @re_rule
|
273
|
+
end
|
274
|
+
|
275
|
+
it "should destroy the re_rule" do
|
276
|
+
@re_rule.should_receive(:destroy)
|
277
|
+
delete :destroy, :re_plan_id => @re_plan.id, :workflow_id => @re_workflow.id, :id => 123
|
278
|
+
end
|
279
|
+
|
280
|
+
it "should display a flash success message" do
|
281
|
+
delete :destroy, :re_plan_id => @re_plan.id, :workflow_id => @re_workflow.id, :id => 123
|
282
|
+
flash[:success].should_not be_blank
|
283
|
+
end
|
284
|
+
|
285
|
+
it "should redirect to the change re_workflow page for HTML" do
|
286
|
+
delete :destroy, :re_plan_id => @re_plan.id, :workflow_id => @re_workflow.id, :id => 123
|
287
|
+
response.should redirect_to(change_re_plan_workflow_path(@re_plan, @re_workflow))
|
288
|
+
end
|
289
|
+
|
290
|
+
it "should render the update template for JAVASCRIPT" do
|
291
|
+
xhr :delete, :destroy, :re_plan_id => @re_plan.id, :workflow_id => @re_workflow.id, :id => 123
|
292
|
+
response.should render_template(:update)
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
describe "move_up" do
|
297
|
+
it_should_require_rules_engine_editor_access(:move_up, :re_plan_id => 123, :workflow_id => 456, :id => 456)
|
298
|
+
|
299
|
+
before(:each) do
|
300
|
+
@re_rule = ReRule.make(:re_workflow => @re_workflow)
|
301
|
+
end
|
302
|
+
|
303
|
+
it "should get the rule record with the ID" do
|
304
|
+
get :move_up, :re_plan_id => @re_plan.id, :workflow_id => @re_workflow.id, :id => @re_rule.id
|
305
|
+
assigns[:re_workflow].should == @re_workflow
|
306
|
+
assigns[:re_rule].should == @re_rule
|
307
|
+
end
|
308
|
+
|
309
|
+
it "should move the rule up" do
|
310
|
+
ReRule.stub!(:find).and_return(@re_rule)
|
311
|
+
@re_rule.should_receive(:move_higher)
|
312
|
+
put :move_up, :re_plan_id => @re_plan.id, :workflow_id => @re_workflow.id, :id => 123
|
313
|
+
end
|
314
|
+
|
315
|
+
it "should redirect to the change re_workflow page for HTML" do
|
316
|
+
put :move_up, :re_plan_id => @re_plan.id, :workflow_id => @re_workflow.id, :id => @re_rule.id
|
317
|
+
response.should redirect_to(change_re_plan_workflow_path(@re_plan, @re_workflow))
|
318
|
+
end
|
319
|
+
|
320
|
+
it "should render the update template for JAVASCRIPT" do
|
321
|
+
xhr :put, :move_up, :re_plan_id => @re_plan.id, :workflow_id => @re_workflow.id, :id => @re_rule.id
|
322
|
+
response.should render_template(:update)
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
326
|
+
describe "move_down" do
|
327
|
+
it_should_require_rules_engine_editor_access(:move_down, :re_plan_id => 123, :workflow_id => 456, :id => 456)
|
328
|
+
|
329
|
+
before(:each) do
|
330
|
+
@re_rule = ReRule.make(:re_workflow => @re_workflow)
|
331
|
+
end
|
332
|
+
|
333
|
+
it "should get the rule record with the ID" do
|
334
|
+
get :move_down, :re_plan_id => @re_plan.id, :workflow_id => @re_workflow.id, :id => @re_rule.id
|
335
|
+
assigns[:re_workflow].should == @re_workflow
|
336
|
+
assigns[:re_rule].should == @re_rule
|
337
|
+
end
|
338
|
+
|
339
|
+
it "should move the rule down" do
|
340
|
+
ReRule.stub!(:find).and_return(@re_rule)
|
341
|
+
@re_rule.should_receive(:move_lower)
|
342
|
+
put :move_down, :re_plan_id => @re_plan.id, :workflow_id => @re_workflow.id, :id => 123
|
343
|
+
end
|
344
|
+
|
345
|
+
it "should redirect to the change re_workflow page for HTML" do
|
346
|
+
put :move_down, :re_plan_id => @re_plan.id, :workflow_id => @re_workflow.id, :id => @re_rule.id
|
347
|
+
response.should redirect_to(change_re_plan_workflow_path(@re_plan, @re_workflow))
|
348
|
+
end
|
349
|
+
|
350
|
+
it "should render the update template for JAVASCRIPT" do
|
351
|
+
xhr :put, :move_down, :re_plan_id => @re_plan.id, :workflow_id => @re_workflow.id, :id => @re_rule.id
|
352
|
+
response.should render_template(:update)
|
353
|
+
end
|
354
|
+
end
|
355
|
+
end
|
@@ -0,0 +1,364 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe RePlanWorkflowsController 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_plan = RePlan.make
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "show" do
|
17
|
+
it_should_require_rules_engine_reader_access(:show, :re_plan_id => 123, :id => 456)
|
18
|
+
|
19
|
+
it "should get the workflow record with the ID" do
|
20
|
+
re_workflow = ReWorkflow.make(:re_plans => [@re_plan])
|
21
|
+
get :show, :re_plan_id => @re_plan.id, :id => re_workflow.id
|
22
|
+
assigns[:re_plan].should == @re_plan
|
23
|
+
assigns[:re_workflow].should == re_workflow
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "new" do
|
28
|
+
it_should_require_rules_engine_editor_access(:new, :re_plan_id => 123)
|
29
|
+
|
30
|
+
it "should assign a new workflow record" do
|
31
|
+
get :new, :re_plan_id => @re_plan.id
|
32
|
+
assigns[:re_workflow].should be_instance_of(ReWorkflow)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should render the 'new' template" do
|
36
|
+
get :new, :re_plan_id => @re_plan.id
|
37
|
+
response.should render_template(:new)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "create" do
|
42
|
+
it_should_require_rules_engine_editor_access(:create, :re_plan_id => 123, :re_workflow => {})
|
43
|
+
|
44
|
+
before do
|
45
|
+
@re_workflow = ReWorkflow.make
|
46
|
+
ReWorkflow.stub!(:new).and_return(@re_workflow)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should assign the re_workflow parameters" do
|
50
|
+
ReWorkflow.should_receive(:new).with("code" => "name", "title" => "value")
|
51
|
+
post :create, :re_plan_id => @re_plan.id, :re_workflow => { :code => "name", :title => "value" }
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should save the re_workflow" do
|
55
|
+
@re_workflow.should_receive(:save)
|
56
|
+
post :create, :re_plan_id => @re_plan.id, :re_workflow => { :title => "name" }
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "save failed" do
|
60
|
+
before(:each) do
|
61
|
+
@re_workflow.stub!(:save).and_return(false)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should render the 'new' template" do
|
65
|
+
post :create, :re_plan_id => @re_plan.id, :re_workflow => { :title => "name" }
|
66
|
+
response.should render_template(:new)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "save succeeded" do
|
71
|
+
before(:each) do
|
72
|
+
@re_workflow.stub!(:save).and_return(true)
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should add the workflow to the plan" do
|
76
|
+
post :create, :re_plan_id => @re_plan.id, :re_workflow => { :title => "name" }
|
77
|
+
@re_plan.re_workflows.should include(@re_workflow)
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should display a flash success message" do
|
81
|
+
post :create, :re_plan_id => @re_plan.id, :re_workflow => { :title => "name" }
|
82
|
+
flash[:success].should_not be_blank
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should redirect to the change re_workflow page for HTML" do
|
86
|
+
post :create, :re_plan_id => @re_plan.id, :re_workflow => { :title => "name" }
|
87
|
+
response.should redirect_to(change_re_plan_path(@re_plan))
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should render 're_plans/update' template for JAVASCRIPT" do
|
91
|
+
xhr :post, :create, :re_plan_id => @re_plan.id, :re_workflow => { :title => "name" }
|
92
|
+
response.should render_template('re_plans/update')
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "edit" do
|
98
|
+
it_should_require_rules_engine_editor_access(:edit, :re_plan_id => 123, :id => 456)
|
99
|
+
|
100
|
+
it "should get the workflow record with the ID" do
|
101
|
+
re_workflow = ReWorkflow.make(:re_plans => [@re_plan])
|
102
|
+
get :edit, :re_plan_id => @re_plan.id, :id => re_workflow.id
|
103
|
+
assigns[:re_plan].should == @re_plan
|
104
|
+
assigns[:re_workflow].should == re_workflow
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe "update" do
|
109
|
+
it_should_require_rules_engine_editor_access(:update, :re_plan_id => 123, :id => 456, :re_workflow => {})
|
110
|
+
|
111
|
+
before do
|
112
|
+
@re_workflow = ReWorkflow.make(:re_plans => [@re_plan])
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should get the workflow record with the ID" do
|
116
|
+
ReWorkflow.should_receive(:find).with("123").and_return(@re_workflow)
|
117
|
+
put :update, :re_plan_id => @re_plan.id, :id => 123, :re_workflow => { :title => "value" }
|
118
|
+
assigns[:re_workflow].should == @re_workflow
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should assign the re_workflow parameters" do
|
122
|
+
ReWorkflow.stub!(:find).and_return(@re_workflow)
|
123
|
+
@re_workflow.should_receive(:attributes=).with("title" => "name")
|
124
|
+
put :update, :re_plan_id => @re_plan.id, :id => @re_workflow.id, :re_workflow => { :title => "name" }
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should not assign the re_workflow parameters :code" do
|
128
|
+
ReWorkflow.stub!(:find).and_return(@re_workflow)
|
129
|
+
@re_workflow.should_receive(:attributes=).with("title" => "name")
|
130
|
+
put :update, :re_plan_id => @re_plan.id, :id => @re_workflow.id, :re_workflow => { :title => "name", :code => "code" }
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should save the re_workflow" do
|
134
|
+
put :update, :re_plan_id => @re_plan.id, :id => @re_workflow.id, :re_workflow => { :title => "new name" }
|
135
|
+
@re_workflow.reload
|
136
|
+
@re_workflow.title.should == 'new name'
|
137
|
+
end
|
138
|
+
|
139
|
+
describe "save failed" do
|
140
|
+
it "should render the 'edit' template" do
|
141
|
+
put :update, :re_plan_id => @re_plan.id, :id => @re_workflow.id, :re_workflow => { :title => nil }
|
142
|
+
response.should render_template(:edit)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
describe "save succeeded" do
|
147
|
+
it "should display a flash success message" do
|
148
|
+
put :update, :re_plan_id => @re_plan.id, :id => @re_workflow.id, :re_workflow => { :title => "name" }
|
149
|
+
flash[:success].should_not be_blank
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should redirect to the change re_workflow page for HTML" do
|
153
|
+
put :update, :re_plan_id => @re_plan.id, :id => @re_workflow.id, :re_workflow => { :title => "name" }
|
154
|
+
response.should redirect_to(change_re_workflow_path(@re_workflow))
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should render 'update' template for JAVASCRIPT" do
|
158
|
+
xhr :put, :update, :re_plan_id => @re_plan.id, :id => @re_workflow.id, :re_workflow => { :title => "name" }
|
159
|
+
response.should render_template(:update)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
describe "destroy" do
|
165
|
+
it_should_require_rules_engine_editor_access(:destroy, :re_plan_id => 123, :id => 456)
|
166
|
+
|
167
|
+
before do
|
168
|
+
@re_workflow = ReWorkflow.make(:re_plans => [@re_plan])
|
169
|
+
ReWorkflow.stub!(:find).and_return(@re_workflow)
|
170
|
+
end
|
171
|
+
|
172
|
+
it "should get the workflow record with the ID" do
|
173
|
+
ReWorkflow.should_receive(:find).with("123").and_return(@re_workflow)
|
174
|
+
delete :destroy, :re_plan_id => @re_plan.id, :id => 123
|
175
|
+
assigns[:re_workflow].should == @re_workflow
|
176
|
+
end
|
177
|
+
|
178
|
+
it "should destroy the re_workflow" do
|
179
|
+
@re_workflow.should_receive(:destroy)
|
180
|
+
delete :destroy, :re_plan_id => @re_plan.id, :id => 123
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should display a flash success message" do
|
184
|
+
delete :destroy, :re_plan_id => @re_plan.id, :id => 123
|
185
|
+
flash[:success].should_not be_blank
|
186
|
+
end
|
187
|
+
|
188
|
+
it "should redirect to the change re_plan page for HTML" do
|
189
|
+
delete :destroy, :re_plan_id => @re_plan.id, :id => 123
|
190
|
+
response.should redirect_to(change_re_plan_path(@re_plan))
|
191
|
+
end
|
192
|
+
|
193
|
+
it "should redirect to the change re_plan page page for JAVASCRIPT" do
|
194
|
+
xhr :delete, :destroy, :re_plan_id => @re_plan.id, :id => 123
|
195
|
+
response.body.should == "window.location.href = '#{change_re_plan_path(@re_plan)}';"
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
describe "change" do
|
200
|
+
it_should_require_rules_engine_editor_access(:change, :re_plan_id => 123, :id => 456)
|
201
|
+
|
202
|
+
before(:each) do
|
203
|
+
@re_workflow = ReWorkflow.make(:re_plans => [@re_plan])
|
204
|
+
end
|
205
|
+
|
206
|
+
it "should rediscover all of the rules" do
|
207
|
+
RulesEngine::Discovery.should_receive(:discover!)
|
208
|
+
get :change, :re_plan_id => @re_plan.id, :id => @re_workflow.id
|
209
|
+
end
|
210
|
+
|
211
|
+
it "should get the workflow record with the ID" do
|
212
|
+
get :change, :re_plan_id => @re_plan.id, :id => @re_workflow.id
|
213
|
+
assigns[:re_plan].should == @re_plan
|
214
|
+
assigns[:re_workflow].should == @re_workflow
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
describe "default" do
|
219
|
+
it_should_require_rules_engine_editor_access(:default, :re_plan_id => 123, :id => 456)
|
220
|
+
|
221
|
+
before(:each) do
|
222
|
+
@re_workflow_one = ReWorkflow.make(:re_plans => [@re_plan])
|
223
|
+
@re_workflow_two = ReWorkflow.make(:re_plans => [@re_plan])
|
224
|
+
end
|
225
|
+
|
226
|
+
it "should set the default workflow" do
|
227
|
+
@re_plan.default_workflow.should == @re_workflow_one
|
228
|
+
put :default, :re_plan_id => @re_plan.id, :id => @re_workflow_two.id
|
229
|
+
@re_plan.reload
|
230
|
+
@re_plan.default_workflow.should == @re_workflow_two
|
231
|
+
end
|
232
|
+
|
233
|
+
it "should redirect to the change re_plan page for HTML" do
|
234
|
+
put :default, :re_plan_id => @re_plan.id, :id => @re_workflow_one.id
|
235
|
+
response.should redirect_to(change_re_plan_path(@re_plan))
|
236
|
+
end
|
237
|
+
|
238
|
+
it "should render to the update re_plan page page for JAVASCRIPT" do
|
239
|
+
xhr :put, :default, :re_plan_id => @re_plan.id, :id => @re_workflow_one.id
|
240
|
+
response.should render_template('re_plans/update')
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
describe "add" do
|
245
|
+
it_should_require_rules_engine_editor_access(:add, :re_plan_id => 123, :id => 456)
|
246
|
+
|
247
|
+
before(:each) do
|
248
|
+
@re_workflow_one = ReWorkflow.make(:re_plans => [@re_plan])
|
249
|
+
@re_workflow_two = ReWorkflow.make
|
250
|
+
end
|
251
|
+
|
252
|
+
it "should add the workflow" do
|
253
|
+
put :add, :re_plan_id => @re_plan.id, :id => @re_workflow_two.id
|
254
|
+
@re_plan.reload
|
255
|
+
@re_plan.re_workflows.should == [@re_workflow_one, @re_workflow_two]
|
256
|
+
end
|
257
|
+
|
258
|
+
it "should redirect to the change re_plan page for HTML" do
|
259
|
+
put :add, :re_plan_id => @re_plan.id, :id => @re_workflow_one.id
|
260
|
+
response.should redirect_to(change_re_plan_path(@re_plan))
|
261
|
+
end
|
262
|
+
|
263
|
+
it "should render to the update re_plan page page for JAVASCRIPT" do
|
264
|
+
xhr :put, :add, :re_plan_id => @re_plan.id, :id => @re_workflow_one.id
|
265
|
+
response.should render_template('re_plans/update')
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
describe "remove" do
|
270
|
+
it_should_require_rules_engine_editor_access(:remove, :re_plan_id => 123, :id => 456)
|
271
|
+
|
272
|
+
before(:each) do
|
273
|
+
@re_workflow_one = ReWorkflow.make(:re_plans => [@re_plan])
|
274
|
+
@re_workflow_two = ReWorkflow.make(:re_plans => [@re_plan])
|
275
|
+
end
|
276
|
+
|
277
|
+
it "should remove the workflow" do
|
278
|
+
put :remove, :re_plan_id => @re_plan.id, :id => @re_workflow_two.id
|
279
|
+
@re_plan.reload
|
280
|
+
@re_plan.re_workflows.should == [@re_workflow_one]
|
281
|
+
flash[:success].should_not be_blank
|
282
|
+
end
|
283
|
+
|
284
|
+
it "should redirect to the change re_plan page for HTML" do
|
285
|
+
put :remove, :re_plan_id => @re_plan.id, :id => @re_workflow_one.id
|
286
|
+
response.should redirect_to(change_re_plan_path(@re_plan))
|
287
|
+
end
|
288
|
+
|
289
|
+
it "should render to the update re_plan page page for JAVASCRIPT" do
|
290
|
+
xhr :put, :remove, :re_plan_id => @re_plan.id, :id => @re_workflow_one.id
|
291
|
+
response.should render_template('re_plans/update')
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
295
|
+
describe "copy" do
|
296
|
+
it_should_require_rules_engine_editor_access(:copy, :re_plan_id => 123, :id => 456)
|
297
|
+
|
298
|
+
before(:each) do
|
299
|
+
@re_workflow = ReWorkflow.make(:re_plans => [@re_plan])
|
300
|
+
end
|
301
|
+
|
302
|
+
it "should assign an empty workflow copy" do
|
303
|
+
get :copy, :re_plan_id => @re_plan.id, :id => @re_workflow.id
|
304
|
+
assigns[:re_workflow_copy].should be_instance_of(ReWorkflow)
|
305
|
+
end
|
306
|
+
end
|
307
|
+
|
308
|
+
describe "duplicate" do
|
309
|
+
it_should_require_rules_engine_editor_access(:duplicate, :re_plan_id => 123, :id => 456)
|
310
|
+
|
311
|
+
before(:each) do
|
312
|
+
@re_workflow = ReWorkflow.make(:re_plans => [@re_plan])
|
313
|
+
ReWorkflow.stub!(:find).and_return(@re_workflow)
|
314
|
+
|
315
|
+
@re_workflow_copy = ReWorkflow.make
|
316
|
+
ReWorkflow.stub!(:new).and_return(@re_workflow_copy)
|
317
|
+
end
|
318
|
+
|
319
|
+
it "should use the revert and publish method to copy the parameters" do
|
320
|
+
@re_workflow.should_receive(:publish).and_return({:published => "mock value"})
|
321
|
+
@re_workflow_copy.should_receive(:revert!).with({:published => "mock value"})
|
322
|
+
post :duplicate, :re_plan_id => @re_plan.id, :id => @re_workflow.id, :re_workflow => {:title => 'new title'}
|
323
|
+
end
|
324
|
+
|
325
|
+
it "should update the attributes of the new workflow" do
|
326
|
+
post :duplicate, :re_plan_id => @re_plan.id, :id => @re_workflow.id, :re_workflow => {:title => 'new title'}
|
327
|
+
@re_workflow_copy.title.should == 'new title'
|
328
|
+
end
|
329
|
+
|
330
|
+
describe "the copied workflow was saved" do
|
331
|
+
before(:each) do
|
332
|
+
@re_workflow_copy.stub!(:save).and_return(true)
|
333
|
+
end
|
334
|
+
|
335
|
+
it "should add the copied workflow to the re_plan" do
|
336
|
+
RePlan.stub!(:find).and_return(@re_plan)
|
337
|
+
@re_plan.should_receive(:add_workflow).with(@re_workflow_copy)
|
338
|
+
post :duplicate, :re_plan_id => @re_plan.id, :id => @re_workflow.id, :re_workflow => {:title => 'new title'}
|
339
|
+
end
|
340
|
+
|
341
|
+
it "should display a flash success message" do
|
342
|
+
post :duplicate, :re_plan_id => @re_plan.id, :id => @re_workflow.id, :re_workflow => {:title => 'new title'}
|
343
|
+
flash[:success].should_not be_blank
|
344
|
+
end
|
345
|
+
|
346
|
+
it "should redirect to the change re_plan workflow page for HTML" do
|
347
|
+
post :duplicate, :re_plan_id => @re_plan.id, :id => @re_workflow.id, :re_workflow => {:title => 'new title'}
|
348
|
+
response.should redirect_to(change_re_plan_workflow_path(@re_plan, @re_workflow_copy))
|
349
|
+
end
|
350
|
+
|
351
|
+
it "should redirect to the change re_workflows page for JAVASCRIPT" do
|
352
|
+
xhr :post, :duplicate, :re_plan_id => @re_plan.id, :id => @re_workflow.id, :re_workflow => {:title => 'new title'}
|
353
|
+
response.body.should == "window.location.href = '#{change_re_plan_workflow_path(@re_plan, @re_workflow_copy)}';"
|
354
|
+
end
|
355
|
+
end
|
356
|
+
|
357
|
+
describe "the copied workflow was not saved" do
|
358
|
+
it "should render the 'copy' template" do
|
359
|
+
post :duplicate, :re_plan_id => @re_plan.id, :id => @re_workflow.id, :re_workflow => {:title => nil}
|
360
|
+
response.should render_template(:copy)
|
361
|
+
end
|
362
|
+
end
|
363
|
+
end
|
364
|
+
end
|