rules_engine_templates 0.0.2 → 0.0.3
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/plan_start.rb +26 -0
- data/rails_generators/manifests/plan_start.yml +20 -0
- data/rails_generators/manifests/tweet_filter.rb +2 -4
- data/rails_generators/manifests/tweet_filter.yml +2 -5
- data/rails_generators/manifests/tweet_reader.rb +26 -0
- data/rails_generators/manifests/tweet_reader.yml +20 -0
- data/rails_generators/manifests/workflow_start.rb +26 -0
- data/rails_generators/manifests/workflow_start.yml +20 -0
- data/rails_generators/manifests/workflow_stop.rb +26 -0
- data/rails_generators/manifests/workflow_stop.yml +20 -0
- data/rails_generators/templates/app/rules/plan_start.rb +89 -0
- data/rails_generators/templates/app/rules/tweet_filter.rb +6 -3
- data/rails_generators/templates/app/rules/tweet_reader.rb +99 -0
- data/rails_generators/templates/app/rules/workflow_start.rb +84 -0
- data/rails_generators/templates/app/rules/workflow_stop.rb +80 -0
- data/rails_generators/templates/app/views/re_rule_definitions/plan_start/_edit.html.erb +1 -0
- data/rails_generators/templates/app/views/re_rule_definitions/plan_start/_form.html.erb +21 -0
- data/rails_generators/templates/app/views/re_rule_definitions/plan_start/_help.html.erb +1 -0
- data/rails_generators/templates/app/views/re_rule_definitions/plan_start/_new.html.erb +1 -0
- data/rails_generators/templates/app/views/re_rule_definitions/tweet_filter/_edit.html.erb +1 -5
- data/rails_generators/templates/app/views/re_rule_definitions/tweet_filter/_form.html.erb +34 -0
- data/rails_generators/templates/app/views/re_rule_definitions/tweet_filter/{_word.html.erb → _form_word.html.erb} +0 -0
- data/rails_generators/templates/app/views/re_rule_definitions/tweet_filter/_help.html.erb +1 -1
- data/rails_generators/templates/app/views/re_rule_definitions/tweet_filter/_new.html.erb +1 -5
- data/rails_generators/templates/app/views/re_rule_definitions/tweet_reader/_edit.html.erb +1 -0
- data/rails_generators/templates/app/views/re_rule_definitions/tweet_reader/_form.html.erb +29 -0
- data/rails_generators/templates/app/views/re_rule_definitions/tweet_reader/_help.html.erb +1 -0
- data/rails_generators/templates/app/views/re_rule_definitions/tweet_reader/_new.html.erb +1 -0
- data/rails_generators/templates/app/views/re_rule_definitions/workflow_start/_edit.html.erb +1 -0
- data/rails_generators/templates/app/views/re_rule_definitions/workflow_start/_form.html.erb +21 -0
- data/rails_generators/templates/app/views/re_rule_definitions/workflow_start/_help.html.erb +1 -0
- data/rails_generators/templates/app/views/re_rule_definitions/workflow_start/_new.html.erb +1 -0
- data/rails_generators/templates/app/views/re_rule_definitions/workflow_stop/_edit.html.erb +1 -0
- data/rails_generators/templates/app/views/re_rule_definitions/workflow_stop/_form.html.erb +25 -0
- data/rails_generators/templates/app/views/re_rule_definitions/workflow_stop/_help.html.erb +1 -0
- data/rails_generators/templates/app/views/re_rule_definitions/workflow_stop/_new.html.erb +1 -0
- data/rails_generators/templates/spec/lib/rules/plan_start_spec.rb +237 -0
- data/rails_generators/templates/spec/lib/rules/tweet_filter_spec.rb +61 -10
- data/rails_generators/templates/spec/lib/rules/tweet_reader_spec.rb +272 -0
- data/rails_generators/templates/spec/lib/rules/workflow_start_spec.rb +223 -0
- data/rails_generators/templates/spec/lib/rules/workflow_stop_spec.rb +212 -0
- metadata +38 -8
- data/rails_generators/templates/app/views/re_rule_definitions/tweet_filter/_script.html.erb +0 -8
- data/rails_generators/templates/app/views/re_rule_definitions/tweet_filter/_title.html.erb +0 -7
- data/rails_generators/templates/app/views/re_rule_definitions/tweet_filter/_words.html.erb +0 -16
@@ -1,10 +1,15 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
2
|
|
3
|
+
def valid_<%=rule_name%>_rule_data
|
4
|
+
'["Rule Title", ["word one", "word two"]]'
|
5
|
+
end
|
6
|
+
|
7
|
+
|
3
8
|
describe RulesEngine::Rule::<%=rule_class%> do
|
4
9
|
|
5
10
|
def valid_attributes
|
6
11
|
{
|
7
|
-
:<%=rule_name%>_title => '
|
12
|
+
:<%=rule_name%>_title => 'Another Title',
|
8
13
|
:<%=rule_name%>_words => {
|
9
14
|
"1" => { "word" => 'first word' },
|
10
15
|
"2" => { "word" => 'second word' }
|
@@ -12,10 +17,6 @@ describe RulesEngine::Rule::<%=rule_class%> do
|
|
12
17
|
}
|
13
18
|
end
|
14
19
|
|
15
|
-
def valid_json_data
|
16
|
-
'["Rule Title", ["one", "two"]]'
|
17
|
-
end
|
18
|
-
|
19
20
|
it "should be discoverable" do
|
20
21
|
RulesEngine::Discovery.rule_class("RulesEngine::Rule::<%=rule_class%>").should == RulesEngine::Rule::<%=rule_class%>
|
21
22
|
end
|
@@ -45,7 +46,7 @@ describe RulesEngine::Rule::<%=rule_class%> do
|
|
45
46
|
describe "setting the rule data" do
|
46
47
|
before(:each) do
|
47
48
|
@filter = RulesEngine::Rule::<%=rule_class%>.new
|
48
|
-
@filter.data =
|
49
|
+
@filter.data = valid_<%=rule_name%>_rule_data
|
49
50
|
end
|
50
51
|
|
51
52
|
describe "the json data is valid" do
|
@@ -58,7 +59,7 @@ describe RulesEngine::Rule::<%=rule_class%> do
|
|
58
59
|
end
|
59
60
|
|
60
61
|
it "should set the words" do
|
61
|
-
@filter.words.should == ["one", "two"]
|
62
|
+
@filter.words.should == ["word one", "word two"]
|
62
63
|
end
|
63
64
|
end
|
64
65
|
|
@@ -94,9 +95,9 @@ describe RulesEngine::Rule::<%=rule_class%> do
|
|
94
95
|
describe "the data" do
|
95
96
|
it "should be converted to a json string" do
|
96
97
|
filter = RulesEngine::Rule::<%=rule_class%>.new
|
97
|
-
filter.should_receive(:title).and_return(
|
98
|
+
filter.should_receive(:title).and_return("mock title")
|
98
99
|
filter.should_receive(:words).and_return(["one", "two"])
|
99
|
-
filter.data.should == '[
|
100
|
+
filter.data.should == '["mock title",["one","two"]]'
|
100
101
|
end
|
101
102
|
end
|
102
103
|
|
@@ -120,7 +121,7 @@ describe RulesEngine::Rule::<%=rule_class%> do
|
|
120
121
|
describe "setting the <%=rule_name%>_title" do
|
121
122
|
it "should set the title" do
|
122
123
|
@filter.attributes = valid_attributes
|
123
|
-
@filter.title.should == '
|
124
|
+
@filter.title.should == 'Another Title'
|
124
125
|
end
|
125
126
|
|
126
127
|
it "should not be valid if the '<%=rule_name%>_title' attribute is missing" do
|
@@ -218,3 +219,53 @@ describe RulesEngine::Rule::<%=rule_class%> do
|
|
218
219
|
end
|
219
220
|
end
|
220
221
|
end
|
222
|
+
|
223
|
+
describe ReWorkflowRulesController, :type => :controller do
|
224
|
+
integrate_views
|
225
|
+
|
226
|
+
before(:each) do
|
227
|
+
controller.instance_eval { flash.stub!(:sweep) }
|
228
|
+
|
229
|
+
RulesEngine::Discovery.discover!
|
230
|
+
|
231
|
+
controller.stub!(:rules_engine_reader_access_required).and_return(true)
|
232
|
+
controller.stub!(:rules_engine_editor_access_required).and_return(true)
|
233
|
+
|
234
|
+
@re_workflow = ReWorkflow.make
|
235
|
+
ReWorkflow.stub!(:find).and_return(@re_workflow)
|
236
|
+
end
|
237
|
+
|
238
|
+
describe "help" do
|
239
|
+
it "should assign the <%=rule_name%> rule class" do
|
240
|
+
get :help, :rule_class_name => "RulesEngine::Rule::<%=rule_class%>"
|
241
|
+
assigns[:rule_class].should == RulesEngine::Rule::<%=rule_class%>
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
describe "new" do
|
246
|
+
it "show the new form" do
|
247
|
+
get :new, :rule_class_name => "RulesEngine::Rule::<%=rule_class%>"
|
248
|
+
response.should have_tag("form#re_rule_new_form") do
|
249
|
+
with_tag("input#<%=rule_name%>_title")
|
250
|
+
with_tag("input#<%=rule_name%>_words_0_word")
|
251
|
+
end
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
describe "edit" do
|
256
|
+
it "show the edit form" do
|
257
|
+
re_rule = ReRule.make(:re_workflow_id => @re_workflow.id,
|
258
|
+
:rule_class_name => "RulesEngine::Rule::<%=rule_class%>",
|
259
|
+
:data => valid_<%=rule_name%>_rule_data)
|
260
|
+
ReRule.stub!(:find).and_return(re_rule)
|
261
|
+
|
262
|
+
get :edit, :re_workflow_id => @re_workflow.id, :re_rule_id => 1001, :rule_class_name => "RulesEngine::Rule::<%=rule_class%>"
|
263
|
+
response.should have_tag("form#re_rule_edit_form") do
|
264
|
+
with_tag("input#<%=rule_name%>_title", :value => 'Rule Title')
|
265
|
+
with_tag("input#<%=rule_name%>_words_0_word", :value => 'word one')
|
266
|
+
with_tag("input#<%=rule_name%>_words_1_word", :value => 'word two')
|
267
|
+
end
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
end
|
@@ -0,0 +1,272 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
def valid_<%=rule_name%>_rule_data
|
4
|
+
'["Rule Title", "Twitter Message to Find", "Other Plan"]'
|
5
|
+
end
|
6
|
+
|
7
|
+
|
8
|
+
describe RulesEngine::Rule::<%=rule_class%> do
|
9
|
+
|
10
|
+
def valid_attributes
|
11
|
+
{
|
12
|
+
:<%=rule_name%>_title => 'Rule Title',
|
13
|
+
:<%=rule_name%>_message => 'The Message',
|
14
|
+
:<%=rule_name%>_plan => 'Next Plan'
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should be discoverable" do
|
19
|
+
RulesEngine::Discovery.rule_class("RulesEngine::Rule::<%=rule_class%>").should == RulesEngine::Rule::<%=rule_class%>
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "the expected class options" do
|
23
|
+
it "should be in the 'General' group" do
|
24
|
+
RulesEngine::Rule::<%=rule_class%>.options[:group].should == "Twitter"
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should have the diplay name of '<%=rule_class%> Rule'" do
|
28
|
+
RulesEngine::Rule::<%=rule_class%>.options[:display_name].should == "Twitter Reader"
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should have the help template of '/re_rule_definitions/<%=rule_name%>/help'" do
|
32
|
+
RulesEngine::Rule::<%=rule_class%>.options[:help_partial].should == '/re_rule_definitions/<%=rule_name%>/help'
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should have the new template of '/re_rule_definitions/<%=rule_name%>/new'" do
|
36
|
+
RulesEngine::Rule::<%=rule_class%>.options[:new_partial].should == '/re_rule_definitions/<%=rule_name%>/new'
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should have the edit view partial template of '/re_rule_definitions/<%=rule_name%>/edit'" do
|
40
|
+
RulesEngine::Rule::<%=rule_class%>.options[:edit_partial].should == '/re_rule_definitions/<%=rule_name%>/edit'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "setting the rule data" do
|
45
|
+
before(:each) do
|
46
|
+
@<%=rule_name%> = RulesEngine::Rule::<%=rule_class%>.new
|
47
|
+
@<%=rule_name%>.data = valid_<%=rule_name%>_rule_data
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "the json data is valid" do
|
51
|
+
it "should be valid" do
|
52
|
+
@<%=rule_name%>.should be_valid
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should set the title" do
|
56
|
+
@<%=rule_name%>.title.should == "Rule Title"
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should set the message" do
|
60
|
+
@<%=rule_name%>.message.should == "Twitter Message to Find"
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should set the plan" do
|
64
|
+
@<%=rule_name%>.plan.should == "Other Plan"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "the data is nil" do
|
69
|
+
it "should set the title to nil" do
|
70
|
+
@<%=rule_name%>.title.should_not be_nil
|
71
|
+
@<%=rule_name%>.data = nil
|
72
|
+
@<%=rule_name%>.title.should be_nil
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should set the message to nil" do
|
76
|
+
@<%=rule_name%>.message.should_not be_nil
|
77
|
+
@<%=rule_name%>.data = nil
|
78
|
+
@<%=rule_name%>.message.should be_nil
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should set the 'plan' to nil" do
|
82
|
+
@<%=rule_name%>.plan.should_not be_nil
|
83
|
+
@<%=rule_name%>.data = nil
|
84
|
+
@<%=rule_name%>.plan.should be_nil
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "the summary" do
|
90
|
+
it "should show the plan" do
|
91
|
+
<%=rule_name%> = RulesEngine::Rule::<%=rule_class%>.new
|
92
|
+
<%=rule_name%>.stub!(:message).and_return("twitter message")
|
93
|
+
<%=rule_name%>.stub!(:plan).and_return("mock")
|
94
|
+
<%=rule_name%>.summary.should == "Look for \"twitter message\" and send matches to the plan : mock"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe "the data" do
|
99
|
+
it "should be converted to a json string" do
|
100
|
+
<%=rule_name%> = RulesEngine::Rule::<%=rule_class%>.new
|
101
|
+
<%=rule_name%>.should_receive(:title).and_return("mock title")
|
102
|
+
<%=rule_name%>.should_receive(:message).and_return("message")
|
103
|
+
<%=rule_name%>.should_receive(:plan).and_return("plan")
|
104
|
+
<%=rule_name%>.data.should == '["mock title","message","plan"]'
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe "the expected_outcomes" do
|
109
|
+
it "should be next and stop failure" do
|
110
|
+
<%=rule_name%> = RulesEngine::Rule::<%=rule_class%>.new
|
111
|
+
<%=rule_name%>.expected_outcomes.should include(:outcome => RulesEngine::Rule::Outcome::NEXT)
|
112
|
+
<%=rule_name%>.expected_outcomes.should include(:outcome => RulesEngine::Rule::Outcome::STOP_FAILURE)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe "setting the rule attributes" do
|
117
|
+
before(:each) do
|
118
|
+
@<%=rule_name%> = RulesEngine::Rule::<%=rule_class%>.new
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should be valid with valid attributes" do
|
122
|
+
@<%=rule_name%>.attributes = valid_attributes
|
123
|
+
@<%=rule_name%>.should be_valid
|
124
|
+
end
|
125
|
+
|
126
|
+
describe "setting the <%=rule_name%>_title" do
|
127
|
+
it "should set the title" do
|
128
|
+
@<%=rule_name%>.attributes = valid_attributes
|
129
|
+
@<%=rule_name%>.title.should == 'Rule Title'
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should not be valid if the '<%=rule_name%>_title' attribute is missing" do
|
133
|
+
@<%=rule_name%>.attributes = valid_attributes.except(:<%=rule_name%>_title)
|
134
|
+
@<%=rule_name%>.should_not be_valid
|
135
|
+
@<%=rule_name%>.errors.should include(:<%=rule_name%>_title)
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should not be valid if the '<%=rule_name%>_title' attribute is blank" do
|
139
|
+
@<%=rule_name%>.attributes = valid_attributes.merge(:<%=rule_name%>_title => "")
|
140
|
+
@<%=rule_name%>.should_not be_valid
|
141
|
+
@<%=rule_name%>.errors.should include(:<%=rule_name%>_title)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
describe "setting the <%=rule_name%>_message" do
|
146
|
+
it "should set the message" do
|
147
|
+
@<%=rule_name%>.attributes = valid_attributes
|
148
|
+
@<%=rule_name%>.message.should == 'The Message'
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should not be valid if the '<%=rule_name%>_message' attribute is missing" do
|
152
|
+
@<%=rule_name%>.attributes = valid_attributes.except(:<%=rule_name%>_message)
|
153
|
+
@<%=rule_name%>.should_not be_valid
|
154
|
+
@<%=rule_name%>.errors.should include(:<%=rule_name%>_message)
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should not be valid if the '<%=rule_name%>_message' attribute is blank" do
|
158
|
+
@<%=rule_name%>.attributes = valid_attributes.merge(:<%=rule_name%>_message => "")
|
159
|
+
@<%=rule_name%>.should_not be_valid
|
160
|
+
@<%=rule_name%>.errors.should include(:<%=rule_name%>_message)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
describe "setting the <%=rule_name%>_plan" do
|
165
|
+
it "should be valid with valid '<%=rule_name%>_plan'" do
|
166
|
+
@<%=rule_name%>.attributes = valid_attributes
|
167
|
+
@<%=rule_name%>.should be_valid
|
168
|
+
@<%=rule_name%>.plan.should == 'Next Plan'
|
169
|
+
end
|
170
|
+
|
171
|
+
it "should not be valid if the '<%=rule_name%>_plan' attribute is missing" do
|
172
|
+
@<%=rule_name%>.attributes = valid_attributes.except(:<%=rule_name%>_plan)
|
173
|
+
@<%=rule_name%>.should_not be_valid
|
174
|
+
@<%=rule_name%>.errors.should include(:<%=rule_name%>_plan)
|
175
|
+
end
|
176
|
+
|
177
|
+
it "should not be valid if the '<%=rule_name%>_plan' attribute is blank" do
|
178
|
+
@<%=rule_name%>.attributes = valid_attributes.merge(:<%=rule_name%>_plan => "")
|
179
|
+
@<%=rule_name%>.should_not be_valid
|
180
|
+
@<%=rule_name%>.errors.should include(:<%=rule_name%>_plan)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
describe "after a rule is created" do
|
186
|
+
# xit "There is nothing to do here"
|
187
|
+
end
|
188
|
+
|
189
|
+
describe "after a rule is created" do
|
190
|
+
# xit "There is nothing to do here"
|
191
|
+
end
|
192
|
+
|
193
|
+
describe "processing the rule" do
|
194
|
+
before(:each) do
|
195
|
+
@<%=rule_name%> = RulesEngine::Rule::<%=rule_class%>.new
|
196
|
+
@<%=rule_name%>.stub!(:plan).and_return('sub_plan')
|
197
|
+
@<%=rule_name%>.stub!(:message).and_return("sub message")
|
198
|
+
|
199
|
+
RulesEngine::Process.runner.stub!(:create).and_return(1003)
|
200
|
+
RulesEngine::Process.runner.stub!(:run)
|
201
|
+
end
|
202
|
+
|
203
|
+
it "should create a rules process to run" do
|
204
|
+
RulesEngine::Process.runner.should_receive(:create).and_return(1003)
|
205
|
+
RulesEngine::Process.runner.should_receive(:run).with(1003, 'sub_plan', {:origional => "data", :message => "sub message"})
|
206
|
+
@<%=rule_name%>.process(1003, {:origional => "data"})
|
207
|
+
end
|
208
|
+
|
209
|
+
it "should return outcome next if the plan was successful" do
|
210
|
+
RulesEngine::Process.runner.stub!(:run).and_return(true)
|
211
|
+
@<%=rule_name%>.process(1003, {}).outcome.should == RulesEngine::Rule::Outcome::NEXT
|
212
|
+
end
|
213
|
+
|
214
|
+
it "should return outcome stop failure if the plan failed" do
|
215
|
+
RulesEngine::Process.runner.stub!(:run).and_return(false)
|
216
|
+
@<%=rule_name%>.process(1003, {}).outcome.should == RulesEngine::Rule::Outcome::STOP_FAILURE
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
|
222
|
+
describe ReWorkflowRulesController, :type => :controller do
|
223
|
+
integrate_views
|
224
|
+
|
225
|
+
before(:each) do
|
226
|
+
controller.instance_eval { flash.stub!(:sweep) }
|
227
|
+
|
228
|
+
RulesEngine::Discovery.discover!
|
229
|
+
|
230
|
+
controller.stub!(:rules_engine_reader_access_required).and_return(true)
|
231
|
+
controller.stub!(:rules_engine_editor_access_required).and_return(true)
|
232
|
+
|
233
|
+
@re_workflow = ReWorkflow.make
|
234
|
+
ReWorkflow.stub!(:find).and_return(@re_workflow)
|
235
|
+
end
|
236
|
+
|
237
|
+
describe "help" do
|
238
|
+
it "should assign the tweet reader_rule class" do
|
239
|
+
get :help, :rule_class_name => "RulesEngine::Rule::<%=rule_class%>"
|
240
|
+
assigns[:rule_class].should == RulesEngine::Rule::<%=rule_class%>
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
describe "new" do
|
245
|
+
it "show the new form class" do
|
246
|
+
get :new, :rule_class_name => "RulesEngine::Rule::<%=rule_class%>"
|
247
|
+
response.should have_tag("form#re_rule_new_form") do
|
248
|
+
with_tag("input#<%=rule_name%>_title")
|
249
|
+
with_tag("input#<%=rule_name%>_message")
|
250
|
+
with_tag("input#<%=rule_name%>_plan")
|
251
|
+
end
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
describe "edit" do
|
256
|
+
it "show the edit form" do
|
257
|
+
re_rule = ReRule.make(:re_workflow_id => @re_workflow.id,
|
258
|
+
:rule_class_name => "RulesEngine::Rule::<%=rule_class%>",
|
259
|
+
:data => valid_<%=rule_name%>_rule_data)
|
260
|
+
ReRule.stub!(:find).and_return(re_rule)
|
261
|
+
|
262
|
+
get :edit, :re_workflow_id => @re_workflow.id, :re_rule_id => 1001, :rule_class_name => "RulesEngine::Rule::<%=rule_class%>"
|
263
|
+
response.should have_tag("form#re_rule_edit_form") do
|
264
|
+
with_tag("input#<%=rule_name%>_title", :value => 'Rule Title')
|
265
|
+
with_tag("input#<%=rule_name%>_message", :value => 'Twitter Message to Find')
|
266
|
+
with_tag("input#<%=rule_name%>_plan", :value => 'Other Plan')
|
267
|
+
end
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
end
|
272
|
+
|
@@ -0,0 +1,223 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
def valid_<%=rule_name%>_rule_data
|
4
|
+
'["Rule Title", "Other Pipeline"]'
|
5
|
+
end
|
6
|
+
|
7
|
+
|
8
|
+
describe RulesEngine::Rule::<%=rule_class%> do
|
9
|
+
|
10
|
+
def valid_attributes
|
11
|
+
{
|
12
|
+
:<%=rule_name%>_title => 'Rule Title',
|
13
|
+
:<%=rule_name%>_workflow => 'Next Workflow'
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should be discoverable" do
|
18
|
+
RulesEngine::Discovery.rule_class("RulesEngine::Rule::<%=rule_class%>").should == RulesEngine::Rule::<%=rule_class%>
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "the expected class options" do
|
22
|
+
it "should be in the 'General' group" do
|
23
|
+
RulesEngine::Rule::<%=rule_class%>.options[:group].should == "Workflow"
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should have the diplay name of '<%=rule_class%> Rule'" do
|
27
|
+
RulesEngine::Rule::<%=rule_class%>.options[:display_name].should == "Workflow Start"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should have the help template of '/re_rule_definitions/<%=rule_name%>/help'" do
|
31
|
+
RulesEngine::Rule::<%=rule_class%>.options[:help_partial].should == '/re_rule_definitions/<%=rule_name%>/help'
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should have the new template of '/re_rule_definitions/<%=rule_name%>/new'" do
|
35
|
+
RulesEngine::Rule::<%=rule_class%>.options[:new_partial].should == '/re_rule_definitions/<%=rule_name%>/new'
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should have the edit view partial template of '/re_rule_definitions/<%=rule_name%>/edit'" do
|
39
|
+
RulesEngine::Rule::<%=rule_class%>.options[:edit_partial].should == '/re_rule_definitions/<%=rule_name%>/edit'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "setting the rule data" do
|
44
|
+
before(:each) do
|
45
|
+
@<%=rule_name%> = RulesEngine::Rule::<%=rule_class%>.new
|
46
|
+
@<%=rule_name%>.data = valid_<%=rule_name%>_rule_data
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "the json data is valid" do
|
50
|
+
it "should be valid" do
|
51
|
+
@<%=rule_name%>.should be_valid
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should set the title" do
|
55
|
+
@<%=rule_name%>.title.should == "Rule Title"
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should set the workflow" do
|
59
|
+
@<%=rule_name%>.workflow.should == "Other Pipeline"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "the data is nil" do
|
64
|
+
it "should set the title to nil" do
|
65
|
+
@<%=rule_name%>.title.should_not be_nil
|
66
|
+
@<%=rule_name%>.data = nil
|
67
|
+
@<%=rule_name%>.title.should be_nil
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should set the 'workflow' to nil" do
|
71
|
+
@<%=rule_name%>.workflow.should_not be_nil
|
72
|
+
@<%=rule_name%>.data = nil
|
73
|
+
@<%=rule_name%>.workflow.should be_nil
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "the summary" do
|
79
|
+
it "should show the workflow to start" do
|
80
|
+
<%=rule_name%> = RulesEngine::Rule::<%=rule_class%>.new
|
81
|
+
<%=rule_name%>.stub!(:workflow).and_return("mock")
|
82
|
+
<%=rule_name%>.summary.should == "Start the workflow : mock"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "the data" do
|
87
|
+
it "should be converted to a json string" do
|
88
|
+
<%=rule_name%> = RulesEngine::Rule::<%=rule_class%>.new
|
89
|
+
<%=rule_name%>.should_receive(:title).and_return("mock title")
|
90
|
+
<%=rule_name%>.should_receive(:workflow).and_return("workflow")
|
91
|
+
<%=rule_name%>.data.should == '["mock title","workflow"]'
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe "the expected_outcomes" do
|
96
|
+
it "should be start workflow" do
|
97
|
+
<%=rule_name%> = RulesEngine::Rule::<%=rule_class%>.new
|
98
|
+
<%=rule_name%>.should_receive(:workflow).and_return('mock workflow')
|
99
|
+
<%=rule_name%>.expected_outcomes.should == [:outcome => RulesEngine::Rule::Outcome::START_WORKFLOW, :workflow_code => "mock workflow"]
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
describe "setting the rule attributes" do
|
104
|
+
before(:each) do
|
105
|
+
@<%=rule_name%> = RulesEngine::Rule::<%=rule_class%>.new
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should be valid with valid attributes" do
|
109
|
+
@<%=rule_name%>.attributes = valid_attributes
|
110
|
+
@<%=rule_name%>.should be_valid
|
111
|
+
end
|
112
|
+
|
113
|
+
describe "setting the <%=rule_name%>_title" do
|
114
|
+
it "should set the title" do
|
115
|
+
@<%=rule_name%>.attributes = valid_attributes
|
116
|
+
@<%=rule_name%>.title.should == 'Rule Title'
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should not be valid if the '<%=rule_name%>_title' attribute is missing" do
|
120
|
+
@<%=rule_name%>.attributes = valid_attributes.except(:<%=rule_name%>_title)
|
121
|
+
@<%=rule_name%>.should_not be_valid
|
122
|
+
@<%=rule_name%>.errors.should include(:<%=rule_name%>_title)
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should not be valid if the '<%=rule_name%>_title' attribute is blank" do
|
126
|
+
@<%=rule_name%>.attributes = valid_attributes.merge(:<%=rule_name%>_title => "")
|
127
|
+
@<%=rule_name%>.should_not be_valid
|
128
|
+
@<%=rule_name%>.errors.should include(:<%=rule_name%>_title)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
describe "setting the <%=rule_name%>_title" do
|
133
|
+
it "should be valid with valid '<%=rule_name%>_workflow'" do
|
134
|
+
@<%=rule_name%>.attributes = valid_attributes
|
135
|
+
@<%=rule_name%>.should be_valid
|
136
|
+
@<%=rule_name%>.workflow.should == 'Next Workflow'
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should not be valid if the '<%=rule_name%>_workflow' attribute is missing" do
|
140
|
+
@<%=rule_name%>.attributes = valid_attributes.except(:<%=rule_name%>_workflow)
|
141
|
+
@<%=rule_name%>.should_not be_valid
|
142
|
+
@<%=rule_name%>.errors.should include(:<%=rule_name%>_workflow)
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should not be valid if the '<%=rule_name%>_workflow' attribute is blank" do
|
146
|
+
@<%=rule_name%>.attributes = valid_attributes.merge(:<%=rule_name%>_workflow => "")
|
147
|
+
@<%=rule_name%>.should_not be_valid
|
148
|
+
@<%=rule_name%>.errors.should include(:<%=rule_name%>_workflow)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
describe "after a rule is created" do
|
154
|
+
# xit "There is nothing to do here"
|
155
|
+
end
|
156
|
+
|
157
|
+
describe "after a rule is created" do
|
158
|
+
# xit "There is nothing to do here"
|
159
|
+
end
|
160
|
+
|
161
|
+
describe "processing the rule" do
|
162
|
+
before(:each) do
|
163
|
+
@<%=rule_name%> = RulesEngine::Rule::<%=rule_class%>.new
|
164
|
+
end
|
165
|
+
|
166
|
+
it "should return start workflow with the workflow_code" do
|
167
|
+
@<%=rule_name%>.should_receive(:workflow).and_return('mock_workflow')
|
168
|
+
<%=rule_name%>_outcome = @<%=rule_name%>.process(1001, {})
|
169
|
+
<%=rule_name%>_outcome.outcome.should == RulesEngine::Rule::Outcome::START_WORKFLOW
|
170
|
+
<%=rule_name%>_outcome.workflow_code.should == "mock_workflow"
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
|
176
|
+
describe ReWorkflowRulesController, :type => :controller do
|
177
|
+
integrate_views
|
178
|
+
|
179
|
+
before(:each) do
|
180
|
+
controller.instance_eval { flash.stub!(:sweep) }
|
181
|
+
|
182
|
+
RulesEngine::Discovery.discover!
|
183
|
+
|
184
|
+
controller.stub!(:rules_engine_reader_access_required).and_return(true)
|
185
|
+
controller.stub!(:rules_engine_editor_access_required).and_return(true)
|
186
|
+
|
187
|
+
@re_workflow = ReWorkflow.make
|
188
|
+
ReWorkflow.stub!(:find).and_return(@re_workflow)
|
189
|
+
end
|
190
|
+
|
191
|
+
describe "help" do
|
192
|
+
it "should assign the <%=rule_name%> rule class" do
|
193
|
+
get :help, :rule_class_name => "RulesEngine::Rule::<%=rule_class%>"
|
194
|
+
assigns[:rule_class].should == RulesEngine::Rule::<%=rule_class%>
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
describe "new" do
|
199
|
+
it "show the new form class" do
|
200
|
+
get :new, :rule_class_name => "RulesEngine::Rule::<%=rule_class%>"
|
201
|
+
response.should have_tag("form#re_rule_new_form") do
|
202
|
+
with_tag("input#<%=rule_name%>_title")
|
203
|
+
with_tag("input#<%=rule_name%>_workflow")
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
describe "edit" do
|
209
|
+
it "show the edit form" do
|
210
|
+
re_rule = ReRule.make(:re_workflow_id => @re_workflow.id,
|
211
|
+
:rule_class_name => "RulesEngine::Rule::<%=rule_class%>",
|
212
|
+
:data => valid_<%=rule_name%>_rule_data)
|
213
|
+
ReRule.stub!(:find).and_return(re_rule)
|
214
|
+
|
215
|
+
get :edit, :re_workflow_id => @re_workflow.id, :re_rule_id => 1001, :rule_class_name => "RulesEngine::Rule::<%=rule_class%>"
|
216
|
+
response.should have_tag("form#re_rule_edit_form") do
|
217
|
+
with_tag("input#<%=rule_name%>_title", :value => 'Rule Title')
|
218
|
+
with_tag("input#<%=rule_name%>_workflow", :value => 'Next Workflow')
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
end
|