rules_engine 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.6
1
+ 0.0.7
@@ -37,7 +37,11 @@ module RulesEngine
37
37
 
38
38
  activated_pipeline = RePipelineActivated.find_by_code(pipeline_code)
39
39
  unless activated_pipeline
40
- audit("Activated Pipleine : #{pipeline_code} not found", ReJobAudit::AUDIT_FAILURE)
40
+ if RePipeline.find_by_code(pipeline_code)
41
+ audit("Pipleine : #{pipeline_code} not activated", ReJobAudit::AUDIT_FAILURE)
42
+ else
43
+ audit("Pipleine : #{pipeline_code} not found", ReJobAudit::AUDIT_FAILURE)
44
+ end
41
45
  error = done = true
42
46
  next
43
47
  end
@@ -122,7 +122,7 @@ class RulesEngineManifest
122
122
  features/step_definitions/common/re_view_steps.rb
123
123
  features/support/blueprint_re_pipelines.rb
124
124
  features/support/rules_engine.rb
125
- lib/tasks/re_execute.rake
125
+ lib/tasks/rules_engine.rake
126
126
  public/javascripts/jquery-1.4.2.min.js
127
127
  public/javascripts/jquery.autocomplete.pack.js
128
128
  public/javascripts/jquery.blockUI.js
@@ -39,7 +39,7 @@ files :
39
39
 
40
40
  - app/views/layouts/rules_engine.html.erb
41
41
 
42
- - lib/tasks/re_execute.rake
42
+ - lib/tasks/rules_engine.rake
43
43
 
44
44
  - db/migrate/20100308225008_create_re_pipelines.rb
45
45
 
@@ -89,7 +89,7 @@ class RePipelinesController < ApplicationController
89
89
  klass = RePipeline
90
90
  @re_pipelines = klass.find(:all)
91
91
 
92
- if @re_pipelines.any? { | re_pipeline| !re_pipeline.valid? }
92
+ if @re_pipelines.any? { | re_pipeline| re_pipeline.pipeline_error }
93
93
  flash[:error] = 'Cannot Activate Pipelines.'
94
94
  else
95
95
  @re_pipelines.each do |re_pipeline|
@@ -109,8 +109,12 @@ class RePipelinesController < ApplicationController
109
109
  end
110
110
 
111
111
  def activate
112
- @re_pipeline.activate!
113
- flash[:success] = 'Pipeline Activated.'
112
+ if @re_pipeline.pipeline_error
113
+ flash[:error] = 'Cannot Activate Pipelines.'
114
+ else
115
+ @re_pipeline.activate!
116
+ flash[:success] = 'Pipeline Activated.'
117
+ end
114
118
 
115
119
  respond_to do |format|
116
120
  format.html do
@@ -40,7 +40,13 @@ class ReJob < ActiveRecord::Base
40
40
  'start_date' => job_audit.audit_date,
41
41
  'start_data' => job_audit.audit_message,
42
42
  })
43
- end
43
+ else
44
+ result.merge!({
45
+ 'start_date' => Time.parse(result['job_date']).utc,
46
+ 'start_data' => ""
47
+ })
48
+ end
49
+
44
50
 
45
51
  if result['job_status'].to_i != ReJob::JOB_STATUS_RUNNING
46
52
  job_audit = ReJobAudit.find(:all, :conditions => ["re_job_id = ?", result['job_id']], :order => "audit_date DESC", :limit => 1).first
@@ -4,12 +4,12 @@ class RePipelineActivated < RePipelineBase
4
4
  def self.find_by_code(code)
5
5
  return find_by_code_without_caching(code) unless RulesEngine::Cache.perform_caching?
6
6
 
7
- code.gsub!(/[^a-zA-Z0-9]+/i, '_')
8
- re_pipeline = RulesEngine::Cache.cache_store.read("activated_pipeline_#{code}")
7
+ cache_code = code.gsub(/[^a-zA-Z0-9]+/i, '_')
8
+ re_pipeline = RulesEngine::Cache.cache_store.read("activated_pipeline_#{cache_code}")
9
9
  if (re_pipeline.nil?)
