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
@@ -0,0 +1,84 @@
|
|
1
|
+
module RulesEngine
|
2
|
+
module Rule
|
3
|
+
class <%=rule_class%> < RulesEngine::Rule::Definition
|
4
|
+
|
5
|
+
attr_reader :workflow
|
6
|
+
|
7
|
+
##################################################################
|
8
|
+
# class options
|
9
|
+
self.options =
|
10
|
+
{
|
11
|
+
:group => 'Workflow',
|
12
|
+
:display_name => 'Workflow Start',
|
13
|
+
:help_partial => '/re_rule_definitions/<%=rule_name%>/help',
|
14
|
+
:new_partial => '/re_rule_definitions/<%=rule_name%>/new',
|
15
|
+
:edit_partial => '/re_rule_definitions/<%=rule_name%>/edit'
|
16
|
+
}
|
17
|
+
|
18
|
+
##################################################################
|
19
|
+
# set the rule data
|
20
|
+
def data= data
|
21
|
+
if data.nil?
|
22
|
+
@title = nil
|
23
|
+
@workflow = nil
|
24
|
+
else
|
25
|
+
@title, @workflow = ActiveSupport::JSON.decode(data)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
##################################################################
|
30
|
+
# get the rule attributes
|
31
|
+
def title
|
32
|
+
@title
|
33
|
+
end
|
34
|
+
|
35
|
+
def summary
|
36
|
+
"Start the workflow : #{workflow}"
|
37
|
+
end
|
38
|
+
|
39
|
+
def data
|
40
|
+
[title, workflow].to_json
|
41
|
+
end
|
42
|
+
|
43
|
+
def expected_outcomes
|
44
|
+
[:outcome => RulesEngine::Rule::Outcome::START_WORKFLOW, :workflow_code => workflow]
|
45
|
+
end
|
46
|
+
|
47
|
+
##################################################################
|
48
|
+
# set the rule attributes
|
49
|
+
def attributes=(params)
|
50
|
+
param_hash = params.symbolize_keys
|
51
|
+
|
52
|
+
@title = param_hash[:<%=rule_name%>_title]
|
53
|
+
@workflow = param_hash[:<%=rule_name%>_workflow]
|
54
|
+
end
|
55
|
+
|
56
|
+
##################################################################
|
57
|
+
# validation and errors
|
58
|
+
def valid?
|
59
|
+
@errors = {}
|
60
|
+
@errors[:<%=rule_name%>_title] = "Title required" if title.blank?
|
61
|
+
@errors[:<%=rule_name%>_workflow] = "Workflow required" if workflow.blank?
|
62
|
+
return @errors.empty?
|
63
|
+
end
|
64
|
+
|
65
|
+
##################################################################
|
66
|
+
# callbacks when the rule is added and removed from a workflow
|
67
|
+
def before_create()
|
68
|
+
end
|
69
|
+
|
70
|
+
def before_update()
|
71
|
+
end
|
72
|
+
|
73
|
+
def before_destroy()
|
74
|
+
end
|
75
|
+
|
76
|
+
##################################################################
|
77
|
+
# execute the rule
|
78
|
+
# start the workflow
|
79
|
+
def process(process_id, data)
|
80
|
+
return RulesEngine::Rule::Outcome.new(RulesEngine::Rule::Outcome::START_WORKFLOW, workflow)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module RulesEngine
|
2
|
+
module Rule
|
3
|
+
class <%=rule_class%> < RulesEngine::Rule::Definition
|
4
|
+
|
5
|
+
attr_reader :description
|
6
|
+
##################################################################
|
7
|
+
# class options
|
8
|
+
self.options =
|
9
|
+
{
|
10
|
+
:group => 'Workflow',
|
11
|
+
:display_name => 'Workflow Stop',
|
12
|
+
:help_partial => '/re_rule_definitions/<%=rule_name%>/help',
|
13
|
+
:new_partial => '/re_rule_definitions/<%=rule_name%>/new',
|
14
|
+
:edit_partial => '/re_rule_definitions/<%=rule_name%>/edit'
|
15
|
+
}
|
16
|
+
|
17
|
+
##################################################################
|
18
|
+
# set the rule data
|
19
|
+
def data= data
|
20
|
+
if data.nil?
|
21
|
+
@title = nil
|
22
|
+
@description = nil
|
23
|
+
else
|
24
|
+
@title, @description = ActiveSupport::JSON.decode(data)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
##################################################################
|
29
|
+
# get the rule attributes
|
30
|
+
def title
|
31
|
+
@title
|
32
|
+
end
|
33
|
+
|
34
|
+
def summary
|
35
|
+
description || "Does Nothing"
|
36
|
+
end
|
37
|
+
|
38
|
+
def data
|
39
|
+
[title, description].to_json
|
40
|
+
end
|
41
|
+
|
42
|
+
def expected_outcomes
|
43
|
+
[:outcome => RulesEngine::Rule::Outcome::STOP_SUCCESS]
|
44
|
+
end
|
45
|
+
|
46
|
+
##################################################################
|
47
|
+
# set the rule attributes
|
48
|
+
def attributes=(params)
|
49
|
+
param_hash = params.symbolize_keys
|
50
|
+
|
51
|
+
@title = param_hash[:<%=rule_name%>_title]
|
52
|
+
@description = param_hash[:<%=rule_name%>_description]
|
53
|
+
end
|
54
|
+
|
55
|
+
##################################################################
|
56
|
+
# validation and errors
|
57
|
+
def valid?
|
58
|
+
@errors = {}
|
59
|
+
@errors[:<%=rule_name%>_title] = "Title required" if title.blank?
|
60
|
+
return @errors.empty?
|
61
|
+
end
|
62
|
+
|
63
|
+
##################################################################
|
64
|
+
# callbacks when the rule is added and removed from a workflow
|
65
|
+
def before_add_to_workflow()
|
66
|
+
end
|
67
|
+
|
68
|
+
def before_remove_from_workflow()
|
69
|
+
end
|
70
|
+
|
71
|
+
##################################################################
|
72
|
+
# execute the rule
|
73
|
+
# this rule stops the plan
|
74
|
+
def process(process_id, data)
|
75
|
+
RulesEngine::Process.auditor.audit(process_id, "Inside Rule #{title}", RulesEngine::Process::AUDIT_INFO)
|
76
|
+
RulesEngine::Rule::Outcome.new(RulesEngine::Rule::Outcome::STOP_SUCCESS)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<%%= render '/re_rule_definitions/<%=rule_name%>/form' %>
|
@@ -0,0 +1,21 @@
|
|
1
|
+
<%% javascript_tag do %>
|
2
|
+
|
3
|
+
$(document).ready(function() {
|
4
|
+
$('#<%=rule_name%>_title').focus();
|
5
|
+
});
|
6
|
+
|
7
|
+
<%% end %>
|
8
|
+
|
9
|
+
<%%= re_text_field "Title",
|
10
|
+
"<%=rule_name%>_title",
|
11
|
+
params[:<%=rule_name%>_title] || @re_rule.rule.title,
|
12
|
+
:size => 30,
|
13
|
+
:required => true,
|
14
|
+
:error => @re_rule.rule.errors[:<%=rule_name%>_title],
|
15
|
+
:span => '4x13' %>
|
16
|
+
|
17
|
+
<%%= re_text_field "Plan Code", "<%=rule_name%>_plan", @re_rule.rule.plan || params[:<%=rule_name%>_plan],
|
18
|
+
:size => 20,
|
19
|
+
:required => true,
|
20
|
+
:span => '4x13',
|
21
|
+
:error => @re_rule.rule.errors[:<%=rule_name%>_plan] %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<p>Run the plan passing the data to the new plan</p>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%%= render '/re_rule_definitions/<%=rule_name%>/form' %>
|
@@ -0,0 +1,34 @@
|
|
1
|
+
<%% javascript_tag do %>
|
2
|
+
var new_<%=rule_name%> = '<%%=escape_javascript(render("/re_rule_definitions/<%=rule_name%>/form_word"))%>'
|
3
|
+
|
4
|
+
$(document).ready(function() {
|
5
|
+
$('#<%=rule_name%>_title').focus();
|
6
|
+
});
|
7
|
+
|
8
|
+
<%% end %>
|
9
|
+
|
10
|
+
|
11
|
+
<%%= re_text_field "Title",
|
12
|
+
"<%=rule_name%>_title",
|
13
|
+
params[:<%=rule_name%>_title] || @re_rule.rule.title,
|
14
|
+
:size => 30,
|
15
|
+
:required => true,
|
16
|
+
:error => @re_rule.rule.errors[:<%=rule_name%>_title],
|
17
|
+
:span => '4x13' %>
|
18
|
+
|
19
|
+
<%% position = 0 %>
|
20
|
+
<%% (@re_rule.rule.words || []).each do | word | %>
|
21
|
+
<%% f.fields_for :rule_data, {:first => false} do |frd| %>
|
22
|
+
<%%= render '/re_rule_definitions/<%=rule_name%>/form_word', :f => frd, :position => position, :word => word %>
|
23
|
+
<%% position += 1 %>
|
24
|
+
<%% end %>
|
25
|
+
<%% end %>
|
26
|
+
<%% if position == 0 %>
|
27
|
+
<%% f.fields_for :rule_data, {:first => false} do |frd| %>
|
28
|
+
<%%= render '/re_rule_definitions/<%=rule_name%>/form_word', :f => frd, :position => position %>
|
29
|
+
<%% end %>
|
30
|
+
<%% end %>
|
31
|
+
|
32
|
+
<div id="new_position_<%=rule_name%>"></div>
|
33
|
+
<%%= re_form_text "", re_add_link('Add another word to filter', '<%=rule_name%>') %>
|
34
|
+
|
File without changes
|
@@ -1 +1 @@
|
|
1
|
-
<p>
|
1
|
+
<p>This will filter out any tweets with the matching text</p>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%%= render '/re_rule_definitions/<%=rule_name%>/form' %>
|
@@ -0,0 +1,29 @@
|
|
1
|
+
<%% javascript_tag do %>
|
2
|
+
|
3
|
+
$(document).ready(function() {
|
4
|
+
$('#<%=rule_name%>_title').focus();
|
5
|
+
});
|
6
|
+
|
7
|
+
<%% end %>
|
8
|
+
|
9
|
+
<%%= re_text_field "Title",
|
10
|
+
"<%=rule_name%>_title",
|
11
|
+
params[:<%=rule_name%>_title] || @re_rule.rule.title,
|
12
|
+
:size => 30,
|
13
|
+
:required => true,
|
14
|
+
:error => @re_rule.rule.errors[:<%=rule_name%>_title],
|
15
|
+
:span => '4x13' %>
|
16
|
+
|
17
|
+
<%%= re_text_field "Message",
|
18
|
+
"<%=rule_name%>_message",
|
19
|
+
params[:<%=rule_name%>_message] || @re_rule.rule.message,
|
20
|
+
:size => 60,
|
21
|
+
:required => true,
|
22
|
+
:error => @re_rule.rule.errors[:<%=rule_name%>_message],
|
23
|
+
:span => '4x13' %>
|
24
|
+
|
25
|
+
<%%= re_text_field "Plan Code", "<%=rule_name%>_plan", @re_rule.rule.plan || params[:<%=rule_name%>_plan],
|
26
|
+
:size => 20,
|
27
|
+
:required => true,
|
28
|
+
:span => '4x13',
|
29
|
+
:error => @re_rule.rule.errors[:<%=rule_name%>_plan] %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<p>This read the tweet message and send each tweet to the defined plan</p>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%%= render '/re_rule_definitions/<%=rule_name%>/form' %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%%= render '/re_rule_definitions/<%=rule_name%>/form' %>
|
@@ -0,0 +1,21 @@
|
|
1
|
+
<%% javascript_tag do %>
|
2
|
+
|
3
|
+
$(document).ready(function() {
|
4
|
+
$('#<%=rule_name%>_title').focus();
|
5
|
+
});
|
6
|
+
|
7
|
+
<%% end %>
|
8
|
+
|
9
|
+
<%%= re_text_field "Title",
|
10
|
+
"<%=rule_name%>_title",
|
11
|
+
params[:<%=rule_name%>_title] || @re_rule.rule.title,
|
12
|
+
:size => 30,
|
13
|
+
:required => true,
|
14
|
+
:error => @re_rule.rule.errors[:<%=rule_name%>_title],
|
15
|
+
:span => '4x13' %>
|
16
|
+
|
17
|
+
<%%= re_text_field "Workflow Code", "<%=rule_name%>_workflow", @re_rule.rule.workflow || params[:<%=rule_name%>_workflow],
|
18
|
+
:size => 20,
|
19
|
+
:required => true,
|
20
|
+
:span => '4x13',
|
21
|
+
:error => @re_rule.rule.errors[:<%=rule_name%>_workflow] %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<p>This will start the given workflow</p>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%%= render '/re_rule_definitions/<%=rule_name%>/form' %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%%= render '/re_rule_definitions/<%=rule_name%>/form' %>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<%% javascript_tag do %>
|
2
|
+
|
3
|
+
$(document).ready(function() {
|
4
|
+
$('#<%=rule_name%>_title').focus();
|
5
|
+
});
|
6
|
+
|
7
|
+
<%% end %>
|
8
|
+
|
9
|
+
|
10
|
+
<%%= re_text_field "Title",
|
11
|
+
"<%=rule_name%>_title",
|
12
|
+
params[:<%=rule_name%>_title] || @re_rule.rule.title,
|
13
|
+
:size => 30,
|
14
|
+
:required => true,
|
15
|
+
:error => @re_rule.rule.errors[:<%=rule_name%>_title],
|
16
|
+
:span => '4x13' %>
|
17
|
+
|
18
|
+
|
19
|
+
<%%= re_text_field "Description",
|
20
|
+
"<%=rule_name%>_description",
|
21
|
+
params[:<%=rule_name%>_description] || @re_rule.rule.description,
|
22
|
+
:size => 40,
|
23
|
+
:required => false,
|
24
|
+
:error => @re_rule.rule.errors[:<%=rule_name%>_description],
|
25
|
+
:span => '4x13' %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<p> stop the workflow and plan </p>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%%= render '/re_rule_definitions/<%=rule_name%>/form' %>
|
@@ -0,0 +1,237 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
def valid_<%=rule_name%>_rule_data
|
4
|
+
'["Rule Title", "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%>_plan => 'Next Plan'
|
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 == "Plan 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 plan" do
|
59
|
+
@<%=rule_name%>.plan.should == "Other Plan"
|
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 'plan' to nil" do
|
71
|
+
@<%=rule_name%>.plan.should_not be_nil
|
72
|
+
@<%=rule_name%>.data = nil
|
73
|
+
@<%=rule_name%>.plan.should be_nil
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "the summary" do
|
79
|
+
it "should show the plan" do
|
80
|
+
<%=rule_name%> = RulesEngine::Rule::<%=rule_class%>.new
|
81
|
+
<%=rule_name%>.stub!(:plan).and_return("mock")
|
82
|
+
<%=rule_name%>.summary.should == "Run the plan : 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(:plan).and_return("plan")
|
91
|
+
<%=rule_name%>.data.should == '["mock title","plan"]'
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe "the expected_outcomes" do
|
96
|
+
it "should be next and stop failure" do
|
97
|
+
<%=rule_name%> = RulesEngine::Rule::<%=rule_class%>.new
|
98
|
+
<%=rule_name%>.expected_outcomes.should include(:outcome => RulesEngine::Rule::Outcome::NEXT)
|
99
|
+
<%=rule_name%>.expected_outcomes.should include(:outcome => RulesEngine::Rule::Outcome::STOP_FAILURE)
|
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%>_plan" do
|
133
|
+
it "should be valid with valid '<%=rule_name%>_plan'" do
|
134
|
+
@<%=rule_name%>.attributes = valid_attributes
|
135
|
+
@<%=rule_name%>.should be_valid
|
136
|
+
@<%=rule_name%>.plan.should == 'Next Plan'
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should not be valid if the '<%=rule_name%>_plan' attribute is missing" do
|
140
|
+
@<%=rule_name%>.attributes = valid_attributes.except(:<%=rule_name%>_plan)
|
141
|
+
@<%=rule_name%>.should_not be_valid
|
142
|
+
@<%=rule_name%>.errors.should include(:<%=rule_name%>_plan)
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should not be valid if the '<%=rule_name%>_plan' attribute is blank" do
|
146
|
+
@<%=rule_name%>.attributes = valid_attributes.merge(:<%=rule_name%>_plan => "")
|
147
|
+
@<%=rule_name%>.should_not be_valid
|
148
|
+
@<%=rule_name%>.errors.should include(:<%=rule_name%>_plan)
|
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
|
+
@<%=rule_name%>.stub!(:plan).and_return('sub_plan')
|
165
|
+
|
166
|
+
RulesEngine::Process.runner.stub!(:create).and_return(1003)
|
167
|
+
RulesEngine::Process.runner.stub!(:run)
|
168
|
+
end
|
169
|
+
|
170
|
+
it "should create a rules process to run" do
|
171
|
+
RulesEngine::Process.runner.should_receive(:create).and_return(1003)
|
172
|
+
RulesEngine::Process.runner.should_receive(:run).with(1003, 'sub_plan', {:origional => "data"})
|
173
|
+
@<%=rule_name%>.process(1003, {:origional => "data"})
|
174
|
+
end
|
175
|
+
|
176
|
+
it "should return outcome next if the plan was successful" do
|
177
|
+
RulesEngine::Process.runner.stub!(:run).and_return(true)
|
178
|
+
@<%=rule_name%>.process(1003, {}).outcome.should == RulesEngine::Rule::Outcome::NEXT
|
179
|
+
end
|
180
|
+
|
181
|
+
it "should return outcome stop failure if the plan failed" do
|
182
|
+
RulesEngine::Process.runner.stub!(:run).and_return(false)
|
183
|
+
@<%=rule_name%>.process(1003, {}).outcome.should == RulesEngine::Rule::Outcome::STOP_FAILURE
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
|
189
|
+
describe ReWorkflowRulesController, :type => :controller do
|
190
|
+
integrate_views
|
191
|
+
|
192
|
+
before(:each) do
|
193
|
+
controller.instance_eval { flash.stub!(:sweep) }
|
194
|
+
|
195
|
+
RulesEngine::Discovery.discover!
|
196
|
+
|
197
|
+
controller.stub!(:rules_engine_reader_access_required).and_return(true)
|
198
|
+
controller.stub!(:rules_engine_editor_access_required).and_return(true)
|
199
|
+
|
200
|
+
@re_workflow = ReWorkflow.make
|
201
|
+
ReWorkflow.stub!(:find).and_return(@re_workflow)
|
202
|
+
end
|
203
|
+
|
204
|
+
describe "help" do
|
205
|
+
it "should assign the tweet reader_rule class" do
|
206
|
+
get :help, :rule_class_name => "RulesEngine::Rule::<%=rule_class%>"
|
207
|
+
assigns[:rule_class].should == RulesEngine::Rule::<%=rule_class%>
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
describe "new" do
|
212
|
+
it "show the new form class" do
|
213
|
+
get :new, :rule_class_name => "RulesEngine::Rule::<%=rule_class%>"
|
214
|
+
response.should have_tag("form#re_rule_new_form") do
|
215
|
+
with_tag("input#<%=rule_name%>_title")
|
216
|
+
with_tag("input#<%=rule_name%>_plan")
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
describe "edit" do
|
222
|
+
it "show the edit form" do
|
223
|
+
re_rule = ReRule.make(:re_workflow_id => @re_workflow.id,
|
224
|
+
:rule_class_name => "RulesEngine::Rule::<%=rule_class%>",
|
225
|
+
:data => valid_<%=rule_name%>_rule_data)
|
226
|
+
ReRule.stub!(:find).and_return(re_rule)
|
227
|
+
|
228
|
+
get :edit, :re_workflow_id => @re_workflow.id, :re_rule_id => 1001, :rule_class_name => "RulesEngine::Rule::<%=rule_class%>"
|
229
|
+
response.should have_tag("form#re_rule_edit_form") do
|
230
|
+
with_tag("input#<%=rule_name%>_title", :value => 'Rule Title')
|
231
|
+
with_tag("input#<%=rule_name%>_plan", :value => 'Other Plan')
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
end
|
237
|
+
|