rules_engine_templates 0.0.2 → 0.0.3

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.
Files changed (46) hide show
  1. data/VERSION +1 -1
  2. data/rails_generators/manifests/plan_start.rb +26 -0
  3. data/rails_generators/manifests/plan_start.yml +20 -0
  4. data/rails_generators/manifests/tweet_filter.rb +2 -4
  5. data/rails_generators/manifests/tweet_filter.yml +2 -5
  6. data/rails_generators/manifests/tweet_reader.rb +26 -0
  7. data/rails_generators/manifests/tweet_reader.yml +20 -0
  8. data/rails_generators/manifests/workflow_start.rb +26 -0
  9. data/rails_generators/manifests/workflow_start.yml +20 -0
  10. data/rails_generators/manifests/workflow_stop.rb +26 -0
  11. data/rails_generators/manifests/workflow_stop.yml +20 -0
  12. data/rails_generators/templates/app/rules/plan_start.rb +89 -0
  13. data/rails_generators/templates/app/rules/tweet_filter.rb +6 -3
  14. data/rails_generators/templates/app/rules/tweet_reader.rb +99 -0
  15. data/rails_generators/templates/app/rules/workflow_start.rb +84 -0
  16. data/rails_generators/templates/app/rules/workflow_stop.rb +80 -0
  17. data/rails_generators/templates/app/views/re_rule_definitions/plan_start/_edit.html.erb +1 -0
  18. data/rails_generators/templates/app/views/re_rule_definitions/plan_start/_form.html.erb +21 -0
  19. data/rails_generators/templates/app/views/re_rule_definitions/plan_start/_help.html.erb +1 -0
  20. data/rails_generators/templates/app/views/re_rule_definitions/plan_start/_new.html.erb +1 -0
  21. data/rails_generators/templates/app/views/re_rule_definitions/tweet_filter/_edit.html.erb +1 -5
  22. data/rails_generators/templates/app/views/re_rule_definitions/tweet_filter/_form.html.erb +34 -0
  23. data/rails_generators/templates/app/views/re_rule_definitions/tweet_filter/{_word.html.erb → _form_word.html.erb} +0 -0
  24. data/rails_generators/templates/app/views/re_rule_definitions/tweet_filter/_help.html.erb +1 -1
  25. data/rails_generators/templates/app/views/re_rule_definitions/tweet_filter/_new.html.erb +1 -5
  26. data/rails_generators/templates/app/views/re_rule_definitions/tweet_reader/_edit.html.erb +1 -0
  27. data/rails_generators/templates/app/views/re_rule_definitions/tweet_reader/_form.html.erb +29 -0
  28. data/rails_generators/templates/app/views/re_rule_definitions/tweet_reader/_help.html.erb +1 -0
  29. data/rails_generators/templates/app/views/re_rule_definitions/tweet_reader/_new.html.erb +1 -0
  30. data/rails_generators/templates/app/views/re_rule_definitions/workflow_start/_edit.html.erb +1 -0
  31. data/rails_generators/templates/app/views/re_rule_definitions/workflow_start/_form.html.erb +21 -0
  32. data/rails_generators/templates/app/views/re_rule_definitions/workflow_start/_help.html.erb +1 -0
  33. data/rails_generators/templates/app/views/re_rule_definitions/workflow_start/_new.html.erb +1 -0
  34. data/rails_generators/templates/app/views/re_rule_definitions/workflow_stop/_edit.html.erb +1 -0
  35. data/rails_generators/templates/app/views/re_rule_definitions/workflow_stop/_form.html.erb +25 -0
  36. data/rails_generators/templates/app/views/re_rule_definitions/workflow_stop/_help.html.erb +1 -0
  37. data/rails_generators/templates/app/views/re_rule_definitions/workflow_stop/_new.html.erb +1 -0
  38. data/rails_generators/templates/spec/lib/rules/plan_start_spec.rb +237 -0
  39. data/rails_generators/templates/spec/lib/rules/tweet_filter_spec.rb +61 -10
  40. data/rails_generators/templates/spec/lib/rules/tweet_reader_spec.rb +272 -0
  41. data/rails_generators/templates/spec/lib/rules/workflow_start_spec.rb +223 -0
  42. data/rails_generators/templates/spec/lib/rules/workflow_stop_spec.rb +212 -0
  43. metadata +38 -8
  44. data/rails_generators/templates/app/views/re_rule_definitions/tweet_filter/_script.html.erb +0 -8
  45. data/rails_generators/templates/app/views/re_rule_definitions/tweet_filter/_title.html.erb +0 -7
  46. data/rails_generators/templates/app/views/re_rule_definitions/tweet_filter/_words.html.erb +0 -16
