rules_engine 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. data/VERSION +1 -1
  2. data/lib/rules_engine/rule/definition.rb +5 -2
  3. data/rails_generators/manifests/complex.rb +2 -5
  4. data/rails_generators/manifests/complex.yml +2 -5
  5. data/rails_generators/manifests/simple.yml +1 -1
  6. data/rails_generators/templates/app/controllers/re_plans_controller.rb +1 -1
  7. data/rails_generators/templates/app/controllers/re_workflow_rules_controller.rb +1 -3
  8. data/rails_generators/templates/app/models/re_rule.rb +13 -9
  9. data/rails_generators/templates/app/models/re_rule_expected_outcome.rb +2 -0
  10. data/rails_generators/templates/app/rules/complex.rb +4 -4
  11. data/rails_generators/templates/app/rules/simple.rb +8 -8
  12. data/rails_generators/templates/app/views/re_rule_definitions/complex/_edit.html.erb +1 -7
  13. data/rails_generators/templates/app/views/re_rule_definitions/complex/_form.html.erb +76 -0
  14. data/rails_generators/templates/app/views/re_rule_definitions/complex/{_word.html.erb → _form_word.html.erb} +0 -0
  15. data/rails_generators/templates/app/views/re_rule_definitions/complex/_help.html.erb +1 -1
  16. data/rails_generators/templates/app/views/re_rule_definitions/complex/_new.html.erb +1 -7
  17. data/rails_generators/templates/app/views/re_rule_definitions/simple/_edit.html.erb +1 -1
  18. data/rails_generators/templates/app/views/re_rule_definitions/simple/_form.html.erb +16 -7
  19. data/rails_generators/templates/app/views/re_rule_definitions/simple/_help.html.erb +1 -1
  20. data/rails_generators/templates/app/views/re_rule_definitions/simple/_new.html.erb +1 -1
  21. data/rails_generators/templates/app/views/re_workflows/_rule_change.html.erb +3 -3
  22. data/rails_generators/templates/app/views/re_workflows/_rule_show.html.erb +3 -3
  23. data/rails_generators/templates/doc/README.rules_engine +1 -1
  24. data/rails_generators/templates/spec/controllers/re_plans_controller_spec.rb +259 -183
  25. data/rails_generators/templates/spec/lib/rules/complex_spec.rb +67 -13
  26. data/rails_generators/templates/spec/lib/rules/simple_spec.rb +104 -54
  27. data/rails_generators/templates/spec/models/re_plan_spec.rb +1 -1
  28. data/rails_generators/templates/spec/models/re_rule_spec.rb +23 -18
  29. data/rails_generators/templates/spec/models/re_workflow_spec.rb +1 -1
  30. data/rails_generators/templates/spec/support/rules_engine_blueprints.rb +9 -1
  31. data/spec/railsenv/log/debug.log +592 -0
  32. data/spec/railsenv/log/test.log +52 -0
  33. data/spec/rules_engine/discovery_spec.rb +0 -1
  34. data/spec/rules_engine/rule/definition_spec.rb +8 -4
  35. metadata +6 -9
  36. data/rails_generators/templates/app/views/re_rule_definitions/complex/_script.html.erb +0 -25
  37. data/rails_generators/templates/app/views/re_rule_definitions/complex/_title.html.erb +0 -7
  38. data/rails_generators/templates/app/views/re_rule_definitions/complex/_words.html.erb +0 -16
  39. data/rails_generators/templates/app/views/re_rule_definitions/complex/_workflow.html.erb +0 -22
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.1.5
@@ -63,10 +63,13 @@ module RulesEngine
63
63
 
64
64
  ##################################################################
65
65
  # callbacks when the rule is added and removed from a workflow
66
- def after_add_to_workflow(workflow_code)
66
+ def before_create()
67
67
  end
68
68
 
69
- def before_remove_from_workflow(workflow_code)
69
+ def before_update()
70
+ end
71
+
72
+ def before_destroy()
70
73
  end
71
74
 
72
75
  ##################################################################
@@ -17,13 +17,10 @@ class ComplexManifest
17
17
 
18
18
  m.template "app/rules/complex.rb", "app/rules/#{rule_name}.rb"
19
19
  m.template "app/views/re_rule_definitions/complex/_edit.html.erb", "app/views/re_rule_definitions/#{rule_name}/_edit.html.erb"
20
+ m.template "app/views/re_rule_definitions/complex/_form.html.erb", "app/views/re_rule_definitions/#{rule_name}/_form.html.erb"
21
+ m.template "app/views/re_rule_definitions/complex/_form_word.html.erb", "app/views/re_rule_definitions/#{rule_name}/_form_word.html.erb"
20
22
  m.template "app/views/re_rule_definitions/complex/_help.html.erb", "app/views/re_rule_definitions/#{rule_name}/_help.html.erb"