10
- re_pipeline = find_by_code_without_caching(code)
10
+ re_pipeline = find_by_code_without_caching(cache_code)
11
11
 
12
- RulesEngine::Cache.cache_store.write("activated_pipeline_#{code}", re_pipeline)
12
+ RulesEngine::Cache.cache_store.write("activated_pipeline_#{cache_code}", re_pipeline)
13
13
  end
14
14
 
15
15
  re_pipeline
@@ -22,8 +22,8 @@ class RePipelineActivated < RePipelineBase
22
22
  def self.reset_cache(code)
23
23
  return unless RulesEngine::Cache.perform_caching?
24
24
 
25
- code.gsub!(/[^a-zA-Z0-9]+/i, '_')
26
- RulesEngine::Cache.cache_store.delete("activated_pipeline_#{code}")
25
+ cache_code = code.gsub(/[^a-zA-Z0-9]+/i, '_')
26
+ RulesEngine::Cache.cache_store.delete("activated_pipeline_#{cache_code}")
27
27
  end
28
28
 
29
29
  end
@@ -52,12 +52,7 @@ class RePipelineBase < ActiveRecord::Base
52
52
 
53
53
  def pipeline_error
54
54
  return 'rules required' if re_rules.empty?
55
-
56
- re_rules.each do |re_rule|
57
- error = re_rule.rule_error
58
- return error unless error.blank?
59
- end
60
-
55
+ return 'error within rules' if re_rules.any? { | re_rule | re_rule.rule_error }
61
56
  nil
62
57
  end
63
58
 
@@ -4,7 +4,7 @@ class ReRule < ActiveRecord::Base
4
4
 
5
5
  has_many :re_rule_expected_outcomes, :dependent => :destroy, :order => "outcome ASC"
6
6
  has_many :re_job_audits
7
-
7
+
8
8
  validates_associated :re_pipeline
9
9
  validates_presence_of :rule_class_name
10
10
 
@@ -86,16 +86,16 @@ class ReRule < ActiveRecord::Base
86
86
 
87
87
  def rule_error
88
88
  return "#{title} class #{rule_class_name} invalid" if rule.nil?
89
- return "#{title} invalid" unless rule.valid?
89
+ return "#{rule.errors.values.join(', ')}" unless rule.valid?
90
90
 
91
91
  re_rule_expected_outcomes.each do |re_rule_expected_outcome|
92
92
  next if re_rule_expected_outcome.pipeline_code.blank?
93
93
 
94
- re_pipeline_activated = RePipelineActivated.find_by_code(re_rule_expected_outcome.pipeline_code)
95
- return "#{re_rule_expected_outcome.pipeline_code} not activated" if re_pipeline_activated.nil?
94
+ re_pipeline = RePipeline.find_by_code(re_rule_expected_outcome.pipeline_code)
95
+ return "#{re_rule_expected_outcome.pipeline_code} missing" if re_pipeline.nil?
96
96
 
97
- pipeline_error = re_pipeline_activated.pipeline_error
98
- return "#{re_rule_expected_outcome.pipeline_code} invalid" unless re_pipeline_activated.pipeline_error.blank?
97
+ pipeline_error = re_pipeline.pipeline_error
98
+ return "#{re_rule_expected_outcome.pipeline_code} invalid" unless re_pipeline.pipeline_error.blank?
99
99
  end
100
100
 
101
101
  nil
@@ -4,7 +4,6 @@
4
4
  <tr class="<%= cycle('', 'odd') %>">
5
5
  <td class="no-border-right">
6
6
  <%
7
- job_date = re_job['start_date']
8
7
  case re_job['job_status'].to_i
9
8
  when ReJob::JOB_STATUS_NONE, ReJob::JOB_STATUS_RUNNING
10
9
  job_class = 'job-running'
@@ -23,7 +22,7 @@
23
22
  <td class="no-border-left text-right">