@@ -0,0 +1,212 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ def valid_<%=rule_name%>_data
4
+ '["Rule Title", "Rule Description"]'
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%>_description => 'Rule Description'
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 'Workflow Stop'" do
27
+ RulesEngine::Rule::<%=rule_class%>.options[:display_name].should == "Workflow Stop"
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%>_data
47
+ end
48
+
49
+ describe "the 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 description" do
59
+ @<%=rule_name%>.description.should == "Rule Description"
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 description to nil" do
71
+ @<%=rule_name%>.description.should_not be_nil
72
+ @<%=rule_name%>.data = nil
73
+ @<%=rule_name%>.description.should be_nil
74
+ end
75
+ end
76
+ end
77
+
78
+ describe "the summary" do
79
+ describe "description set" do
80
+ it "should be the rule description" do
81
+ <%=rule_name%> = RulesEngine::Rule::<%=rule_class%>.new
82
+ <%=rule_name%>.should_receive(:description).and_return("mock description")
83
+ <%=rule_name%>.summary.should == "mock description"
84
+ end
85
+ end
86
+ describe "description not set" do
87
+ it "should be Does Nothing" do
88
+ <%=rule_name%> = RulesEngine::Rule::<%=rule_class%>.new
89
+ <%=rule_name%>.should_receive(:description).and_return(nil)
90
+ <%=rule_name%>.summary.should == "Does Nothing"
91
+ end
92
+ end
93
+ end
94
+
95
+ describe "the data" do
96
+ it "should be converted to a json string" do
97
+ <%=rule_name%> = RulesEngine::Rule::<%=rule_class%>.new
98
+ <%=rule_name%>.should_receive(:title).and_return("mock title")
99
+ <%=rule_name%>.should_receive(:description).and_return("mock description")
100
+ <%=rule_name%>.data.should == '["mock title","mock description"]'
101
+ end
102
+ end
103
+
104
+ describe "the expected_outcomes" do
105
+ it "should be outcome stop success" do
106
+ <%=rule_name%> = RulesEngine::Rule::<%=rule_class%>.new
107
+ <%=rule_name%>.expected_outcomes.should == [:outcome => RulesEngine::Rule::Outcome::STOP_SUCCESS]
108
+ end
109
+ end
110
+
111
+ describe "setting the rule attributes" do
112
+ before(:each) do
113
+ @<%=rule_name%> = RulesEngine::Rule::<%=rule_class%>.new
114
+ end
115
+
116
+ it "should be valid with valid attributes" do
117
+ @<%=rule_name%>.attributes = valid_attributes
118
+ @<%=rule_name%>.should be_valid
119
+ end
120
+
121
+ describe "setting the <%=rule_name%>_title" do
122
+ it "should set the title" do
123
+ @<%=rule_name%>.attributes = valid_attributes
124
+ @<%=rule_name%>.title.should == 'Rule Title'
125
+ end
126
+
127
+ it "should not be valid if the '<%=rule_name%>_title' attribute is missing" do
128
+ @<%=rule_name%>.attributes = valid_attributes.except(:<%=rule_name%>_title)
129
+ @<%=rule_name%>.should_not be_valid
130
+ @<%=rule_name%>.errors.should include(:<%=rule_name%>_title)
131
+ end
132
+
133
+ it "should not be valid if the '<%=rule_name%>_title' attribute is blank" do
134
+ @<%=rule_name%>.attributes = valid_attributes.merge(:<%=rule_name%>_title => "")
135
+ @<%=rule_name%>.should_not be_valid
136
+ @<%=rule_name%>.errors.should include(:<%=rule_name%>_title)
137
+ end
138
+ end
139
+
140
+ describe "setting the <%=rule_name%>_description" do
141
+ it "should set the description" do
142
+ @<%=rule_name%>.attributes = valid_attributes.merge(:<%=rule_name%>_description => 'Rule Description')
143
+ @<%=rule_name%>.description.should == 'Rule Description'
144
+ end
145
+ end
146
+ end
147
+
148
+ describe "after a rule is created" do
149
+ # xit "There is nothing to do here"
150
+ end
151
+
152
+ describe "after a rule is created" do
153
+ # xit "There is nothing to do here"
154
+ end
155
+
156
+ describe "processing the rule" do
157
+ it "should stop the process" do
158
+ @<%=rule_name%> = RulesEngine::Rule::<%=rule_class%>.new
159
+ @<%=rule_name%>.process(1001, {}).outcome.should == RulesEngine::Rule::Outcome::STOP_SUCCESS
160
+ end
161
+ end
162
+ end
163
+
164
+
165
+ describe ReWorkflowRulesController, :type => :controller do
166
+ integrate_views
167
+
168
+ before(:each) do
169
+ controller.instance_eval { flash.stub!(:sweep) }
170
+
171
+ RulesEngine::Discovery.discover!
172
+
173
+ controller.stub!(:rules_engine_reader_access_required).and_return(true)
174
+ controller.stub!(:rules_engine_editor_access_required).and_return(true)
175
+
176
+ @re_workflow = ReWorkflow.make
177
+ ReWorkflow.stub!(:find).and_return(@re_workflow)
178
+ end
179
+
180
+ describe "help" do
181
+ it "should assign the <%=rule_name%> rule class" do
182
+ get :help, :rule_class_name => "RulesEngine::Rule::<%=rule_class%>"
183
+ assigns[:rule_class].should == RulesEngine::Rule::<%=rule_class%>
184
+ end
185
+ end
186
+
187
+ describe "new" do
188
+ it "show the new form class" do
189
+ get :new, :rule_class_name => "RulesEngine::Rule::<%=rule_class%>"
190
+ response.should have_tag("form#re_rule_new_form") do
191
+ with_tag("input#<%=rule_name%>_title")
192
+ with_tag("input#<%=rule_name%>_description")
193
+ end
194
+ end
195
+ end
196
+
197
+ describe "edit" do
198
+ it "show the edit form" do
199
+ re_rule = ReRule.make(:re_workflow_id => @re_workflow.id,
200
+ :rule_class_name => "RulesEngine::Rule::<%=rule_class%>",
201
+ :data => valid_<%=rule_name%>_data)
202
+ ReRule.stub!(:find).and_return(re_rule)
203
+
204
+ get :edit, :re_workflow_id => @re_workflow.id, :re_rule_id => 1001, :rule_class_name => "RulesEngine::Rule::<%=rule_class%>"
205
+ response.should have_tag("form#re_rule_edit_form") do
206
+ with_tag("input#<%=rule_name%>_title", :value => 'Rule Title')
207
+ with_tag("input#<%=rule_name%>_description", :value => 'Rule Description')
208
+ end
209
+ end
210
+ end
211
+
212
+ 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: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Chris Douglas
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-21 00:00:00 +10:00
18
+ date: 2010-07-24 00:00:00 +10:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -48,19 +48,49 @@ files:
48
48
  - README.rdoc