21
23
  m.template "app/views/re_rule_definitions/complex/_new.html.erb", "app/views/re_rule_definitions/#{rule_name}/_new.html.erb"
22
- m.template "app/views/re_rule_definitions/complex/_script.html.erb", "app/views/re_rule_definitions/#{rule_name}/_script.html.erb"
23
- m.template "app/views/re_rule_definitions/complex/_title.html.erb", "app/views/re_rule_definitions/#{rule_name}/_title.html.erb"
24
- m.template "app/views/re_rule_definitions/complex/_word.html.erb", "app/views/re_rule_definitions/#{rule_name}/_word.html.erb"
25
- m.template "app/views/re_rule_definitions/complex/_words.html.erb", "app/views/re_rule_definitions/#{rule_name}/_words.html.erb"
26
- m.template "app/views/re_rule_definitions/complex/_workflow.html.erb", "app/views/re_rule_definitions/#{rule_name}/_workflow.html.erb"
27
24
  m.template "spec/lib/rules/complex_spec.rb", "spec/lib/rules/#{rule_name}_spec.rb"
28
25
 
29
26
  end
@@ -14,11 +14,8 @@ templates :
14
14
  files :
15
15
  - app/rules/complex.rb
16
16
  - app/views/re_rule_definitions/complex/_edit.html.erb
17
+ - app/views/re_rule_definitions/complex/_form_word.html.erb
18
+ - app/views/re_rule_definitions/complex/_form.html.erb
17
19
  - app/views/re_rule_definitions/complex/_help.html.erb
18
- - app/views/re_rule_definitions/complex/_workflow.html.erb
19
- - app/views/re_rule_definitions/complex/_script.html.erb
20
- - app/views/re_rule_definitions/complex/_title.html.erb
21
20
  - app/views/re_rule_definitions/complex/_new.html.erb
22
- - app/views/re_rule_definitions/complex/_word.html.erb
23
- - app/views/re_rule_definitions/complex/_words.html.erb
24
21
  - spec/lib/rules/complex_spec.rb
@@ -14,8 +14,8 @@ templates :
14
14
  files :
15
15
  - app/rules/simple.rb
16
16
  - app/views/re_rule_definitions/simple/_edit.html.erb
17
+ - app/views/re_rule_definitions/simple/_form.html.erb
17
18
  - app/views/re_rule_definitions/simple/_help.html.erb
18
19
  - app/views/re_rule_definitions/simple/_new.html.erb
19
- - app/views/re_rule_definitions/simple/_form.html.erb
20
20
  - spec/lib/rules/simple_spec.rb
21
21
 
@@ -31,7 +31,7 @@ class RePlansController < ApplicationController
31
31
 
32
32
  respond_to do |format|
33
33
  format.html do
34
- redirect_to(re_plans_path)
34
+ redirect_to(change_re_plan_path(@re_plan))
35
35
  end
36
36
  format.js do
37
37
  render :action => "create"
@@ -19,9 +19,7 @@ class ReWorkflowRulesController < ApplicationController
19
19
  if @rule_class.nil?
20
20
  flash[:error] = "#{params[:rule_class]} : class not found."
21
21
  render :error
22
- else
23
- @rule = @rule_class.new
24
- end
22
+ end
25
23
  end
26
24
 
27
25
  def error
@@ -8,12 +8,18 @@ class ReRule < ActiveRecord::Base
8
8
 
9
9
  default_scope :order => 're_rules.position ASC'
10
10
 
11
- before_save :before_save_rule
12
- after_create :after_create_rule
11
+ before_save :before_save_rule
13
12
  before_destroy :before_destroy_rule
14
13
 
15
14
  def before_save_rule
16
15
  return if rule.nil?
16
+
17
+ if self.new_record?
18
+ rule.before_create()
19
+ else
20
+ rule.before_update()
21
+ end
22
+
17
23
  self.title = rule.title
18
24
  self.summary = rule.summary
19
25
  self.data = rule.data
@@ -23,19 +29,17 @@ class ReRule < ActiveRecord::Base
23
29
  re_workflow.changed! if changes.detect { |change| !ignore_attributes.include?(change[0])}
24
30
  end
25
31
 
26
- def after_create_rule
27
- rule.after_add_to_workflow(self.re_workflow.code) unless rule.nil?
28
- end
29
-
30
32
  def before_destroy_rule
31
- rule.before_remove_from_workflow(self.re_workflow.code) unless rule.nil?
33
+ rule.before_destroy() unless rule.nil?
32
34
  end
33
35
 
34
36
  def validate
35
37
  if self.rule.nil?
36
- errors.add("rule_class", "not found")
38
+ errors.add("rule_class", "not found")
37
39
  elsif !self.rule.valid?