24
23
  <a class="re-job-detail" href='#<%= re_job['job_id'] %>'>
25
24
  <div>
26
- <%= job_date.strftime('%d %b %Y - %H:%M:%S') %>
25
+ <%= re_job['start_date'].strftime('%d %b %Y - %H:%M:%S') %>
27
26
  </div>
28
27
  </a>
29
28
  </td>
@@ -10,8 +10,7 @@
10
10
  <div class="span-6 <%= local_new_row ? 'left-20' : 'left-10' %> re-rule-show">
11
11
  <div class="<%= re_rule_error.blank? ? 're-bluebox' : 're-redbox' %> re-rule-status-<%= re_rule_error.blank? ? 'valid' : 'verify' %>"><%= re_rule.title %></div>
12
12
  <div class="<%= re_rule_error.blank? ? 're-bluebox' : 're-redbox' %> no-top">
13
- <p class="top-5"><%= re_rule.summary %></p>
14
-
13
+ <p class="top-5"><%= re_rule.summary %></p>
15
14
  <div class="top-10 float-right">
16
15
  <% if re_rule.re_rule_expected_outcomes.empty? %>
17
16
  <div class="re-rule-continue">Continue</div>
@@ -7,6 +7,7 @@
7
7
  <h3 class="float-left"><%= re_rule.title %></h3>
8
8
  <div class="float-right">
9
9
  <!-- NO ACTIONS ON THE RULE -->
10
+ <p class="red smalltext"><%= re_rule_error %></p>
10
11
  </div>
11
12
  <div class="clear"></div>
12
13
  </div>
@@ -4,12 +4,12 @@
4
4
  <%= link_to("Edit Pipeline Details", "##{@re_pipeline.id}", :id => "re_pipeline_edit") %>
5
5
  </h3>
6
6
 
7
- <% if changed_status == RePipelineBase::CHANGED_STATUS_DRAFT %>
7
+ <% if changed_status == RePipelineBase::CHANGED_STATUS_DRAFT && !@re_pipeline.pipeline_error %>
8
8
  <h3 class="re-pipeline-activate float-left clear">
9
9
  <%= link_to("Activate Pipeline", "##{@re_pipeline.id}", :id => "re_pipeline_activate") %>
10
10
  </h3>
11
11
  <% end %>
12
- <% if changed_status == RePipelineBase::CHANGED_STATUS_CHANGED %>
12
+ <% if changed_status == RePipelineBase::CHANGED_STATUS_CHANGED && !@re_pipeline.pipeline_error %>
13
13
  <h3 class="re-pipeline-activate float-left clear">
14
14
  <%= link_to("Activate Pipeline Changes", "##{@re_pipeline.id}", :id => "re_pipeline_activate") %>
15
15
  </h3>
@@ -0,0 +1,16 @@
1
+ desc "run a rules pipeline with the complex rule"
2
+ task :rules_engine => :environment do
3
+
4
+ if ENV['re_pipeline_code'].blank?
5
+ raise "usage: rake rules_engine re_pipeline_code=[pipeline code] re_param='[value]'"
6
+ end
7
+
8
+ data = ENV.inject({}){ |data, value| data[value[0].sub(/^re_/, '').to_sym] = value[1] if value[0] =~ /^re_/; data }
9
+
10
+ job = RulesEngine::Job.create
11
+ # job = RulesEngine::Job.open(job.re_job.id)
12
+
13
+ result = job.run(data[:pipeline_code], data)
14
+
15
+ puts "rule completed : data = #{data.inspect}"
16
+ end
@@ -269,10 +269,10 @@ describe RePipelinesController do
269
269
 
270
270
  before do
271
271
  @re_pipeline_1 = mock_model(RePipeline)
272
- @re_pipeline_1.stub!(:valid?).and_return(true)
272
+ @re_pipeline_1.stub!(:pipeline_error).and_return(nil)
273
273
  @re_pipeline_1.stub!(:activate!)
274
274
  @re_pipeline_2 = mock_model(RePipeline)