49
49
  - VERSION
50
50
  - lib/rules_engine_templates.rb
51
+ - rails_generators/manifests/plan_start.rb
52
+ - rails_generators/manifests/plan_start.yml
51
53
  - rails_generators/manifests/tweet_filter.rb
52
54
  - rails_generators/manifests/tweet_filter.yml
55
+ - rails_generators/manifests/tweet_reader.rb
56
+ - rails_generators/manifests/tweet_reader.yml
57
+ - rails_generators/manifests/workflow_start.rb
58
+ - rails_generators/manifests/workflow_start.yml
59
+ - rails_generators/manifests/workflow_stop.rb
60
+ - rails_generators/manifests/workflow_stop.yml
53
61
  - rails_generators/rules_engine_templates_generator.rb
62
+ - rails_generators/templates/app/rules/plan_start.rb
54
63
  - rails_generators/templates/app/rules/tweet_filter.rb
64
+ - rails_generators/templates/app/rules/tweet_reader.rb
65
+ - rails_generators/templates/app/rules/workflow_start.rb
66
+ - rails_generators/templates/app/rules/workflow_stop.rb
67
+ - rails_generators/templates/app/views/re_rule_definitions/plan_start/_edit.html.erb
68
+ - rails_generators/templates/app/views/re_rule_definitions/plan_start/_form.html.erb
69
+ - rails_generators/templates/app/views/re_rule_definitions/plan_start/_help.html.erb
70
+ - rails_generators/templates/app/views/re_rule_definitions/plan_start/_new.html.erb
55
71
  - rails_generators/templates/app/views/re_rule_definitions/tweet_filter/_edit.html.erb