38
- errors.add(self.rule_class_name, "not valid")
40
+ errors.add(self.rule_class_name, "not valid")
41
+ else
42
+ true
39
43
  end
40
44
  end
41
45
 
@@ -7,6 +7,8 @@ class ReRuleExpectedOutcome < ActiveRecord::Base
7
7
  def validate
8
8
  if outcome == RulesEngine::Rule::Outcome::START_WORKFLOW && workflow_code.blank?
9
9
  errors.add(:workflow_code, "workflow code required")
10
+ else
11
+ true
10
12
  end
11
13
  end
12
14
  end
@@ -76,7 +76,7 @@ module RulesEngine
76
76
  end
77
77
 
78
78
  @workflow_action = param_hash[:<%=rule_name%>_workflow_action] || 'continue'
79
- @workflow = param_hash[:<%=rule_name%>_workflow] || ''
79
+ @workflow = param_hash[:<%=rule_name%>_workflow]
80
80
  end
81
81
 
82
82
  ##################################################################
@@ -91,10 +91,10 @@ module RulesEngine
91
91
 
92
92
  ##################################################################
93
93
  # callbacks when the rule is added and removed from a workflow
94
- def after_add_to_workflow(workflow_code)
94
+ def before_add_to_workflow()
95
95
  end
96
96
 
97
- def before_remove_from_workflow(workflow_code)
97
+ def before_remove_from_workflow()
98
98
  end
99
99
 
100
100
  ##################################################################
@@ -110,7 +110,7 @@ module RulesEngine
110
110
 
111
111
  words.each do |word|
112
112
  if /#{word}/i =~ tweet
113
- RulesEngine::Process.auditor.audit(process_id, "#{title} Found #{word}", RulesEngine::Process::AUDIT_INFO)
113
+ RulesEngine::Process.auditor.audit(process_id, "Found #{word}", RulesEngine::Process::AUDIT_INFO)
114
114
  data[:match] = word
115
115
 
116
116
  case workflow_action
@@ -9,9 +9,9 @@ module RulesEngine
9
9
  {
10
10
  :group => 'General',
11
11
  :display_name => 'Simple',
12
- :help_partial => '/re_rule_definitions/rule_<%=rule_name%>/help',
13
- :new_partial => '/re_rule_definitions/rule_<%=rule_name%>/new',
14
- :edit_partial => '/re_rule_definitions/rule_<%=rule_name%>/edit'
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
15
  }
16
16
 
17
17
  ##################################################################
@@ -48,24 +48,24 @@ module RulesEngine
48
48
  def attributes=(params)
49
49
  param_hash = params.symbolize_keys
50
50
 
51
- @title = param_hash[:rule_<%=rule_name%>_title]
52
- @description = param_hash[:rule_<%=rule_name%>_description]
51
+ @title = param_hash[:<%=rule_name%>_title]
52
+ @description = param_hash[:<%=rule_name%>_description]
53
53
  end
54
54
 
55
55
  ##################################################################
56
56
  # validation and errors
57
57
  def valid?
58
58
  @errors = {}
59
- @errors[:rule_<%=rule_name%>_title] = "Title required" if title.blank?
59
+ @errors[:<%=rule_name%>_title] = "Title required" if title.blank?
60
60
  return @errors.empty?
61
61
  end
62
62
 
63
63
  ##################################################################
64
64
  # callbacks when the rule is added and removed from a workflow
65
- def after_add_to_workflow(workflow_code)
65
+ def before_add_to_workflow()
66
66
  end
67
67
 
68
- def before_remove_from_workflow(workflow_code)
68
+ def before_remove_from_workflow()
69
69
  end
70
70
 
71
71
  ##################################################################
