rules_engine 0.1.7 → 0.1.8
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/lib/rules_engine/process/runner.rb +81 -75
- data/lib/rules_engine/process/runner/db_runner.rb +2 -2
- data/lib/rules_engine/rule/definition.rb +1 -1
- data/lib/rules_engine_view/alerts.rb +3 -4
- data/lib/rules_engine_view/navigate.rb +2 -2
- data/rails_generators/manifests/complex.rb +6 -6
- data/rails_generators/manifests/complex.yml +6 -6
- data/rails_generators/manifests/simple.rb +5 -5
- data/rails_generators/manifests/simple.yml +5 -5
- data/rails_generators/templates/app/controllers/re_plans_controller.rb +2 -2
- data/rails_generators/templates/app/models/re_plan.rb +7 -2
- data/rails_generators/templates/app/models/re_workflow.rb +8 -1
- data/rails_generators/templates/app/rules/complex.rb +21 -21
- data/rails_generators/templates/app/rules/simple.rb +4 -4
- data/rails_generators/templates/app/views/re_plan_workflows/edit.js.erb +2 -0
- data/rails_generators/templates/app/views/re_plan_workflows/new.js.erb +2 -0
- data/rails_generators/templates/app/views/re_plans/_menu.html.erb +6 -8
- data/rails_generators/templates/app/views/re_plans/change.html.erb +1 -0
- data/rails_generators/templates/app/views/re_plans/edit.js.erb +2 -0
- data/rails_generators/templates/app/views/re_plans/new.js.erb +2 -0
- data/rails_generators/templates/app/views/re_rules/complex/_edit.html.erb +1 -0
- data/rails_generators/templates/app/views/{re_rule_definitions → re_rules}/complex/_form.html.erb +10 -10
- data/rails_generators/templates/app/views/{re_rule_definitions → re_rules}/complex/_form_word.html.erb +1 -1
- data/rails_generators/templates/app/views/{re_rule_definitions → re_rules}/complex/_help.html.erb +0 -0
- data/rails_generators/templates/app/views/re_rules/complex/_new.html.erb +1 -0
- data/rails_generators/templates/app/views/re_rules/simple/_edit.html.erb +1 -0
- data/rails_generators/templates/app/views/{re_rule_definitions → re_rules}/simple/_form.html.erb +0 -0
- data/rails_generators/templates/app/views/{re_rule_definitions → re_rules}/simple/_help.html.erb +0 -0
- data/rails_generators/templates/app/views/re_rules/simple/_new.html.erb +1 -0
- data/rails_generators/templates/app/views/re_workflows/edit.js.erb +2 -0
- data/rails_generators/templates/app/views/re_workflows/new.js.erb +3 -1
- data/rails_generators/templates/lib/tasks/rules_engine.rake +4 -4
- data/rails_generators/templates/public/javascripts/rules_engine/re_plan_change.js +13 -1
- data/rails_generators/templates/public/stylesheets/rules_engine/screen.css +2 -2
- data/rails_generators/templates/spec/controllers/re_plans_controller_spec.rb +0 -8
- data/rails_generators/templates/spec/lib/rules/complex_spec.rb +70 -69
- data/rails_generators/templates/spec/lib/rules/simple_spec.rb +8 -8
- data/rails_generators/templates/spec/models/re_plan_spec.rb +3 -3
- data/rails_generators/templates/spec/models/re_rule_spec.rb +14 -19
- data/rails_generators/templates/spec/models/re_workflow_spec.rb +9 -0
- data/spec/railsenv/log/debug.log +4050 -0
- data/spec/railsenv/log/test.log +592 -0
- data/spec/rules_engine/process/runner/db_runner_spec.rb +15 -16
- data/spec/rules_engine/process/runner_spec.rb +166 -113
- data/spec/rules_engine/rule/definition_spec.rb +2 -2
- metadata +13 -13
- data/rails_generators/templates/app/views/re_rule_definitions/complex/_edit.html.erb +0 -1
- data/rails_generators/templates/app/views/re_rule_definitions/complex/_new.html.erb +0 -1
- data/rails_generators/templates/app/views/re_rule_definitions/simple/_edit.html.erb +0 -1
- data/rails_generators/templates/app/views/re_rule_definitions/simple/_new.html.erb +0 -1
@@ -9,9 +9,9 @@ module RulesEngine
|
|
9
9
|
{
|
10
10
|
:group => 'General',
|
11
11
|
:display_name => 'Simple',
|
12
|
-
:help_partial => '/
|
13
|
-
:new_partial => '/
|
14
|
-
:edit_partial => '/
|
12
|
+
:help_partial => '/re_rules/<%=rule_name%>/help',
|
13
|
+
:new_partial => '/re_rules/<%=rule_name%>/new',
|
14
|
+
:edit_partial => '/re_rules/<%=rule_name%>/edit'
|
15
15
|
}
|
16
16
|
|
17
17
|
##################################################################
|
@@ -74,7 +74,7 @@ module RulesEngine
|
|
74
74
|
##################################################################
|
75
75
|
# execute the rule
|
76
76
|
# this rule does nothing
|
77
|
-
def process(process_id, data)
|
77
|
+
def process(process_id, plan, data)
|
78
78
|
RulesEngine::Process.auditor.audit(process_id, "Inside Rule #{title}", RulesEngine::Process::AUDIT_INFO)
|
79
79
|
# RulesEngine::Rule::Outcome.new(RulesEngine::Rule::Outcome::STOP_SUCCESS)
|
80
80
|
# RulesEngine::Rule::Outcome.new(RulesEngine::Rule::Outcome::STOP_FAILURE)
|
@@ -1,14 +1,12 @@
|
|
1
1
|
<% plan_status = @re_plan.plan_status %>
|
2
2
|
|
3
|
-
<% if plan_status == RePlan::PLAN_STATUS_DRAFT
|
3
|
+
<% if plan_status == RePlan::PLAN_STATUS_DRAFT || plan_status == RePlan::PLAN_STATUS_CHANGED %>
|
4
4
|
<h4>
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
<%
|
10
|
-
<h4>
|
11
|
-
<%= link_to("Publish Changes", "##{@re_plan.id}", :id => "re_plan_publish", :class => "re-menu-plan-publish") %>
|
5
|
+
<% if @re_plan.plan_error %>
|
6
|
+
<%= link_to("Publish Plan", "##{@re_plan.id}", :id => "re_plan_publish_with_errors", :class => "re-menu-plan-publish") %>
|
7
|
+
<% else %>
|
8
|
+
<%= link_to("Publish Plan", "##{@re_plan.id}", :id => "re_plan_publish", :class => "re-menu-plan-publish") %>
|
9
|
+
<% end %>
|
12
10
|
</h4>
|
13
11
|
<div class="clear top-5"></div>
|
14
12
|
<% end %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%%= render '/re_rules/<%=rule_name%>/form', :f => f %>
|
data/rails_generators/templates/app/views/{re_rule_definitions → re_rules}/complex/_form.html.erb
RENAMED
@@ -1,14 +1,14 @@
|
|
1
1
|
<%% javascript_tag do %>
|
2
|
-
var new_<%=rule_name%> = '<%%=escape_javascript(render("/
|
2
|
+
var new_<%=rule_name%> = '<%%=escape_javascript(render("/re_rules/<%=rule_name%>/form_word"))%>'
|
3
3
|
|
4
4
|
var update<%=rule_class%>WorkflowAction = function() {
|
5
5
|
if ($('#<%=rule_name%>_workflow_action').attr('value') == "start_workflow")
|
6
6
|
{
|
7
|
-
$('#<%=rule_name%>
|
8
|
-
$('#<%=rule_name%>
|
7
|
+
$('#<%=rule_name%>_workflow_code').re_form_enable();
|
8
|
+
$('#<%=rule_name%>_workflow_code').removeAttr("disabled");
|
9
9
|
} else {
|
10
|
-
$('#<%=rule_name%>
|
11
|
-
$('#<%=rule_name%>
|
10
|
+
$('#<%=rule_name%>_workflow_code').re_form_disable();
|
11
|
+
$('#<%=rule_name%>_workflow_code').attr("disabled", true);
|
12
12
|
}
|
13
13
|
}
|
14
14
|
|
@@ -35,15 +35,15 @@
|
|
35
35
|
|
36
36
|
<!-- WORDS -->
|
37
37
|
<%% position = 0 %>
|
38
|
-
<%% (@re_rule.rule.
|
38
|
+
<%% (@re_rule.rule.match_words || []).each do | word | %>
|
39
39
|
<%% f.fields_for :rule_data, {:first => false} do |frd| %>
|
40
|
-
<%%= render '/
|
40
|
+
<%%= render '/re_rules/<%=rule_name%>/form_word', :f => frd, :position => position, :word => word %>
|
41
41
|
<%% position += 1 %>
|
42
42
|
<%% end %>
|
43
43
|
<%% end %>
|
44
44
|
<%% if position == 0 %>
|
45
45
|
<%% f.fields_for :rule_data, {:first => false} do |frd| %>
|
46
|
-
<%%= render '/
|
46
|
+
<%%= render '/re_rules/<%=rule_name%>/form_word', :f => frd, :position => position %>
|
47
47
|
<%% end %>
|
48
48
|
<%% end %>
|
49
49
|
|
@@ -67,10 +67,10 @@
|
|
67
67
|
:required => true %>
|
68
68
|
</div>
|
69
69
|
<div class="prepend-1 span-7 last">
|
70
|
-
<%%= re_text_field "Workflow Code", "<%=rule_name%>
|
70
|
+
<%%= re_text_field "Workflow Code", "<%=rule_name%>_workflow_code", @re_rule.rule.workflow_code || params[:<%=rule_name%>_workflow_code],
|
71
71
|
:size => 20,
|
72
72
|
:required => true,
|
73
73
|
:span => '3x5',
|
74
|
-
:error => @re_rule.rule.errors[:<%=rule_name%>
|
74
|
+
:error => @re_rule.rule.errors[:<%=rule_name%>_workflow_code] %>
|
75
75
|
</div>
|
76
76
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<%% id = local_assigns[:position] ? position : 'NEW_RECORD' %>
|
2
2
|
|
3
3
|
<div id="<%=rule_name%>_<%%=id%>">
|
4
|
-
<%%= re_text_field "Words to match", "<%=rule_name%>
|
4
|
+
<%%= re_text_field "Words to match", "<%=rule_name%>_match_words[#{id}][word]",
|
5
5
|
local_assigns[:word] ? word : '',
|
6
6
|
:size => 25,
|
7
7
|
:required => id == 0,
|
data/rails_generators/templates/app/views/{re_rule_definitions → re_rules}/complex/_help.html.erb
RENAMED
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
<%%= render '/re_rules/<%=rule_name%>/form', :f => f %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%%= render '/re_rules/<%=rule_name%>/form' %>
|
data/rails_generators/templates/app/views/{re_rule_definitions → re_rules}/simple/_form.html.erb
RENAMED
File without changes
|
data/rails_generators/templates/app/views/{re_rule_definitions → re_rules}/simple/_help.html.erb
RENAMED
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
<%%= render '/re_rules/<%=rule_name%>/form' %>
|
@@ -2,4 +2,6 @@ $('#re_content').html('<%=escape_javascript(render('/re_workflows/new', :create_
|
|
2
2
|
|
3
3
|
$('#re_workflow_new_insert').closest('div.re-form-button').re_form_button();
|
4
4
|
|
5
|
-
$("#re_workflow_new_form").submit(function() { return false; });
|
5
|
+
$("#re_workflow_new_form").submit(function() { return false; });
|
6
|
+
|
7
|
+
$('#re_workflow_code').focus();
|
@@ -15,19 +15,19 @@ task :rules_engine do
|
|
15
15
|
|
16
16
|
RulesEngine::Publish.publisher = :db_publisher
|
17
17
|
RulesEngine::Process.runner = :db_runner
|
18
|
-
|
19
|
-
|
18
|
+
RulesEngine::Process.auditor = :db_auditor
|
19
|
+
RulesEngine::Process.auditor.audit_level = RulesEngine::Process::AUDIT_INFO
|
20
20
|
RulesEngine::Discovery.rules_path = File.expand_path(File.join(File.dirname(__FILE__), '/../../app/rules'))
|
21
21
|
RulesEngine::Discovery.discover!
|
22
22
|
|
23
23
|
plan = RulesEngine::Publish.publisher.get(ENV['re_plan'])
|
24
24
|
if plan.nil?
|
25
|
-
raise "published plan \"ENV['re_plan']\" not found"
|
25
|
+
raise "published plan \"#{ENV['re_plan']}\" not found"
|
26
26
|
end
|
27
27
|
|
28
28
|
data = ENV.inject({}){ |data, value| data[value[0].sub(/^re_/, '').to_sym] = value[1] if value[0] =~ /^re_/; data }
|
29
29
|
process_id = RulesEngine::Process.runner.create
|
30
|
-
success = RulesEngine::Process.runner.
|
30
|
+
success = RulesEngine::Process.runner.run_plan(process_id, plan, data)
|
31
31
|
|
32
32
|
# process = RulesEngine::Process.open(process.re_process.id)
|
33
33
|
|
@@ -50,7 +50,19 @@ $(document).ready(function() {
|
|
50
50
|
return false;
|
51
51
|
});
|
52
52
|
|
53
|
-
$('a#re_plan_publish').live('click', function() {
|
53
|
+
$('a#re_plan_publish').live('click', function() {
|
54
|
+
$('#re_plan_publish_warning').html('');
|
55
|
+
$('#re_plan_publish_form #tag').attr('value', '')
|
56
|
+
$('#re_plan_publish_tag').attr('value', '')
|
57
|
+
$('#re_plan_publish_tag').re_form_valid();
|
58
|
+
$('#re_plan_publish_tag').closest('#re_plan_publish_confirm').find('.form-error-message').remove();
|
59
|
+
$.fancybox({ 'href': '#re_plan_publish_confirm' });
|
60
|
+
|
61
|
+
return false;
|
62
|
+
});
|
63
|
+
|
64
|
+
$('a#re_plan_publish_with_errors').live('click', function() {
|
65
|
+
$('#re_plan_publish_warning').html('Warning! The plan you are publishing has errors!');
|
54
66
|
$('#re_plan_publish_form #tag').attr('value', '')
|
55
67
|
$('#re_plan_publish_tag').attr('value', '')
|
56
68
|
$('#re_plan_publish_tag').re_form_valid();
|
@@ -237,14 +237,6 @@ describe RePlansController do
|
|
237
237
|
RePlan.stub!(:find).and_return(@re_plan)
|
238
238
|
end
|
239
239
|
|
240
|
-
describe "plan has errors" do
|
241
|
-
it "should display a flash error message" do
|
242
|
-
@re_plan.should_receive(:plan_error).and_return('error')
|
243
|
-
put :publish, :id => 123, :tag => "publish tag"
|
244
|
-
flash[:error].should_not be_blank
|
245
|
-
end
|
246
|
-
end
|
247
|
-
|
248
240
|
describe "tag is blank" do
|
249
241
|
it "should display a flash error message" do
|
250
242
|
put :publish, :id => 123, :tag => ""
|
@@ -9,7 +9,7 @@ describe RulesEngine::Rule::<%=rule_class%> do
|
|
9
9
|
def valid_attributes
|
10
10
|
{
|
11
11
|
:<%=rule_name%>_title => 'Another Title',
|
12
|
-
:<%=rule_name%>
|
12
|
+
:<%=rule_name%>_match_words => {
|
13
13
|
"1" => { "word" => 'first word' },
|
14
14
|
"2" => { "word" => 'second word' }
|
15
15
|
}
|
@@ -29,16 +29,16 @@ describe RulesEngine::Rule::<%=rule_class%> do
|
|
29
29
|
RulesEngine::Rule::<%=rule_class%>.options[:display_name].should == "<%=rule_class%>"
|
30
30
|
end
|
31
31
|
|
32
|
-
it "should have the help template of '/
|
33
|
-
RulesEngine::Rule::<%=rule_class%>.options[:help_partial].should == '/
|
32
|
+
it "should have the help template of '/re_rules/<%=rule_name%>/help'" do
|
33
|
+
RulesEngine::Rule::<%=rule_class%>.options[:help_partial].should == '/re_rules/<%=rule_name%>/help'
|
34
34
|
end
|
35
35
|
|
36
|
-
it "should have the new template of '/
|
37
|
-
RulesEngine::Rule::<%=rule_class%>.options[:new_partial].should == '/
|
36
|
+
it "should have the new template of '/re_rules/<%=rule_name%>/new'" do
|
37
|
+
RulesEngine::Rule::<%=rule_class%>.options[:new_partial].should == '/re_rules/<%=rule_name%>/new'
|
38
38
|
end
|
39
39
|
|
40
|
-
it "should have the edit view partial template of '/
|
41
|
-
RulesEngine::Rule::<%=rule_class%>.options[:edit_partial].should == '/
|
40
|
+
it "should have the edit view partial template of '/re_rules/<%=rule_name%>/edit'" do
|
41
|
+
RulesEngine::Rule::<%=rule_class%>.options[:edit_partial].should == '/re_rules/<%=rule_name%>/edit'
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -57,8 +57,8 @@ describe RulesEngine::Rule::<%=rule_class%> do
|
|
57
57
|
@<%=rule_name%>.title.should == "Rule Title"
|
58
58
|
end
|
59
59
|
|
60
|
-
it "should set the
|
61
|
-
@<%=rule_name%>.
|
60
|
+
it "should set the match_words" do
|
61
|
+
@<%=rule_name%>.match_words.should == ["word one", "word two"]
|
62
62
|
end
|
63
63
|
|
64
64
|
it "should set the workflow_action" do
|
@@ -66,7 +66,7 @@ describe RulesEngine::Rule::<%=rule_class%> do
|
|
66
66
|
end
|
67
67
|
|
68
68
|
it "should set the workflow" do
|
69
|
-
@<%=rule_name%>.
|
69
|
+
@<%=rule_name%>.workflow_code.should == "Other Workflow"
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
@@ -77,10 +77,10 @@ describe RulesEngine::Rule::<%=rule_class%> do
|
|
77
77
|
@<%=rule_name%>.title.should be_nil
|
78
78
|
end
|
79
79
|
|
80
|
-
it "should set the
|
81
|
-
@<%=rule_name%>.
|
80
|
+
it "should set the match_words to nil" do
|
81
|
+
@<%=rule_name%>.match_words.should_not be_nil
|
82
82
|
@<%=rule_name%>.data = nil
|
83
|
-
@<%=rule_name%>.
|
83
|
+
@<%=rule_name%>.match_words.should be_nil
|
84
84
|
end
|
85
85
|
|
86
86
|
it "should se the workflow action to 'continue'" do
|
@@ -90,23 +90,23 @@ describe RulesEngine::Rule::<%=rule_class%> do
|
|
90
90
|
end
|
91
91
|
|
92
92
|
it "should set the 'workflow' to nil" do
|
93
|
-
@<%=rule_name%>.
|
93
|
+
@<%=rule_name%>.workflow_code.should_not be_nil
|
94
94
|
@<%=rule_name%>.data = nil
|
95
|
-
@<%=rule_name%>.
|
95
|
+
@<%=rule_name%>.workflow_code.should be_nil
|
96
96
|
end
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
100
100
|
describe "the summary" do
|
101
|
-
it "should be singluar if there is one
|
101
|
+
it "should be singluar if there is one match_word" do
|
102
102
|
<%=rule_name%> = RulesEngine::Rule::<%=rule_class%>.new
|
103
|
-
<%=rule_name%>.stub!(:
|
103
|
+
<%=rule_name%>.stub!(:match_words).and_return(["one"])
|
104
104
|
<%=rule_name%>.summary.should == "Match the word one"
|
105
105
|
end
|
106
106
|
|
107
|
-
it "should be plural if there are multiple
|
107
|
+
it "should be plural if there are multiple match_words" do
|
108
108
|
<%=rule_name%> = RulesEngine::Rule::<%=rule_class%>.new
|
109
|
-
<%=rule_name%>.stub!(:
|
109
|
+
<%=rule_name%>.stub!(:match_words).and_return(["one", "two", "three"])
|
110
110
|
<%=rule_name%>.summary.should == "Match the words one, two, three"
|
111
111
|
end
|
112
112
|
end
|
@@ -115,9 +115,9 @@ describe RulesEngine::Rule::<%=rule_class%> do
|
|
115
115
|
it "should be converted to a json string" do
|
116
116
|
<%=rule_name%> = RulesEngine::Rule::<%=rule_class%>.new
|
117
117
|
<%=rule_name%>.should_receive(:title).and_return("mock title")
|
118
|
-
<%=rule_name%>.should_receive(:
|
118
|
+
<%=rule_name%>.should_receive(:match_words).and_return(["one", "two"])
|
119
119
|
<%=rule_name%>.should_receive(:workflow_action).and_return("workflow action")
|
120
|
-
<%=rule_name%>.should_receive(:
|
120
|
+
<%=rule_name%>.should_receive(:workflow_code).and_return("workflow")
|
121
121
|
<%=rule_name%>.data.should == '["mock title",["one","two"],"workflow action","workflow"]'
|
122
122
|
end
|
123
123
|
end
|
@@ -125,32 +125,33 @@ describe RulesEngine::Rule::<%=rule_class%> do
|
|
125
125
|
describe "the expected_outcomes" do
|
126
126
|
it "should be next" do
|
127
127
|
<%=rule_name%> = RulesEngine::Rule::<%=rule_class%>.new
|
128
|
-
<%=rule_name%>.
|
129
|
-
<%=rule_name%>.expected_outcomes.should ==
|
128
|
+
<%=rule_name%>.stub!(:workflow_action).and_return('next')
|
129
|
+
<%=rule_name%>.expected_outcomes[0][:outcome].should == RulesEngine::Rule::Outcome::NEXT
|
130
130
|
end
|
131
131
|
|
132
132
|
it "should be stop success" do
|
133
133
|
<%=rule_name%> = RulesEngine::Rule::<%=rule_class%>.new
|
134
|
-
<%=rule_name%>.
|
135
|
-
<%=rule_name%>.expected_outcomes.should ==
|
134
|
+
<%=rule_name%>.stub!(:workflow_action).and_return('stop_success')
|
135
|
+
<%=rule_name%>.expected_outcomes[0][:outcome].should == RulesEngine::Rule::Outcome::STOP_SUCCESS
|
136
136
|
end
|
137
137
|
|
138
138
|
it "should be stop failure" do
|
139
139
|
<%=rule_name%> = RulesEngine::Rule::<%=rule_class%>.new
|
140
|
-
<%=rule_name%>.
|
141
|
-
<%=rule_name%>.expected_outcomes.should ==
|
140
|
+
<%=rule_name%>.stub!(:workflow_action).and_return('stop_failure')
|
141
|
+
<%=rule_name%>.expected_outcomes[0][:outcome].should == RulesEngine::Rule::Outcome::STOP_FAILURE
|
142
142
|
end
|
143
143
|
|
144
144
|
it "should be start workflow" do
|
145
145
|
<%=rule_name%> = RulesEngine::Rule::<%=rule_class%>.new
|
146
|
-
<%=rule_name%>.
|
147
|
-
<%=rule_name%>.
|
148
|
-
<%=rule_name%>.expected_outcomes.should ==
|
146
|
+
<%=rule_name%>.stub!(:workflow_action).and_return('start_workflow')
|
147
|
+
<%=rule_name%>.stub!(:workflow_code).and_return('workflow_code')
|
148
|
+
<%=rule_name%>.expected_outcomes[0][:outcome].should == RulesEngine::Rule::Outcome::START_WORKFLOW
|
149
|
+
<%=rule_name%>.expected_outcomes[0][:title].should == "Start Workflow : workflow_code"
|
149
150
|
end
|
150
151
|
|
151
152
|
it "should be next be default" do
|
152
153
|
<%=rule_name%> = RulesEngine::Rule::<%=rule_class%>.new
|
153
|
-
<%=rule_name%>.
|
154
|
+
<%=rule_name%>.stub!(:workflow_action).and_return('this is not valid')
|
154
155
|
<%=rule_name%>.expected_outcomes.should == [:outcome => RulesEngine::Rule::Outcome::NEXT]
|
155
156
|
end
|
156
157
|
|
@@ -185,38 +186,38 @@ describe RulesEngine::Rule::<%=rule_class%> do
|
|
185
186
|
end
|
186
187
|
end
|
187
188
|
|
188
|
-
describe "setting the <%=rule_name%>
|
189
|
-
it "should set the
|
189
|
+
describe "setting the <%=rule_name%>_match_words" do
|
190
|
+
it "should set the match_words" do
|
190
191
|
@<%=rule_name%>.attributes = valid_attributes
|
191
|
-
@<%=rule_name%>.
|
192
|
+
@<%=rule_name%>.match_words.should == ['first word', 'second word']
|
192
193
|
end
|
193
194
|
|
194
|
-
it "should not be valid if the '<%=rule_name%>
|
195
|
-
@<%=rule_name%>.attributes = valid_attributes.except(:<%=rule_name%>
|
195
|
+
it "should not be valid if the '<%=rule_name%>_match_words' attribute is missing" do
|
196
|
+
@<%=rule_name%>.attributes = valid_attributes.except(:<%=rule_name%>_match_words)
|
196
197
|
@<%=rule_name%>.should_not be_valid
|
197
|
-
@<%=rule_name%>.errors.should include(:<%=rule_name%>
|
198
|
+
@<%=rule_name%>.errors.should include(:<%=rule_name%>_match_words)
|
198
199
|
end
|
199
200
|
|
200
|
-
it "should not be valid if the '<%=rule_name%>
|
201
|
-
@<%=rule_name%>.attributes = valid_attributes.merge(:<%=rule_name%>
|
201
|
+
it "should not be valid if the '<%=rule_name%>_match_words' is not a hash" do
|
202
|
+
@<%=rule_name%>.attributes = valid_attributes.merge(:<%=rule_name%>_match_words => "<%=rule_name%> word")
|
202
203
|
@<%=rule_name%>.should_not be_valid
|
203
|
-
@<%=rule_name%>.errors.should include(:<%=rule_name%>
|
204
|
+
@<%=rule_name%>.errors.should include(:<%=rule_name%>_match_words)
|
204
205
|
end
|
205
206
|
|
206
|
-
it "should not be valid if the '<%=rule_name%>
|
207
|
-
@<%=rule_name%>.attributes = valid_attributes.merge(:<%=rule_name%>
|
207
|
+
it "should not be valid if the '<%=rule_name%>_match_words' is empty" do
|
208
|
+
@<%=rule_name%>.attributes = valid_attributes.merge(:<%=rule_name%>_match_words => {})
|
208
209
|
@<%=rule_name%>.should_not be_valid
|
209
|
-
@<%=rule_name%>.errors.should include(:<%=rule_name%>
|
210
|
+
@<%=rule_name%>.errors.should include(:<%=rule_name%>_match_words)
|
210
211
|
end
|
211
212
|
|
212
213
|
it "should not include parameters that are marked for deletion" do
|
213
|
-
@<%=rule_name%>.attributes = valid_attributes.merge(:<%=rule_name%>
|
214
|
+
@<%=rule_name%>.attributes = valid_attributes.merge(:<%=rule_name%>_match_words => {
|
214
215
|
"1" => { "word" => 'first word', "_delete" => '1' },
|
215
216
|
"2" => { "word" => 'second word' }
|
216
217
|
}
|
217
218
|
)
|
218
219
|
@<%=rule_name%>.should be_valid
|
219
|
-
@<%=rule_name%>.
|
220
|
+
@<%=rule_name%>.match_words.should == ['second word']
|
220
221
|
end
|
221
222
|
|
222
223
|
end
|
@@ -234,29 +235,29 @@ describe RulesEngine::Rule::<%=rule_class%> do
|
|
234
235
|
@<%=rule_name%>.workflow_action.should == 'continue'
|
235
236
|
end
|
236
237
|
|
237
|
-
it "should set the
|
238
|
-
@<%=rule_name%>.attributes = valid_attributes.merge(:<%=rule_name%>
|
238
|
+
it "should set the workflow_code" do
|
239
|
+
@<%=rule_name%>.attributes = valid_attributes.merge(:<%=rule_name%>_workflow_code => "mock workflow")
|
239
240
|
@<%=rule_name%>.should be_valid
|
240
|
-
@<%=rule_name%>.
|
241
|
+
@<%=rule_name%>.workflow_code.should == 'mock workflow'
|
241
242
|
end
|
242
243
|
|
243
244
|
describe "workflow action is start_workflow" do
|
244
245
|
it "should be valid with valid '<%=rule_name%>_workflow'" do
|
245
|
-
@<%=rule_name%>.attributes = valid_attributes.merge(:<%=rule_name%>_workflow_action => "start_workflow", :<%=rule_name%>
|
246
|
+
@<%=rule_name%>.attributes = valid_attributes.merge(:<%=rule_name%>_workflow_action => "start_workflow", :<%=rule_name%>_workflow_code => "mock workflow")
|
246
247
|
@<%=rule_name%>.should be_valid
|
247
|
-
@<%=rule_name%>.
|
248
|
+
@<%=rule_name%>.workflow_code.should == 'mock workflow'
|
248
249
|
end
|
249
250
|
|
250
251
|
it "should not be valid if the '<%=rule_name%>_workflow' attribute is missing" do
|
251
|
-
@<%=rule_name%>.attributes = valid_attributes.merge(:<%=rule_name%>_workflow_action => "start_workflow").except(:<%=rule_name%>
|
252
|
+
@<%=rule_name%>.attributes = valid_attributes.merge(:<%=rule_name%>_workflow_action => "start_workflow").except(:<%=rule_name%>_workflow_code)
|
252
253
|
@<%=rule_name%>.should_not be_valid
|
253
|
-
@<%=rule_name%>.errors.should include(:<%=rule_name%>
|
254
|
+
@<%=rule_name%>.errors.should include(:<%=rule_name%>_workflow_code)
|
254
255
|
end
|
255
256
|
|
256
257
|
it "should not be valid if the '<%=rule_name%>_workflow' attribute is blank" do
|
257
|
-
@<%=rule_name%>.attributes = valid_attributes.merge(:<%=rule_name%>_workflow_action => "start_workflow", :<%=rule_name%>
|
258
|
+
@<%=rule_name%>.attributes = valid_attributes.merge(:<%=rule_name%>_workflow_action => "start_workflow", :<%=rule_name%>_workflow_code => "")
|
258
259
|
@<%=rule_name%>.should_not be_valid
|
259
|
-
@<%=rule_name%>.errors.should include(:<%=rule_name%>
|
260
|
+
@<%=rule_name%>.errors.should include(:<%=rule_name%>_workflow_code)
|
260
261
|
end
|
261
262
|
end
|
262
263
|
end
|
@@ -277,15 +278,15 @@ describe RulesEngine::Rule::<%=rule_class%> do
|
|
277
278
|
describe "processing the rule" do
|
278
279
|
before(:each) do
|
279
280
|
@<%=rule_name%> = RulesEngine::Rule::<%=rule_class%>.new
|
280
|
-
@<%=rule_name%>.stub!(:
|
281
|
+
@<%=rule_name%>.stub!(:match_words).and_return(["found", "word"])
|
281
282
|
end
|
282
283
|
|
283
284
|
it "should do nothing if there is no tweet" do
|
284
|
-
@<%=rule_name%>.process(1001, {}).outcome.should == RulesEngine::Rule::Outcome::NEXT
|
285
|
+
@<%=rule_name%>.process(1001, {:plan => "plan"}, {:data => "data"}).outcome.should == RulesEngine::Rule::Outcome::NEXT
|
285
286
|
end
|
286
287
|
|
287
288
|
it "should do nothing if there is no match" do
|
288
|
-
@<%=rule_name%>.process(@job, {:tweet => "not here"}).outcome.should == RulesEngine::Rule::Outcome::NEXT
|
289
|
+
@<%=rule_name%>.process(@job, {:plan => "plan"}, {:tweet => "not here"}).outcome.should == RulesEngine::Rule::Outcome::NEXT
|
289
290
|
end
|
290
291
|
|
291
292
|
describe "a match found" do
|
@@ -294,7 +295,7 @@ describe RulesEngine::Rule::<%=rule_class%> do
|
|
294
295
|
end
|
295
296
|
|
296
297
|
it "should add the match to the data" do
|
297
|
-
@<%=rule_name%>.process(@job, @matched_data)
|
298
|
+
@<%=rule_name%>.process(@job, {:plan => "plan"}, @matched_data)
|
298
299
|
@matched_data[:tweet_match].should == "word"
|
299
300
|
end
|
300
301
|
|
@@ -303,29 +304,29 @@ describe RulesEngine::Rule::<%=rule_class%> do
|
|
303
304
|
process_id.should == 1001
|
304
305
|
message.should =~ /word$/
|
305
306
|
end
|
306
|
-
@<%=rule_name%>.process(1001, @matched_data)
|
307
|
+
@<%=rule_name%>.process(1001, {:plan => "plan"}, @matched_data)
|
307
308
|
end
|
308
309
|
|
309
310
|
describe "matching workflow actions" do
|
310
311
|
it "should return next" do
|
311
312
|
@<%=rule_name%>.should_receive(:workflow_action).and_return('next')
|
312
|
-
@<%=rule_name%>.process(1001, @matched_data).outcome.should == RulesEngine::Rule::Outcome::NEXT
|
313
|
+
@<%=rule_name%>.process(1001, {:plan => "plan"}, @matched_data).outcome.should == RulesEngine::Rule::Outcome::NEXT
|
313
314
|
end
|
314
315
|
|
315
316
|
it "should return stop_success" do
|
316
317
|
@<%=rule_name%>.should_receive(:workflow_action).and_return('stop_success')
|
317
|
-
@<%=rule_name%>.process(1001, @matched_data).outcome.should == RulesEngine::Rule::Outcome::STOP_SUCCESS
|
318
|
+
@<%=rule_name%>.process(1001, {:plan => "plan"}, @matched_data).outcome.should == RulesEngine::Rule::Outcome::STOP_SUCCESS
|
318
319
|
end
|
319
320
|
|
320
321
|
it "should return stop_failure" do
|
321
322
|
@<%=rule_name%>.should_receive(:workflow_action).and_return('stop_failure')
|
322
|
-
@<%=rule_name%>.process(1001, @matched_data).outcome.should == RulesEngine::Rule::Outcome::STOP_FAILURE
|
323
|
+
@<%=rule_name%>.process(1001, {:plan => "plan"}, @matched_data).outcome.should == RulesEngine::Rule::Outcome::STOP_FAILURE
|
323
324
|
end
|
324
325
|
|
325
326
|
it "should return start workflow with the workflow_code" do
|
326
327
|
@<%=rule_name%>.should_receive(:workflow_action).and_return('start_workflow')
|
327
|
-
@<%=rule_name%>.should_receive(:
|
328
|
-
<%=rule_name%>_outcome = @<%=rule_name%>.process(1001, @matched_data)
|
328
|
+
@<%=rule_name%>.should_receive(:workflow_code).and_return('mock_workflow')
|
329
|
+
<%=rule_name%>_outcome = @<%=rule_name%>.process(1001, {:plan => "plan"}, @matched_data)
|
329
330
|
<%=rule_name%>_outcome.outcome.should == RulesEngine::Rule::Outcome::START_WORKFLOW
|
330
331
|
<%=rule_name%>_outcome.workflow_code.should == "mock_workflow"
|
331
332
|
end
|
@@ -362,9 +363,9 @@ describe ReWorkflowRulesController, :type => :controller do
|
|
362
363
|
get :new, :rule_class_name => "RulesEngine::Rule::<%=rule_class%>"
|
363
364
|
response.should have_tag("form#re_rule_new_form") do
|
364
365
|
with_tag("input#<%=rule_name%>_title")
|
365
|
-
with_tag("input#<%=rule_name%>
|
366
|
+
with_tag("input#<%=rule_name%>_match_words_0_word")
|
366
367
|
with_tag("select#<%=rule_name%>_workflow_action")
|
367
|
-
with_tag("input#<%=rule_name%>
|
368
|
+
with_tag("input#<%=rule_name%>_workflow_code")
|
368
369
|
end
|
369
370
|
end
|
370
371
|
end
|
@@ -379,10 +380,10 @@ describe ReWorkflowRulesController, :type => :controller do
|
|
379
380
|
get :edit, :re_workflow_id => @re_workflow.id, :re_rule_id => 1001, :rule_class_name => "RulesEngine::Rule::<%=rule_class%>"
|
380
381
|
response.should have_tag("form#re_rule_edit_form") do
|
381
382
|
with_tag("input#<%=rule_name%>_title", :value => 'Rule Title')
|
382
|
-
with_tag("input#<%=rule_name%>
|
383
|
-
with_tag("input#<%=rule_name%>
|
383
|
+
with_tag("input#<%=rule_name%>_match_words_0_word", :value => 'word one')
|
384
|
+
with_tag("input#<%=rule_name%>_match_words_1_word", :value => 'word two')
|
384
385
|
with_tag("select#<%=rule_name%>_workflow_action", :value => 'start_workflow')
|
385
|
-
with_tag("input#<%=rule_name%>
|
386
|
+
with_tag("input#<%=rule_name%>_workflow_code", :value => 'Other Workflow')
|
386
387
|
end
|
387
388
|
end
|
388
389
|
end
|