72
+ - rails_generators/templates/app/views/re_rule_definitions/tweet_filter/_form.html.erb
73
+ - rails_generators/templates/app/views/re_rule_definitions/tweet_filter/_form_word.html.erb
56
74
  - rails_generators/templates/app/views/re_rule_definitions/tweet_filter/_help.html.erb
57
75
  - 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
76
+ - rails_generators/templates/app/views/re_rule_definitions/tweet_reader/_edit.html.erb
77
+ - rails_generators/templates/app/views/re_rule_definitions/tweet_reader/_form.html.erb
78
+ - rails_generators/templates/app/views/re_rule_definitions/tweet_reader/_help.html.erb
79
+ - rails_generators/templates/app/views/re_rule_definitions/tweet_reader/_new.html.erb
80
+ - rails_generators/templates/app/views/re_rule_definitions/workflow_start/_edit.html.erb
81
+ - rails_generators/templates/app/views/re_rule_definitions/workflow_start/_form.html.erb
82
+ - rails_generators/templates/app/views/re_rule_definitions/workflow_start/_help.html.erb
83
+ - rails_generators/templates/app/views/re_rule_definitions/workflow_start/_new.html.erb
84
+ - rails_generators/templates/app/views/re_rule_definitions/workflow_stop/_edit.html.erb
85
+ - rails_generators/templates/app/views/re_rule_definitions/workflow_stop/_form.html.erb
86
+ - rails_generators/templates/app/views/re_rule_definitions/workflow_stop/_help.html.erb
87
+ - rails_generators/templates/app/views/re_rule_definitions/workflow_stop/_new.html.erb
88
+ - rails_generators/templates/spec/lib/rules/plan_start_spec.rb
62
89
  - rails_generators/templates/spec/lib/rules/rule_tweet_filter_spec.rb
63
90
  - rails_generators/templates/spec/lib/rules/tweet_filter_spec.rb
91
+ - rails_generators/templates/spec/lib/rules/tweet_reader_spec.rb
92
+ - rails_generators/templates/spec/lib/rules/workflow_start_spec.rb
93
+ - rails_generators/templates/spec/lib/rules/workflow_stop_spec.rb
64
94
  - spec/spec.opts
65
95
  - spec/spec_helper.rb
66
96
  has_rdoc: true
@@ -1,8 +0,0 @@
1
- <%% javascript_tag do %>
2
- var new_<%=rule_name%> = '<%%=escape_javascript(render("/re_rule_definitions/<%=rule_name%>/word"))%>'
3
-
4
- $(document).ready(function() {
5
- $('#rule_title').focus();
6
- });
7
-
8
- <%% end %>
@@ -1,7 +0,0 @@
1
- <%%= re_text_field "Filter Title",
2
- "<%=rule_name%>_title",
3
- params[:<%=rule_name%>_title] || @re_rule.rule.title,
4
- :size => 30,
5
- :required => true,
6
- :error => @re_rule.rule.errors[:<%=rule_name%>_title],
7
- :span => '4x13' %>
@@ -1,16 +0,0 @@
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
-