275
- @re_pipeline_2.stub!(:valid?).and_return(true)
275
+ @re_pipeline_2.stub!(:pipeline_error).and_return(nil)
276
276
  @re_pipeline_2.stub!(:activate!)
277
277
  RePipeline.stub!(:find).and_return([@re_pipeline_1, @re_pipeline_2])
278
278
  end
@@ -283,7 +283,7 @@ describe RePipelinesController do
283
283
  assigns[:re_pipelines].should == [@re_pipeline_1, @re_pipeline_2]
284
284
  end
285
285
 
286
- describe "all of the pipelines are valid" do
286
+ describe "no errors in the pipelines" do
287
287
  it "should activate all of the re_pipeline" do
288
288
  @re_pipeline_1.should_receive(:activate!)
289
289
  @re_pipeline_2.should_receive(:activate!)
@@ -296,15 +296,15 @@ describe RePipelinesController do
296
296
  end
297
297
  end
298
298
 
299
- describe "one of the pipelines is invalid" do
299
+ describe "one of the pipelines has errors" do
300
300
  before(:each) do
301
- @re_pipeline_2.stub!(:valid?).and_return(false)
302
- @re_pipeline_2.stub!(:valid?).and_return(false)
301
+ @re_pipeline_2.stub!(:pipeline_error).and_return("you bet")
302
+ @re_pipeline_2.stub!(:pipeline_error).and_return("you bet")
303
303
  end
304
304
 
305
305
  it "should stop checking at the first invalid pipeline" do
306
- @re_pipeline_1.should_receive(:valid?).and_return(false)
307
- @re_pipeline_2.should_not_receive(:valid?)
306
+ @re_pipeline_1.should_receive(:pipeline_error).and_return("you bet")
307
+ @re_pipeline_2.should_not_receive(:pipeline_error)
308
308
  put :activate_all
309
309
  end
310
310
 
@@ -336,7 +336,8 @@ describe RePipelinesController do
336
336
 
337
337
  before do
338
338
  @re_pipeline = mock_model(RePipeline)
339
- @re_pipeline.stub!(:activate!)
339
+ @re_pipeline.stub!(:pipeline_error).and_return(nil)
340
+ @re_pipeline.stub!(:activate!)
340
341
  RePipeline.stub!(:find).and_return(@re_pipeline)
341
342
  end
342
343
 
@@ -346,14 +347,32 @@ describe RePipelinesController do
346
347
  assigns[:re_pipeline].should == @re_pipeline
347
348
  end
348
349
 
349
- it "should activate the re_pipeline" do
350
- @re_pipeline.should_receive(:activate!)
351
- put :activate, :id => 123
352
- end
350
+ describe "the pipeline is valid" do
351
+ it "should activate the re_pipeline" do
352
+ @re_pipeline.should_receive(:activate!)
353
+ put :activate, :id => 123
354
+ end
353
355
 
354
- it "should display a flash success message" do
355
- put :activate, :id => 123
356
- flash[:success].should_not be_blank
356
+ it "should display a flash success message" do
357
+ put :activate, :id => 123
358
+ flash[:success].should_not be_blank
359
+ end
360
+ end
361
+
362
+ describe "the pipeline is invalid" do
363
+ before(:each) do
364
+ @re_pipeline.stub!(:pipeline_error).and_return("you bet")
365
+ end
366
+
367
+ it "should not activate the pipeline" do
368
+ @re_pipeline.should_not_receive(:activate!)
369
+ put :activate, :id => 123
370
+ end
371
+
372
+ it "should display a flash error message" do
373
+ put :activate, :id => 123
374
+ flash[:error].should_not be_blank
375
+ end
357
376
  end
358
377
 
359
378
  it "should redirect to the change re_pipeline page for HTML" do
@@ -475,5 +494,4 @@ describe RePipelinesController do
475
494
  end
476
495
  end
477
496
 
478
-
479
497
  end
@@ -24,31 +24,31 @@ describe RePipelineBase do
24
24
  end
25
25
 