@@ -1,7 +1 @@
1
- <%%= render '/re_rule_definitions/<%=rule_name%>/script' %>
2
-
3
- <%%= render '/re_rule_definitions/<%=rule_name%>/title' %>
4
-
5
- <%%= render '/re_rule_definitions/<%=rule_name%>/words', :f => f %>
6
-
7
- <%%= render '/re_rule_definitions/<%=rule_name%>/workflow' %>
1
+ <%%= render '/re_rule_definitions/<%=rule_name%>/form', :f => f %>
@@ -0,0 +1,76 @@
1
+ <%% javascript_tag do %>
2
+ var new_<%=rule_name%> = '<%%=escape_javascript(render("/re_rule_definitions/<%=rule_name%>/form_word"))%>'
3
+
4
+ var update<%=rule_class%>WorkflowAction = function() {
5
+ if ($('#<%=rule_name%>_workflow_action').attr('value') == "start_workflow")
6
+ {
7
+ $('#<%=rule_name%>_workflow').re_form_enable();
8
+ $('#<%=rule_name%>_workflow').removeAttr("disabled");
9
+ } else {
10
+ $('#<%=rule_name%>_workflow').re_form_disable();
11
+ $('#<%=rule_name%>_workflow').attr("disabled", true);
12
+ }
13
+ }
14
+
15
+ $(document).ready(function() {
16
+ $('#<%=rule_name%>_title').focus();
17
+
18
+ $('#<%=rule_name%>_workflow_action').change(function() {
19
+ update<%=rule_class%>WorkflowAction();
20
+ });
21
+
22
+ update<%=rule_class%>WorkflowAction();
23
+ });
24
+
25
+ <%% end %>
26
+
27
+ <!-- TITLE -->
28
+ <%%= re_text_field "Title",
29
+ "<%=rule_name%>_title",
30
+ params[:<%=rule_name%>_title] || @re_rule.rule.title,
31
+ :size => 30,
32
+ :required => true,
33
+ :error => @re_rule.rule.errors[:<%=rule_name%>_title],
34
+ :span => '4x13' %>
35
+
36
+ <!-- WORDS -->
37
+ <%% position = 0 %>
38
+ <%% (@re_rule.rule.words || []).each do | word | %>
39
+ <%% f.fields_for :rule_data, {:first => false} do |frd| %>
40
+ <%%= render '/re_rule_definitions/<%=rule_name%>/form_word', :f => frd, :position => position, :word => word %>
41
+ <%% position += 1 %>
42
+ <%% end %>
43
+ <%% end %>
44
+ <%% if position == 0 %>
45
+ <%% f.fields_for :rule_data, {:first => false} do |frd| %>
46
+ <%%= render '/re_rule_definitions/<%=rule_name%>/form_word', :f => frd, :position => position %>
47
+ <%% end %>
48
+ <%% end %>
49
+
50
+ <div id="new_position_<%=rule_name%>"></div>
51
+ <%%= re_form_text "", re_add_link('Add another word to match', '<%=rule_name%>') %>
52
+
53
+
54
+ <!-- ACTION -->
55
+ <div class="clear top-10"></div>
56
+ <hr/>
57
+
58
+ <div class="span-8">
59
+ <%%= re_select "Match Outcome", '<%=rule_name%>_workflow_action',
60
+ options_for_select([
61
+ ["Continue Next", 'next'],
62
+ ["Stop Success", 'stop_success'],
63
+ ["Stop Failure", 'stop_failure'],
64
+ ["Start another Workflow", 'start_workflow']
65
+ ],
66
+ @re_rule.rule.workflow_action || params['<%=rule_name%>_workflow_action']),
67
+ :required => true %>
68
+ </div>
69
+ <div class="prepend-1 span-7 last">
70
+ <%%= re_text_field "Workflow Code", "<%=rule_name%>_workflow", @re_rule.rule.workflow || params[:<%=rule_name%>_workflow],
71
+ :size => 20,
72
+ :required => true,
73
+ :span => '3x5',
74
+ :error => @re_rule.rule.errors[:<%=rule_name%>_workflow] %>
75
+ </div>
76
+
@@ -1 +1 @@
1
- <p><%=rule_class%> : This will look for the first match in a given tweet and when found execute the required outcome</p>
1
+ <p>This will look for the first match in a given tweet and when found execute the required outcome</p>
@@ -1,7 +1 @@
1
- <%%= render '/re_rule_definitions/<%=rule_name%>/script' %>
2
-
3
- <%%= render '/re_rule_definitions/<%=rule_name%>/title' %>
4
-
5
- <%%= render '/re_rule_definitions/<%=rule_name%>/words', :f => f %>
6
-
7
- <%%= render '/re_rule_definitions/<%=rule_name%>/workflow' %>
1
+ <%%= render '/re_rule_definitions/<%=rule_name%>/form', :f => f %>
@@ -1 +1 @@
1
- <%%= render '/re_rule_definitions/rule_<%=rule_name%>/form' %>
1
+ <%%= render '/re_rule_definitions/<%=rule_name%>/form' %>
@@ -1,16 +1,25 @@
1
- <%%= re_text_field "Simple Title",
2
- "rule_<%=rule_name%>_title",
3
- params[:rule_<%=rule_name%>_title] || @re_rule.rule.title,
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,
4
13
  :size => 30,
5
14
  :required => true,
6
- :error => @re_rule.rule.errors[:rule_<%=rule_name%>_title],
15
+ :error => @re_rule.rule.errors[:<%=rule_name%>_title],
7
16
  :span => '4x13' %>
8
17
 
9
18
 
10
19
  <%%= re_text_field "Description",
11
- "rule_<%=rule_name%>_description",
12
- params[:rule_<%=rule_name%>_description] || @re_rule.rule.description,
20
+ "<%=rule_name%>_description",
21
+ params[:<%=rule_name%>_description] || @re_rule.rule.description,
13
22
  :size => 40,
