rules_engine_templates 0.0.1 → 0.0.2
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/tweet_filter.rb +29 -0
- data/rails_generators/manifests/tweet_filter.yml +24 -0
- data/rails_generators/templates/app/rules/tweet_filter.rb +104 -0
- data/rails_generators/templates/app/views/re_rule_definitions/tweet_filter/_edit.html.erb +5 -0
- data/rails_generators/templates/app/views/re_rule_definitions/tweet_filter/_help.html.erb +1 -0
- data/rails_generators/templates/app/views/re_rule_definitions/tweet_filter/_new.html.erb +5 -0
- data/rails_generators/templates/app/views/re_rule_definitions/tweet_filter/_script.html.erb +8 -0
- data/rails_generators/templates/app/views/re_rule_definitions/tweet_filter/_title.html.erb +7 -0
- data/rails_generators/templates/app/views/re_rule_definitions/tweet_filter/_word.html.erb +13 -0
- data/rails_generators/templates/app/views/re_rule_definitions/tweet_filter/_words.html.erb +16 -0
- data/rails_generators/templates/spec/lib/rules/rule_tweet_filter_spec.rb +220 -0
- data/rails_generators/templates/spec/lib/rules/tweet_filter_spec.rb +220 -0
- metadata +16 -6
- data/rails_generators/manifests/rule_tweet_filter.rb +0 -29
- data/rails_generators/manifests/rule_tweet_filter.yml +0 -12
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class TweetFilterManifest
|
2
|
+
def self.populate_record(m, rule_name ,rule_class)
|
3
|
+
|
4
|
+
%W(
|
5
|
+
app/rules
|
6
|
+
app/views/re_rule_definitions/#{rule_name}
|
7
|
+
lib/tasks
|
8
|
+
spec/lib/rules
|
9
|
+
).each do |dirname|
|
10
|
+
m.directory dirname
|
11
|
+
end
|
12
|
+
|
13
|
+
%W(
|
14
|
+
).each do |filename|
|
15
|
+
m.file filename, filename
|
16
|
+
end
|
17
|
+
|
18
|
+
m.template "app/rules/tweet_filter.rb", "app/rules/#{rule_name}.rb"
|
19
|
+
m.template "app/views/re_rule_definitions/tweet_filter/_edit.html.erb", "app/views/re_rule_definitions/#{rule_name}/_edit.html.erb"
|
20
|
+
m.template "app/views/re_rule_definitions/tweet_filter/_help.html.erb", "app/views/re_rule_definitions/#{rule_name}/_help.html.erb"
|
21
|
+
m.template "app/views/re_rule_definitions/tweet_filter/_new.html.erb", "app/views/re_rule_definitions/#{rule_name}/_new.html.erb"
|
22
|
+
m.template "app/views/re_rule_definitions/tweet_filter/_script.html.erb", "app/views/re_rule_definitions/#{rule_name}/_script.html.erb"
|
23
|
+
m.template "app/views/re_rule_definitions/tweet_filter/_title.html.erb", "app/views/re_rule_definitions/#{rule_name}/_title.html.erb"
|
24
|
+
m.template "app/views/re_rule_definitions/tweet_filter/_word.html.erb", "app/views/re_rule_definitions/#{rule_name}/_word.html.erb"
|
25
|
+
m.template "app/views/re_rule_definitions/tweet_filter/_words.html.erb", "app/views/re_rule_definitions/#{rule_name}/_words.html.erb"
|
26
|
+
m.template "spec/lib/rules/tweet_filter_spec.rb", "spec/lib/rules/#{rule_name}_spec.rb"
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
directories :
|
2
|
+
- app/rules
|
3
|
+
- spec/lib/rules
|
4
|
+
- lib/tasks
|
5
|
+
|
6
|
+
templates :
|
7
|
+
replacements :
|
8
|
+
- tweet_filter : rule_name
|
9
|
+
- TweetFilter : rule_class
|
10
|
+
|
11
|
+
directories :
|
12
|
+
- app/views/re_rule_definitions/tweet_filter
|
13
|
+
|
14
|
+
files :
|
15
|
+
- app/rules/tweet_filter.rb
|
16
|
+
- app/views/re_rule_definitions/tweet_filter/_edit.html.erb
|
17
|
+
- app/views/re_rule_definitions/tweet_filter/_help.html.erb
|
18
|
+
- app/views/re_rule_definitions/tweet_filter/_new.html.erb
|
19
|
+
- app/views/re_rule_definitions/tweet_filter/_script.html.erb
|
20
|
+
- app/views/re_rule_definitions/tweet_filter/_title.html.erb
|
21
|
+
- app/views/re_rule_definitions/tweet_filter/_word.html.erb
|
22
|
+
- app/views/re_rule_definitions/tweet_filter/_words.html.erb
|
23
|
+
- spec/lib/rules/tweet_filter_spec.rb
|
24
|
+
|
@@ -0,0 +1,104 @@
|
|
1
|
+
module RulesEngine
|
2
|
+
module Rule
|
3
|
+
class <%=rule_class%> < RulesEngine::Rule::Definition
|
4
|
+
|
5
|
+
attr_reader :words
|
6
|
+
|
7
|
+
##################################################################
|
8
|
+
# class options
|
9
|
+
self.options =
|
10
|
+
{
|
11
|
+
:group => 'Twitter',
|
12
|
+
:display_name => 'Twitter Filter',
|
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
|
+
@words = nil
|
24
|
+
else
|
25
|
+
@title, @words = 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
|
+
"Filter out tweets with the #{words.size == 1 ? 'word' : 'words'} #{words.join(', ')}"
|
37
|
+
end
|
38
|
+
|
39
|
+
def data
|
40
|
+
[title, words].to_json
|
41
|
+
end
|
42
|
+
|
43
|
+
def expected_outcomes
|
44
|
+
[{:outcome => RulesEngine::Rule::Outcome::NEXT}, {:outcome => RulesEngine::Rule::Outcome::STOP_SUCCESS}]
|
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
|
+
|
54
|
+
@words = []
|
55
|
+
return if param_hash[:<%=rule_name%>_words].nil?
|
56
|
+
param_hash[:<%=rule_name%>_words].each do |key, values|
|
57
|
+
if values.is_a?(Hash)
|
58
|
+
word_hash = values.symbolize_keys
|
59
|
+
@words << word_hash[:word].downcase unless word_hash[:word].blank? || word_hash[:_delete] == '1'
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
##################################################################
|
65
|
+
# validation and errors
|
66
|
+
def valid?
|
67
|
+
@errors = {}
|
68
|
+
@errors[:<%=rule_name%>_words] = "At least one word must be defined" if words.nil? || words.empty?
|
69
|
+
@errors[:<%=rule_name%>_title] = "Title required" if title.blank?
|
70
|
+
return @errors.empty?
|
71
|
+
end
|
72
|
+
|
73
|
+
##################################################################
|
74
|
+
# callbacks when the rule is added and removed from a workflow
|
75
|
+
def after_add_to_workflow(workflow_code)
|
76
|
+
end
|
77
|
+
|
78
|
+
def before_remove_from_workflow(workflow_code)
|
79
|
+
end
|
80
|
+
|
81
|
+
##################################################################
|
82
|
+
# execute the rule
|
83
|
+
# if a match is found procees to the expected outcome
|
84
|
+
# it gets the data parameter :tweet
|
85
|
+
# it sets the data parameter :match
|
86
|
+
def process(process_id, data)
|
87
|
+
tweet = data[:tweet] || data["tweet"]
|
88
|
+
if tweet.blank?
|
89
|
+
return RulesEngine::Rule::Outcome.new(RulesEngine::Rule::Outcome::NEXT)
|
90
|
+
end
|
91
|
+
|
92
|
+
words.each do |word|
|
93
|
+
if /#{word}/i =~ tweet
|
94
|
+
RulesEngine::Process.auditor.audit(process_id, "#{title} Found #{word}", RulesEngine::Process::AUDIT_INFO)
|
95
|
+
data[:match] = word
|
96
|
+
return RulesEngine::Rule::Outcome.new(RulesEngine::Rule::Outcome::STOP_SUCCESS)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
RulesEngine::Rule::Outcome.new(RulesEngine::Rule::Outcome::NEXT)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<p>Twitter Filter : This will filter out any tweets with the matching text</p>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<%% id = local_assigns[:position] ? position : 'NEW_RECORD' %>
|
2
|
+
|
3
|
+
<div id="<%=rule_name%>_<%%=id%>">
|
4
|
+
<%%= re_text_field "Words to filter", "<%=rule_name%>_words[#{id}][word]",
|
5
|
+
local_assigns[:word] ? word : '',
|
6
|
+
:size => 25,
|
7
|
+
:required => id == 0,
|
8
|
+
:span => '4x13',
|
9
|
+
:error => id == 0 ? @re_rule.rule.errors[:<%=rule_name%>_words] : nil,
|
10
|
+
:hint => re_remove_link("Remove", "<%=rule_name%>[#{id}]", id) %>
|
11
|
+
|
12
|
+
<%%= re_remove_field("<%=rule_name%>[#{id}]", id) %>
|
13
|
+
</div>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<%% position = 0 %>
|
2
|
+
<%% (@re_rule.rule.words || []).each do | word | %>
|
3
|
+
<%% f.fields_for :rule_data, {:first => false} do |frd| %>
|
4
|
+
<%%= render '/re_rule_definitions/<%=rule_name%>/word', :f => frd, :position => position, :word => word %>
|
5
|
+
<%% position += 1 %>
|
6
|
+
<%% end %>
|
7
|
+
<%% end %>
|
8
|
+
<%% if position == 0 %>
|
9
|
+
<%% f.fields_for :rule_data, {:first => false} do |frd| %>
|
10
|
+
<%%= render '/re_rule_definitions/<%=rule_name%>/word', :f => frd, :position => position %>
|
11
|
+
<%% end %>
|
12
|
+
<%% end %>
|
13
|
+
|
14
|
+
<div id="new_position_<%=rule_name%>"></div>
|
15
|
+
<%%= re_form_text "", re_add_link('Add another word to filter', '<%=rule_name%>') %>
|
16
|
+
|
@@ -0,0 +1,220 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
describe <%=rule_class%> do
|
4
|
+
|
5
|
+
def valid_attributes
|
6
|
+
{
|
7
|
+
:tweet_filter_title => 'Valid Title',
|
8
|
+
:tweet_filter_words => {
|
9
|
+
"1" => { "word" => 'first word' },
|
10
|
+
"2" => { "word" => 'second word' }
|
11
|
+
}
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
def valid_json_data
|
16
|
+
'["Rule Title", ["one", "two"]]'
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should be discoverable" do
|
20
|
+
RulesEngine::Discovery.rule_class("<%=rule_class%>").should == <%=rule_class%>
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "the expected class options" do
|
24
|
+
it "should be in the 'Twitter' group" do
|
25
|
+
<%=rule_class%>.options[:group].should == "Twitter"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should have the diplay name of 'Twitter Filter'" do
|
29
|
+
<%=rule_class%>.options[:display_name].should == "Twitter Filter"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should have the help template of '/re_rule_definitions/<%=rule_name%>/help'" do
|
33
|
+
<%=rule_class%>.options[:help_partial].should == '/re_rule_definitions/<%=rule_name%>/help'
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should have the new template of '/re_rule_definitions/<%=rule_name%>/new'" do
|
37
|
+
<%=rule_class%>.options[:new_partial].should == '/re_rule_definitions/<%=rule_name%>/new'
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should have the edit view partial template of '/re_rule_definitions/<%=rule_name%>/edit'" do
|
41
|
+
<%=rule_class%>.options[:edit_partial].should == '/re_rule_definitions/<%=rule_name%>/edit'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "setting the rule data" do
|
46
|
+
before(:each) do
|
47
|
+
@filter = <%=rule_class%>.new
|
48
|
+
@filter.data = valid_json_data
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "the json data is valid" do
|
52
|
+
it "should be valid" do
|
53
|
+
@filter.should be_valid
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should set the title" do
|
57
|
+
@filter.title.should == "Rule Title"
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should set the words" do
|
61
|
+
@filter.words.should == ["one", "two"]
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "the data is nil" do
|
66
|
+
it "should set the title to nil" do
|
67
|
+
@filter.title.should_not be_nil
|
68
|
+
@filter.data = nil
|
69
|
+
@filter.title.should be_nil
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should set the words to nil" do
|
73
|
+
@filter.words.should_not be_nil
|
74
|
+
@filter.data = nil
|
75
|
+
@filter.words.should be_nil
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "the summary" do
|
81
|
+
it "should be singluar if there is one word" do
|
82
|
+
filter = <%=rule_class%>.new
|
83
|
+
filter.stub!(:words).and_return(["one"])
|
84
|
+
filter.summary.should == "Filter out tweets with the word one"
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should be plural if there are multiple words" do
|
88
|
+
filter = <%=rule_class%>.new
|
89
|
+
filter.stub!(:words).and_return(["one", "two", "three"])
|
90
|
+
filter.summary.should == "Filter out tweets with the words one, two, three"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "the data" do
|
95
|
+
it "should be converted to a json string" do
|
96
|
+
filter = <%=rule_class%>.new
|
97
|
+
filter.should_receive(:title).and_return(["mock title"])
|
98
|
+
filter.should_receive(:words).and_return(["one", "two"])
|
99
|
+
filter.data.should == '[["mock title"],["one","two"]]'
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
describe "the expected_outcomes" do
|
104
|
+
it "should be next and stop success" do
|
105
|
+
filter = <%=rule_class%>.new
|
106
|
+
filter.expected_outcomes.should == [{:outcome => RulesEngine::RuleOutcome::OUTCOME_NEXT}, {:outcome => RulesEngine::RuleOutcome::OUTCOME_STOP_SUCCESS}]
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe "setting the rule attributes" do
|
111
|
+
before(:each) do
|
112
|
+
@filter = <%=rule_class%>.new
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should be valid with valid attributes" do
|
116
|
+
@filter.attributes = valid_attributes
|
117
|
+
@filter.should be_valid
|
118
|
+
end
|
119
|
+
|
120
|
+
describe "setting the tweet_filter_title" do
|
121
|
+
it "should set the title" do
|
122
|
+
@filter.attributes = valid_attributes
|
123
|
+
@filter.title.should == 'Valid Title'
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should not be valid if the 'tweet_filter_title' attribute is missing" do
|
127
|
+
@filter.attributes = valid_attributes.except(:tweet_filter_title)
|
128
|
+
@filter.should_not be_valid
|
129
|
+
@filter.errors.should include(:tweet_filter_title)
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should not be valid if the 'tweet_filter_title' attribute is blank" do
|
133
|
+
@filter.attributes = valid_attributes.merge(:tweet_filter_title => "")
|
134
|
+
@filter.should_not be_valid
|
135
|
+
@filter.errors.should include(:tweet_filter_title)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
describe "setting the tweet_filter_words" do
|
140
|
+
it "should set the words" do
|
141
|
+
@filter.attributes = valid_attributes
|
142
|
+
@filter.words.should == ['first word', 'second word']
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should not be valid if the 'tweet_filter_words' attribute is missing" do
|
146
|
+
@filter.attributes = valid_attributes.except(:tweet_filter_words)
|
147
|
+
@filter.should_not be_valid
|
148
|
+
@filter.errors.should include(:tweet_filter_words)
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should not be valid if the 'tweet_filter_words' is not a hash" do
|
152
|
+
@filter.attributes = valid_attributes.merge(:tweet_filter_words => "filter word")
|
153
|
+
@filter.should_not be_valid
|
154
|
+
@filter.errors.should include(:tweet_filter_words)
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should not be valid if the 'tweet_filter_words' is empty" do
|
158
|
+
@filter.attributes = valid_attributes.merge(:tweet_filter_words => {})
|
159
|
+
@filter.should_not be_valid
|
160
|
+
@filter.errors.should include(:tweet_filter_words)
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should not include parameters that are marked for deletion" do
|
164
|
+
@filter.attributes = valid_attributes.merge(:tweet_filter_words => {
|
165
|
+
"1" => { "word" => 'first word', "_delete" => '1' },
|
166
|
+
"2" => { "word" => 'second word' }
|
167
|
+
}
|
168
|
+
)
|
169
|
+
@filter.should be_valid
|
170
|
+
@filter.words.should == ['second word']
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
describe "after a rule is created" do
|
176
|
+
# xit "There is nothing to do here"
|
177
|
+
end
|
178
|
+
|
179
|
+
describe "after a rule is created" do
|
180
|
+
# xit "There is nothing to do here"
|
181
|
+
end
|
182
|
+
|
183
|
+
describe "processing the rule" do
|
184
|
+
before(:each) do
|
185
|
+
@filter = <%=rule_class%>.new
|
186
|
+
@filter.stub!(:words).and_return(["found", "word"])
|
187
|
+
end
|
188
|
+
|
189
|
+
it "should do nothing if there is no tweet" do
|
190
|
+
@filter.process(1001, {}).outcome.should == RulesEngine::RuleOutcome::OUTCOME_NEXT
|
191
|
+
end
|
192
|
+
|
193
|
+
it "should do nothing if there is no match" do
|
194
|
+
@filter.process(@job, {:tweet => "not here"}).outcome.should == RulesEngine::RuleOutcome::OUTCOME_NEXT
|
195
|
+
end
|
196
|
+
|
197
|
+
describe "a match found" do
|
198
|
+
before(:each) do
|
199
|
+
@matched_data = {:tweet => "here is a word"}
|
200
|
+
end
|
201
|
+
|
202
|
+
it "should add the match to the data" do
|
203
|
+
@filter.process(@job, @matched_data)
|
204
|
+
@matched_data[:match].should == "word"
|
205
|
+
end
|
206
|
+
|
207
|
+
it "should audit the match" do
|
208
|
+
RulesEngine::Process.auditor.should_receive(:audit) do |process_id, message, code|
|
209
|
+
process_id.should == 1001
|
210
|
+
message.should =~ /word$/
|
211
|
+
end
|
212
|
+
@filter.process(1001, @matched_data)
|
213
|
+
end
|
214
|
+
|
215
|
+
it "should return stop_success" do
|
216
|
+
@filter.process(1001, @matched_data).outcome.should == RulesEngine::RuleOutcome::OUTCOME_STOP_SUCCESS
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
@@ -0,0 +1,220 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
describe RulesEngine::Rule::<%=rule_class%> do
|
4
|
+
|
5
|
+
def valid_attributes
|
6
|
+
{
|
7
|
+
:<%=rule_name%>_title => 'Valid Title',
|
8
|
+
:<%=rule_name%>_words => {
|
9
|
+
"1" => { "word" => 'first word' },
|
10
|
+
"2" => { "word" => 'second word' }
|
11
|
+
}
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
def valid_json_data
|
16
|
+
'["Rule Title", ["one", "two"]]'
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should be discoverable" do
|
20
|
+
RulesEngine::Discovery.rule_class("RulesEngine::Rule::<%=rule_class%>").should == RulesEngine::Rule::<%=rule_class%>
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "the expected class options" do
|
24
|
+
it "should be in the 'Twitter' group" do
|
25
|
+
RulesEngine::Rule::<%=rule_class%>.options[:group].should == "Twitter"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should have the diplay name of 'Twitter Filter'" do
|
29
|
+
RulesEngine::Rule::<%=rule_class%>.options[:display_name].should == "Twitter Filter"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should have the help template of '/re_rule_definitions/<%=rule_name%>/help'" do
|
33
|
+
RulesEngine::Rule::<%=rule_class%>.options[:help_partial].should == '/re_rule_definitions/<%=rule_name%>/help'
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should have the new template of '/re_rule_definitions/<%=rule_name%>/new'" do
|
37
|
+
RulesEngine::Rule::<%=rule_class%>.options[:new_partial].should == '/re_rule_definitions/<%=rule_name%>/new'
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should have the edit view partial template of '/re_rule_definitions/<%=rule_name%>/edit'" do
|
41
|
+
RulesEngine::Rule::<%=rule_class%>.options[:edit_partial].should == '/re_rule_definitions/<%=rule_name%>/edit'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "setting the rule data" do
|
46
|
+
before(:each) do
|
47
|
+
@filter = RulesEngine::Rule::<%=rule_class%>.new
|
48
|
+
@filter.data = valid_json_data
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "the json data is valid" do
|
52
|
+
it "should be valid" do
|
53
|
+
@filter.should be_valid
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should set the title" do
|
57
|
+
@filter.title.should == "Rule Title"
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should set the words" do
|
61
|
+
@filter.words.should == ["one", "two"]
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "the data is nil" do
|
66
|
+
it "should set the title to nil" do
|
67
|
+
@filter.title.should_not be_nil
|
68
|
+
@filter.data = nil
|
69
|
+
@filter.title.should be_nil
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should set the words to nil" do
|
73
|
+
@filter.words.should_not be_nil
|
74
|
+
@filter.data = nil
|
75
|
+
@filter.words.should be_nil
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "the summary" do
|
81
|
+
it "should be singluar if there is one word" do
|
82
|
+
filter = RulesEngine::Rule::<%=rule_class%>.new
|
83
|
+
filter.stub!(:words).and_return(["one"])
|
84
|
+
filter.summary.should == "Filter out tweets with the word one"
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should be plural if there are multiple words" do
|
88
|
+
filter = RulesEngine::Rule::<%=rule_class%>.new
|
89
|
+
filter.stub!(:words).and_return(["one", "two", "three"])
|
90
|
+
filter.summary.should == "Filter out tweets with the words one, two, three"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "the data" do
|
95
|
+
it "should be converted to a json string" do
|
96
|
+
filter = RulesEngine::Rule::<%=rule_class%>.new
|
97
|
+
filter.should_receive(:title).and_return(["mock title"])
|
98
|
+
filter.should_receive(:words).and_return(["one", "two"])
|
99
|
+
filter.data.should == '[["mock title"],["one","two"]]'
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
describe "the expected_outcomes" do
|
104
|
+
it "should be next and stop success" do
|
105
|
+
filter = RulesEngine::Rule::<%=rule_class%>.new
|
106
|
+
filter.expected_outcomes.should == [{:outcome => RulesEngine::Rule::Outcome::NEXT}, {:outcome => RulesEngine::Rule::Outcome::STOP_SUCCESS}]
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe "setting the rule attributes" do
|
111
|
+
before(:each) do
|
112
|
+
@filter = RulesEngine::Rule::<%=rule_class%>.new
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should be valid with valid attributes" do
|
116
|
+
@filter.attributes = valid_attributes
|
117
|
+
@filter.should be_valid
|
118
|
+
end
|
119
|
+
|
120
|
+
describe "setting the <%=rule_name%>_title" do
|
121
|
+
it "should set the title" do
|
122
|
+
@filter.attributes = valid_attributes
|
123
|
+
@filter.title.should == 'Valid Title'
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should not be valid if the '<%=rule_name%>_title' attribute is missing" do
|
127
|
+
@filter.attributes = valid_attributes.except(:<%=rule_name%>_title)
|
128
|
+
@filter.should_not be_valid
|
129
|
+
@filter.errors.should include(:<%=rule_name%>_title)
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should not be valid if the '<%=rule_name%>_title' attribute is blank" do
|
133
|
+
@filter.attributes = valid_attributes.merge(:<%=rule_name%>_title => "")
|
134
|
+
@filter.should_not be_valid
|
135
|
+
@filter.errors.should include(:<%=rule_name%>_title)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
describe "setting the <%=rule_name%>_words" do
|
140
|
+
it "should set the words" do
|
141
|
+
@filter.attributes = valid_attributes
|
142
|
+
@filter.words.should == ['first word', 'second word']
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should not be valid if the '<%=rule_name%>_words' attribute is missing" do
|
146
|
+
@filter.attributes = valid_attributes.except(:<%=rule_name%>_words)
|
147
|
+
@filter.should_not be_valid
|
148
|
+
@filter.errors.should include(:<%=rule_name%>_words)
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should not be valid if the '<%=rule_name%>_words' is not a hash" do
|
152
|
+
@filter.attributes = valid_attributes.merge(:<%=rule_name%>_words => "filter word")
|
153
|
+
@filter.should_not be_valid
|
154
|
+
@filter.errors.should include(:<%=rule_name%>_words)
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should not be valid if the '<%=rule_name%>_words' is empty" do
|
158
|
+
@filter.attributes = valid_attributes.merge(:<%=rule_name%>_words => {})
|
159
|
+
@filter.should_not be_valid
|
160
|
+
@filter.errors.should include(:<%=rule_name%>_words)
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should not include parameters that are marked for deletion" do
|
164
|
+
@filter.attributes = valid_attributes.merge(:<%=rule_name%>_words => {
|
165
|
+
"1" => { "word" => 'first word', "_delete" => '1' },
|
166
|
+
"2" => { "word" => 'second word' }
|
167
|
+
}
|
168
|
+
)
|
169
|
+
@filter.should be_valid
|
170
|
+
@filter.words.should == ['second word']
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
describe "after a rule is created" do
|
176
|
+
# xit "There is nothing to do here"
|
177
|
+
end
|
178
|
+
|
179
|
+
describe "after a rule is created" do
|
180
|
+
# xit "There is nothing to do here"
|
181
|
+
end
|
182
|
+
|
183
|
+
describe "processing the rule" do
|
184
|
+
before(:each) do
|
185
|
+
@filter = RulesEngine::Rule::<%=rule_class%>.new
|
186
|
+
@filter.stub!(:words).and_return(["found", "word"])
|
187
|
+
end
|
188
|
+
|
189
|
+
it "should do nothing if there is no tweet" do
|
190
|
+
@filter.process(1001, {}).outcome.should == RulesEngine::Rule::Outcome::NEXT
|
191
|
+
end
|
192
|
+
|
193
|
+
it "should do nothing if there is no match" do
|
194
|
+
@filter.process(@job, {:tweet => "not here"}).outcome.should == RulesEngine::Rule::Outcome::NEXT
|
195
|
+
end
|
196
|
+
|
197
|
+
describe "a match found" do
|
198
|
+
before(:each) do
|
199
|
+
@matched_data = {:tweet => "here is a word"}
|
200
|
+
end
|
201
|
+
|
202
|
+
it "should add the match to the data" do
|
203
|
+
@filter.process(@job, @matched_data)
|
204
|
+
@matched_data[:match].should == "word"
|
205
|
+
end
|
206
|
+
|
207
|
+
it "should audit the match" do
|
208
|
+
RulesEngine::Process.auditor.should_receive(:audit) do |process_id, message, code|
|
209
|
+
process_id.should == 1001
|
210
|
+
message.should =~ /word$/
|
211
|
+
end
|
212
|
+
@filter.process(1001, @matched_data)
|
213
|
+
end
|
214
|
+
|
215
|
+
it "should return stop_success" do
|
216
|
+
@filter.process(1001, @matched_data).outcome.should == RulesEngine::Rule::Outcome::STOP_SUCCESS
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rules_engine_templates
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Chris Douglas
|
@@ -48,16 +48,26 @@ files:
|
|
48
48
|
- README.rdoc
|
49
49
|
- VERSION
|
50
50
|
- lib/rules_engine_templates.rb
|
51
|
-
- rails_generators/manifests/
|
52
|
-
- rails_generators/manifests/
|
51
|
+
- rails_generators/manifests/tweet_filter.rb
|
52
|
+
- rails_generators/manifests/tweet_filter.yml
|
53
53
|
- rails_generators/rules_engine_templates_generator.rb
|
54
|
+
- rails_generators/templates/app/rules/tweet_filter.rb
|
55
|
+
- rails_generators/templates/app/views/re_rule_definitions/tweet_filter/_edit.html.erb
|
56
|
+
- rails_generators/templates/app/views/re_rule_definitions/tweet_filter/_help.html.erb
|
57
|
+
- rails_generators/templates/app/views/re_rule_definitions/tweet_filter/_new.html.erb
|
58
|
+
- rails_generators/templates/app/views/re_rule_definitions/tweet_filter/_script.html.erb
|
59
|
+
- rails_generators/templates/app/views/re_rule_definitions/tweet_filter/_title.html.erb
|
60
|
+
- rails_generators/templates/app/views/re_rule_definitions/tweet_filter/_word.html.erb
|
61
|
+
- rails_generators/templates/app/views/re_rule_definitions/tweet_filter/_words.html.erb
|
62
|
+
- rails_generators/templates/spec/lib/rules/rule_tweet_filter_spec.rb
|
63
|
+
- rails_generators/templates/spec/lib/rules/tweet_filter_spec.rb
|
54
64
|
- spec/spec.opts
|
55
65
|
- spec/spec_helper.rb
|
56
66
|
has_rdoc: true
|
57
67
|
homepage: http://github.com/dougochris/rules_engine_templates
|
58
68
|
licenses: []
|
59
69
|
|
60
|
-
post_install_message: "\n *** RUN script/generate rules_engine_templates\n "
|
70
|
+
post_install_message: "\n *** RUN script/generate rules_engine_templates help\n "
|
61
71
|
rdoc_options:
|
62
72
|
- --charset=UTF-8
|
63
73
|
require_paths:
|
@@ -1,29 +0,0 @@
|
|
1
|
-
class RuleTweetFilterManifest
|
2
|
-
def self.populate_record(m)
|
3
|
-
|
4
|
-
%W(
|
5
|
-
app/rules
|
6
|
-
app/views/re_rule_definitions/rule_tweet_filter
|
7
|
-
lib/tasks
|
8
|
-
spec/lib/rules
|
9
|
-
).each do |dirname|
|
10
|
-
m.directory dirname
|
11
|
-
end
|
12
|
-
|
13
|
-
%W(
|
14
|
-
app/rules/rule_tweet_filter.rb
|
15
|
-
app/views/re_rule_definitions/rule_tweet_filter/_edit.html.erb
|
16
|
-
app/views/re_rule_definitions/rule_tweet_filter/_help.html.erb
|
17
|
-
app/views/re_rule_definitions/rule_tweet_filter/_new.html.erb
|
18
|
-
app/views/re_rule_definitions/rule_tweet_filter/_script.html.erb
|
19
|
-
app/views/re_rule_definitions/rule_tweet_filter/_title.html.erb
|
20
|
-
app/views/re_rule_definitions/rule_tweet_filter/_word.html.erb
|
21
|
-
app/views/re_rule_definitions/rule_tweet_filter/_words.html.erb
|
22
|
-
spec/lib/rules/rule_tweet_filter_spec.rb
|
23
|
-
).each do |filename|
|
24
|
-
m.file filename, filename
|
25
|
-
end
|
26
|
-
|
27
|
-
|
28
|
-
end
|
29
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
directories :
|
2
|
-
- app/rules
|
3
|
-
- app/views/re_rule_definitions/rule_tweet_filter
|
4
|
-
- spec/lib/rules
|
5
|
-
- lib/tasks
|
6
|
-
|
7
|
-
contents :
|
8
|
-
- app/views/re_rule_definitions/rule_tweet_filter
|
9
|
-
|
10
|
-
files :
|
11
|
-
- app/rules/rule_tweet_filter.rb
|
12
|
-
- spec/lib/rules/rule_tweet_filter_spec.rb
|