26
26
  it "should replace any nonprint cahracters with an _" do
27
- src = RePipelineBase.new(valid_attributes.merge(:code => "my code"))
28
- src.save!
29
- src.code.should == "my_code"
27
+ re_pipeline = RePipelineBase.new(valid_attributes.merge(:code => "my code"))
28
+ re_pipeline.save!
29
+ re_pipeline.code.should == "my_code"
30
30
  end
31
31
 
32
32
 
33
33
  it "should change the code to lower case when creating" do
34
- src = RePipelineBase.new(valid_attributes.merge(:code => "My code"))
35
- src.save!
36
- src.code.should == "my_code"
34
+ re_pipeline = RePipelineBase.new(valid_attributes.merge(:code => "My code"))
35
+ re_pipeline.save!
36
+ re_pipeline.code.should == "my_code"
37
37
  end
38
38
 
39
39
  describe "code cannot be changed after creation" do
40
40
  it "should save the code with a new record" do
41
- src = RePipelineBase.new(valid_attributes.merge(:code => "my code"))
42
- src.save!
43
- src.code.should == "my_code"
41
+ re_pipeline = RePipelineBase.new(valid_attributes.merge(:code => "my code"))
42
+ re_pipeline.save!
43
+ re_pipeline.code.should == "my_code"
44
44
  end
45
45
 
46
46
  it "should ignore the code attribute for an existing record" do
47
- src = RePipelineBase.new(valid_attributes.merge(:code => "my code"))
48
- src.save!
49
- src.code = "new_code"
50
- src.save!
51
- src.code.should == "my_code"
47
+ re_pipeline = RePipelineBase.new(valid_attributes.merge(:code => "my code"))
48
+ re_pipeline.save!
49
+ re_pipeline.code = "new_code"
50
+ re_pipeline.save!
51
+ re_pipeline.code.should == "my_code"
52
52
  end
53
53
  end
54
54
 
@@ -103,8 +103,8 @@ describe RePipelineBase do
103
103
  @re_pipeline_2 = RePipeline.new(valid_attributes)
104
104
  @re_pipeline_1.stub!(:re_rules).and_return([@rule_1, @rule_2])
105
105
  @re_pipeline_2.stub!(:re_rules).and_return([@rule_1, @rule_2])
106
-
107
106
  end
107
+
108
108
  it "should not compare the rules if the the number is different" do
109
109
  @re_pipeline_2.stub!(:re_rules).and_return([@rule_1])
110
110
 
@@ -155,10 +155,10 @@ describe RePipelineBase do
155
155
  end
156
156
 
157
157
  it "should stop on the first rule error" do
158
- @re_rule1.should_receive(:rule_error).at_least(:once).and_return("invalid rule")
158
+ @re_rule1.should_receive(:rule_error).at_least(:once).and_return("oops")
159
159
  @re_rule2.should_not_receive(:rule)
160
160
 
161
- @re_pipeline.pipeline_error.should == "invalid rule"
161
+ @re_pipeline.pipeline_error.should == "error within rules"
162
162
  end
163
163
  end
164
164
  end
@@ -318,30 +318,23 @@ describe ReRule do
318
318
  @re_rule.rule_error.should be_nil
319
319
  end
320
320
 
321
- it "should validate the rule is present and activated" do
321
+ it "should validate the pipeline is present and activated" do
322
322
  re_rule_expected_outcome = mock_model(ReRuleExpectedOutcome, :pipeline_code => "mock_pipeline_code", :outcome => RulesEngine::RuleOutcome::OUTCOME_START_PIPELINE)
323
- RePipelineActivated.should_receive(:find_by_code).and_return(mock("RePipelineActivated", :pipeline_error => nil))
323
+ RePipeline.should_receive(:find_by_code).and_return(mock("RePipeline", :pipeline_error => nil))
324
324
  @re_rule.stub!(:re_rule_expected_outcomes).and_return([re_rule_expected_outcome])
325
325
  @re_rule.rule_error.should be_nil
326
326
  end