14
23
  :required => false,
15
- :error => @re_rule.rule.errors[:rule_<%=rule_name%>_description],
24
+ :error => @re_rule.rule.errors[:<%=rule_name%>_description],
16
25
  :span => '4x13' %>
@@ -1 +1 @@
1
- <p> Simple : This rule does nothing </p>
1
+ <p>This rule does nothing </p>
@@ -1 +1 @@
1
- <%%= render '/re_rule_definitions/rule_<%=rule_name%>/form' %>
1
+ <%%= render '/re_rule_definitions/<%=rule_name%>/form' %>
@@ -18,16 +18,16 @@
18
18
  <div class="clear"></div>
19
19
  </div>
20
20
  <div class="<%= re_rule_error.blank? ? 're-bluebox' : 're-redbox' %> no-top">
21
- <div class="span-8">
21
+ <div class="span-7">
22
22
  <p class="top-5">
23
23
  <%=h re_rule.summary %>
24
24
  </p>
25
25
  </div>
26
- <div class="prepend-8">
26
+ <div class="span-5 float-right">
27
27
  <div class="float-right red smalltext right-5">
28
28
  <%=h re_rule_error %>
29
29
  </div>
30
- <div class="clear"></div>
30
+ <div class="top-5 clear"></div>
31
31
  <% if re_rule.re_rule_expected_outcomes.empty? %>
32
32
  <div class="re-xtra-rule-continue">Continue</div>
33
33
  <% end %>
@@ -9,16 +9,16 @@
9
9
  <div class="clear"></div>
10
10
  </div>
11
11
  <div class="<%= re_rule_error.blank? ? 're-bluebox' : 're-redbox' %> no-top">
12
- <div class="span-8">
12
+ <div class="span-7">
13
13
  <p class="top-5">
14
14
  <%=h re_rule.summary %>
15
15
  </p>
16
16
  </div>
17
- <div class="prepend-8">
17
+ <div class="span-5 float-right">
18
18
  <div class="float-right red smalltext right-5">
19
19
  <%=h re_rule_error %>
20
20
  </div>
21
- <div class="clear"></div>
21
+ <div class="top-5 clear"></div>
22
22
 
23
23
  <% if re_rule.re_rule_expected_outcomes.empty? %>
24
24
  <div class="re-xtra-rule-continue">Continue</div>
@@ -146,7 +146,7 @@ class ApplicationController < ActionController::Base
146
146
 
147
147
  ######################################
148
148
  # 8. Create a Simple Rule
149
- ./script/generate rules_engine rule_simple does_nothing
149
+ ./script/generate rules_engine simple does_nothing
150
150
 
151
151
  ######################################
152
152
  # 9. Create a Complex Rule
@@ -31,151 +31,264 @@ describe RePlansController do
31
31
  end
32
32
  end
33
33
 
34
- # describe "new" do
35
- # it_should_require_rules_engine_editor_access(:new, :id => 123)
36
- #
37
- # it "should assign a new plan record" do
38
- # re_plan = mock_model(RePlan)
39
- # RePlan.should_receive(:new).and_return(re_plan)
40
- # get :new, :id => 123
41
- # assigns[:re_plan].should == re_plan
42
- # end
43
- #
44
- # it "should render the 'new' template" do
45
- # get :new, :id => 123
46
- # response.should render_template(:new)
47
- # end
48
- # end
49
- #
50
- # describe "create" do
51
- # it_should_require_rules_engine_editor_access(:create, :re_plan => {})
52
- #
53
- # before do
54
- # @re_plan = mock_model(RePlan, :save => false)
55
- # RePlan.stub!(:new).and_return(@re_plan)
56
- # end
57
- #
58
- # it "should assign the re_plan parameters" do
59
- # RePlan.should_receive(:new).with("name" => "name", "value" => "value")
60
- # post :create, :re_plan => { :name => "name", :value => "value" }
61
- # end
62
- #
63
- # it "should save the re_plan" do
64
- # @re_plan.should_receive(:save)
65
- # post :create, :re_plan => { :key => "value" }
66
- # end
67
- #
68
- # describe "save failed" do
69
- # it "should render the 'new' template" do
70
- # post :create, :re_plan => { :key => "value" }
71
- # response.should render_template(:new)
72
- # end
73
- # end
74
- #
75
- # describe "save succeeded" do
76
- # before do
77
- # @re_plan.stub!(:save).and_return(true)
78
- # end
79
- #
80
- # it "should display a flash success message" do
81
- # post :create, :re_plan => { :key => "value" }
82
- # flash[:success].should_not be_blank
83
- # end
84
- #
85
- # it "should redirect to the change re_plan page for HTML" do
86
- # post :create, :re_plan => { :key => "value" }
87
- # response.should redirect_to(change_re_plan_path(@re_plan))
88
- # end
89
- #
90
- # it "should render 'create' template for JAVASCRIPT" do
91
- # xhr :post, :create, :re_plan => { :key => "value" }
92
- # response.should render_template(:create)
93
- # end
94
- # end
95
- # end
96
- #
97
- # describe "change" do
98
- # it_should_require_rules_engine_editor_access(:change, :id => 123)
99
- #
100
- # it "should get the plan record with the ID" do
101
- # re_plan = mock_model(RePlan)
102
- # RePlan.should_receive(:find).with("123").and_return(re_plan)
103
- # get :change, :id => 123
104
- # assigns[:re_plan].should == re_plan
105
- # end
106
- # end
107
- #
108
- # describe "edit" do
109
- # it_should_require_rules_engine_editor_access(:edit, :id => 123)
110
- #
111
- # it "should get the plan record with the ID" do
112
- # re_plan = mock_model(RePlan)
113
- # RePlan.should_receive(:find).with("123").and_return(re_plan)
114
- # get :edit, :id => 123
115
- # assigns[:re_plan].should == re_plan
116
- # end
117
- # end
118
- #
119
- # describe "update" do
120
- # it_should_require_rules_engine_editor_access(:update, :id => 123, :re_plan => {})
121
- #
122
- # before do
123
- # @re_plan = mock_model(RePlan, :save => false)
124
- # @re_plan.stub!(:attributes=)
125
- # RePlan.stub!(:find).and_return(@re_plan)
126
- # end
127
- #
128
- # it "should get the plan record with the ID" do
129
- # RePlan.should_receive(:find).with("123").and_return(@re_plan)
130
- # put :update, :id => 123, :re_plan => { :key => "value" }
131
- # assigns[:re_plan].should == @re_plan
132
- # end
133
- #
134
- # it "should assign the re_plan parameters" do
135
- # @re_plan.should_receive(:attributes=).with("name" => "name", "value" => "value")
136
- # put :update, :id => 123, :re_plan => { :name => "name", :value => "value" }
137
- # end
138
- #
139
- # it "should not assign the re_plan parameters :code" do
140
- # @re_plan.should_receive(:attributes=).with("name" => "name", "value" => "value")
141
- # put :update, :id => 123, :re_plan => { :name => "name", :value => "value", :code => "code" }
142
- # end
143
- #
144
- # it "should save the re_plan" do
145
- # @re_plan.should_receive(:save)
146
- # put :update, :id => 123, :re_plan => { :key => "value" }
147
- # end
148
- #
149
- # describe "save failed" do
150
- # it "should render the 'edit' template" do
151
- # put :update, :id => 123, :re_plan => { :key => "value" }
152
- # response.should render_template(:edit)
153
- # end
154
- # end
155
- #
156
- # describe "save succeeded" do
157
- # before do
158
- # @re_plan.stub!(:save).and_return(true)
159
- # end
160
- #
161
- # it "should display a flash success message" do
162
- # put :update, :id => 123, :re_plan => { :key => "value" }
163
- # flash[:success].should_not be_blank
164
- # end
165
- #
166
- # it "should redirect to the change re_plan page for HTML" do
167
- # put :update, :id => 123, :re_plan => { :key => "value" }
168
- # response.should redirect_to(change_re_plan_path(@re_plan))
169
- # end
170
- #
171
- # it "should render 'update' template for JAVASCRIPT" do
172
- # xhr :put, :update, :id => 123, :re_plan => { :key => "value" }
173
- # response.should render_template(:update)
174
- # end
175
- # end
176
- # end
177
- #
178
- #
34
+ describe "new" do
35
+ it_should_require_rules_engine_editor_access(:new, :id => 123)
36
+
37
+ it "should assign a new plan record" do
38
+ re_plan = RePlan.make
39
+ RePlan.should_receive(:new).and_return(re_plan)
40
+ get :new, :id => 123
41
+ assigns[:re_plan].should == re_plan
42
+ end
43
+
44
+ it "should render the 'new' template" do
45
+ get :new, :id => 123
46
+ response.should render_template(:new)
47
+ end
48
+ end
49
+
50
+ describe "create" do
51
+ it_should_require_rules_engine_editor_access(:create, :re_plan => {})
52
+
53
+ before do
54
+ @re_plan = RePlan.make
55
+ RePlan.stub!(:new).and_return(@re_plan)
56
+ end
57
+
58
+ it "should assign the re_plan parameters" do
59
+ RePlan.should_receive(:new).with("code" => "name", "title" => "value")
60
+ post :create, :re_plan => { :code => "name", :title => "value" }
61
+ end
62
+
63
+ it "should save the re_plan" do
64
+ @re_plan.should_receive(:save)
65
+ post :create, :re_plan => { :title => "name" }
66
+ end
67
+
68
+ describe "save failed" do
69
+ before(:each) do
70
+ @re_plan.stub!(:save).and_return(false)
71
+ end
72
+
73
+ it "should render the 'new' template" do
74
+ post :create, :re_plan => { :title => "name" }
75
+ response.should render_template(:new)
76
+ end
77
+ end
78
+
79
+ describe "save succeeded" do
80
+ before(:each) do
81
+ @re_plan.stub!(:save).and_return(true)
82
+ end
83
+
84
+ it "should display a flash success message" do
85
+ post :create, :re_plan => { :title => "name" }
86
+ flash[:success].should_not be_blank
87
+ end
88
+
89
+ it "should redirect to the change re_plan page for HTML" do
90
+ post :create, :re_plan => { :title => "name" }
91
+ response.should redirect_to(change_re_plan_path(@re_plan))
92
+ end
93
+
94
+ it "should render 'create' template for JAVASCRIPT" do
95
+ xhr :post, :create, :re_plan => { :title => "name" }
96
+ response.should render_template(:create)
97
+ end
98
+ end
99
+ end
100
+
101
+ describe "edit" do
102
+ it_should_require_rules_engine_editor_access(:edit, :id => 123)
103
+
104
+ it "should get the plan record with the ID" do
105
+ re_plan = RePlan.make
106
+ RePlan.should_receive(:find).with("123").and_return(re_plan)
107
+ get :edit, :id => 123
108
+ assigns[:re_plan].should == re_plan
109
+ end
110
+ end
111
+
112
+ describe "update" do
113
+ it_should_require_rules_engine_editor_access(:update, :id => 123, :re_plan => {})
114
+
115
+ before do
116
+ @re_plan = RePlan.make
117
+ RePlan.stub!(:find).and_return(@re_plan)
118
+ end
119
+
120
+ it "should get the plan record with the ID" do
121
+ RePlan.should_receive(:find).with("123").and_return(@re_plan)
122
+ put :update, :id => 123, :re_plan => { :title => "value" }
123
+ assigns[:re_plan].should == @re_plan
124
+ end
125
+
126
+ it "should assign the re_plan parameters" do
127
+ @re_plan.should_receive(:attributes=).with("title" => "name")
128
+ put :update, :id => 123, :re_plan => { :title => "name" }
129
+ end
130
+
131
+ it "should not assign the re_plan parameters :code" do
132
+ @re_plan.should_receive(:attributes=).with("title" => "name")
133
+ put :update, :id => 123, :re_plan => { :title => "name", :code => "code" }
134
+ end
135
+
136
+ it "should save the re_plan" do
137
+ @re_plan.should_receive(:save)
138
+ put :update, :id => 123, :re_plan => { :title => "name" }
139
+ end
140
+
141
+ describe "save failed" do
142
+ before(:each) do
143
+ @re_plan.stub!(:save).and_return(false)
144
+ end
145
+
146
+ it "should render the 'edit' template" do
147
+ put :update, :id => 123, :re_plan => { :title => "name" }
148
+ response.should render_template(:edit)
149
+ end
150
+ end
151
+
152
+ describe "save succeeded" do
153
+ before do
154
+ @re_plan.stub!(:save).and_return(true)
155
+ end
156
+
157
+ it "should display a flash success message" do
158
+ put :update, :id => 123, :re_plan => { :title => "name" }
159
+ flash[:success].should_not be_blank
160
+ end
161
+
162
+ it "should redirect to the change re_plan page for HTML" do
163
+ put :update, :id => 123, :re_plan => { :title => "name" }
164
+ response.should redirect_to(change_re_plan_path(@re_plan))
165
+ end
166
+
167
+ it "should render 'update' template for JAVASCRIPT" do
168
+ xhr :put, :update, :id => 123, :re_plan => { :title => "name" }
169
+ response.should render_template(:update)
170
+ end
171
+ end
172
+ end
173
+
174
+ describe "destroy" do
175
+ it_should_require_rules_engine_editor_access(:destroy, :id => 123)
176
+
177
+ before do
178
+ @re_plan = RePlan.make
179
+ RePlan.stub!(:find).and_return(@re_plan)
180
+ end
181
+
182
+ it "should get the plan record with the ID" do
183
+ RePlan.should_receive(:find).with("123").and_return(@re_plan)
184
+ delete :destroy, :id => 123
185
+ assigns[:re_plan].should == @re_plan
186
+ end
187
+
188
+ it "should destroy the re_plan" do
189
+ @re_plan.should_receive(:destroy)
190
+ delete :destroy, :id => 123
191
+ end
192
+
193
+ it "should display a flash success message" do
194
+ delete :destroy, :id => 123
195
+ flash[:success].should_not be_blank
196
+ end
197
+
198
+ it "should redirect to the re_plans page for HTML" do
199
+ delete :destroy, :id => 123
200
+ response.should redirect_to(re_plans_path)
201
+ end
202
+
203
+ it "should redirect to the re_plans page for JAVASCRIPT" do
204
+ xhr :delete, :destroy, :id => 123
205
+ response.body.should == "window.location.href = '#{re_plans_path}';"
206
+ end
207
+ end
208
+
209
+ describe "change" do
210
+ it_should_require_rules_engine_editor_access(:change, :id => 123)
211
+
212
+ it "should get the plan record with the ID" do
213
+ re_plan = RePlan.make
214
+ RePlan.should_receive(:find).with("123").and_return(re_plan)
215
+ get :change, :id => 123
216
+ assigns[:re_plan].should == re_plan
217
+ end
218
+ end
219
+
220
+ describe "preview" do
221
+ it_should_require_rules_engine_reader_access(:preview, :id => 123)
222
+
223
+ it "should get the plan record with the ID" do
224
+ re_plan = RePlan.make
225
+ RePlan.should_receive(:find).with("123").and_return(re_plan)
226
+ get :preview, :id => 123
227
+ assigns[:re_plan].should == re_plan
228
+ end
229
+ end
230
+
231
+ describe "publish" do
232
+ it_should_require_rules_engine_editor_access(:publish, :id => 123)
233
+
234
+ before do
235
+ @re_plan = RePlan.make
236
+ @re_plan.stub!(:plan_error).and_return(nil)
237
+ RePlan.stub!(:find).and_return(@re_plan)
238
+ end
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
+ describe "tag is blank" do
249
+ it "should display a flash error message" do
250
+ put :publish, :id => 123, :tag => ""
251
+ flash[:error].should_not be_blank
252
+ end
253
+ end
254
+
255
+ describe "plan is valid" do
256
+ before(:each) do
257
+ @publisher = mock('publisher')
258
+ @publisher.stub!(:publish)
259
+ RulesEngine::Publish.stub!(:publisher).and_return(@publisher)
260
+ end
261
+
262
+ it "should publish the plan" do
263
+ @publisher.should_receive(:publish).with(@re_plan.code, "publish tag", @re_plan.publish)
264
+ put :publish, :id => 123, :tag => "publish tag"
265
+ end
266
+
267
+ it "should update the plan to published" do
268
+ put :publish, :id => 123, :tag => "publish tag"
269
+ @re_plan.plan_status.should == RePlan::PLAN_STATUS_PUBLISHED
270
+ end
271
+
272
+ it "should display a flash success message" do
273
+ put :publish, :id => 123, :tag => "publish tag"
274
+ flash[:success].should_not be_blank
275
+ end
276
+ end
277
+
278
+ it "should redirect to the change_re_plan page for HTML" do
279
+ put :publish, :id => 123, :tag => "publish tag"
280
+ response.should redirect_to(change_re_plan_path(@re_plan))
281
+ end
282
+
283
+ it "should render the update page for JAVASCRIPT" do
284
+ xhr :put, :publish, :id => 123, :tag => "publish tag"
285
+ response.should render_template(:update)
286
+ end
287
+ end
288
+ end
289
+
290
+
291
+
179
292
  # describe "activate_all" do