327
327
 
328
- it "should return '[pipeline_code] not activated' if the required pipeline is missing" do
328
+ it "should return '[pipeline_code] missing' if the required pipeline is missing" do
329
329
  re_rule_expected_outcome = mock_model(ReRuleExpectedOutcome, :pipeline_code => "mock_pipeline_code", :outcome => RulesEngine::RuleOutcome::OUTCOME_START_PIPELINE)
330
- RePipelineActivated.should_receive(:find_by_code).and_return(nil)
330
+ RePipeline.should_receive(:find_by_code).and_return(nil)
331
331
  @re_rule.stub!(:re_rule_expected_outcomes).and_return([re_rule_expected_outcome])
332
- @re_rule.rule_error.should == "mock_pipeline_code not activated"
333
- end
334
-
335
- it "should return '[pipeline_code] not activated' if the required pipeline has not been activated" do
336
- re_rule_expected_outcome = mock_model(ReRuleExpectedOutcome, :pipeline_code => "mock_pipeline_code", :outcome => RulesEngine::RuleOutcome::OUTCOME_START_PIPELINE)
337
- RePipelineActivated.should_receive(:find_by_code).and_return(nil)
338
- @re_rule.stub!(:re_rule_expected_outcomes).and_return([re_rule_expected_outcome])
339
- @re_rule.rule_error.should == "mock_pipeline_code not activated"
332
+ @re_rule.rule_error.should == "mock_pipeline_code missing"
340
333
  end
341
334
 
342
335
  it "should return '[pipeline_code] invalid' if the required pipeline has errors" do
343
336
  re_rule_expected_outcome = mock_model(ReRuleExpectedOutcome, :pipeline_code => "mock_pipeline_code", :outcome => RulesEngine::RuleOutcome::OUTCOME_START_PIPELINE)
344
- RePipelineActivated.should_receive(:find_by_code).and_return(mock("RePipelineActivated", :pipeline_error => "pipeline error"))
337
+ RePipeline.should_receive(:find_by_code).and_return(mock("RePipeline", :pipeline_error => "pipeline error"))
345
338
  @re_rule.stub!(:re_rule_expected_outcomes).and_return([re_rule_expected_outcome])
346
339
  @re_rule.rule_error.should == "mock_pipeline_code invalid"
347
340
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rules_engine
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 6
10
- version: 0.0.6
9
+ - 7
10
+ version: 0.0.7
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-06-23 00:00:00 +10:00
18
+ date: 2010-06-24 00:00:00 +10:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -159,7 +159,7 @@ files:
159
159
  - rails_generators/templates/features/step_definitions/common/re_view_steps.rb
160
160
  - rails_generators/templates/features/support/blueprint_re_pipelines.rb
161
161
  - rails_generators/templates/features/support/rules_engine.rb
162
- - rails_generators/templates/lib/tasks/re_execute.rake
162
+ - rails_generators/templates/lib/tasks/rules_engine.rake
163
163
  - rails_generators/templates/public/javascripts/jquery-1.4.2.min.js
164
164
  - rails_generators/templates/public/javascripts/jquery.autocomplete.pack.js
165
165
  - rails_generators/templates/public/javascripts/jquery.blockUI.js
@@ -1,19 +0,0 @@
1
- namespace :re do
2
-
3
- desc "run a rules pipeline with the complex rule"
4
- task :execute => :environment do
5
-
6
- if ENV['re_pipeline_code'].blank?
7
- raise "usage: rake re:execute re_pipeline_code=[pipeline code] re_param='[value]'"
8
- end
9
-
10
- data = ENV.inject({}){ |data, value| data[value[0].sub(/^re_/, '').to_sym] = value[1] if value[0] =~ /^re_/; data }
11
-
12
- job = RulesEngine::Job.create
13
- # job = RulesEngine::Job.open(job.re_job.id)
14
-
15
- result = job.run(data[:pipeline_code], data)
16
-
17
- puts "rule completed : data = #{data.inspect}"
18
- end
19
- end