180
293
  # it_should_require_rules_engine_editor_access(:activate_all)
181
294
  #
@@ -369,41 +482,4 @@ describe RePlansController do
369
482
  # response.should render_template(:update)
370
483
  # end
371
484
  # end
372
- #
373
- # describe "destroy" do
374
- # it_should_require_rules_engine_editor_access(:destroy, :id => 123)
375
- #
376
- # before do
377
- # @re_plan = mock_model(RePlan)
378
- # @re_plan.stub!(:destroy)
379
- # RePlan.stub!(:find).and_return(@re_plan)
380
- # end
381
- #
382
- # it "should get the plan record with the ID" do
383
- # RePlan.should_receive(:find).with("123").and_return(@re_plan)
384
- # delete :destroy, :id => 123
385
- # assigns[:re_plan].should == @re_plan
386
- # end
387
- #
388
- # it "should destroy the re_plan" do
389
- # @re_plan.should_receive(:destroy)
390
- # delete :destroy, :id => 123
391
- # end
392
- #
393
- # it "should display a flash success message" do
394
- # delete :destroy, :id => 123
395
- # flash[:success].should_not be_blank
396
- # end
397
- #
398
- # it "should redirect to the re_plans page for HTML" do
399
- # delete :destroy, :id => 123
400
- # response.should redirect_to(re_plans_path)
401
- # end
402
- #
403
- # it "should redirect to the re_plans page for JAVASCRIPT" do
404
- # xhr :delete, :destroy, :id => 123
405
- # response.body.should == "window.location.href = '#{re_plans_path}';"
406
- # end
407
- # end
408
-
409
- end
485
+ #