triggerable 0.1.3 → 0.1.4
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.
- checksums.yaml +4 -4
- data/lib/triggerable/conditions/schedule/after.rb +13 -7
- data/lib/triggerable/conditions/schedule/before.rb +12 -7
- data/lib/triggerable/conditions/schedule/schedule_condition.rb +0 -7
- data/lib/triggerable/rules/automation.rb +1 -1
- data/lib/triggerable/version.rb +1 -1
- data/spec/integration/automations_spec.rb +4 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9689f441a8bf248c604c1a93480e52ae104c3770
|
4
|
+
data.tar.gz: b4642f6342c5e5c30b1fac31b707ead0162c2b41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1e76b55c3810ab112eaf7a2148227f0525333608c8c7064c827bd650b4fdf87db4bfd763c1206beded0d19f8b3b85cf80523cbe71eef3cf86f36066d6ddc167
|
7
|
+
data.tar.gz: cf4d50158a00bc4f9291b3d03fa19d44b7818176516ff010d19533b6b203517ed67c00f38a9c45aea478ca65661013b800a48749f05425b6da51b3e95c93a300
|
@@ -14,14 +14,20 @@ module Conditions
|
|
14
14
|
end
|
15
15
|
|
16
16
|
private
|
17
|
-
def condition
|
18
|
-
return super if @math_condition.blank?
|
19
17
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
18
|
+
def condition
|
19
|
+
if @math_condition.blank?
|
20
|
+
And.new [
|
21
|
+
GreaterThan.new(@field, from),
|
22
|
+
LessThanOrEqualTo.new(@field, to)
|
23
|
+
]
|
24
|
+
else
|
25
|
+
case @math_condition
|
26
|
+
when :greater_than
|
27
|
+
LessThanOrEqualTo.new(@field, from)
|
28
|
+
when :less_than
|
29
|
+
GreaterThanOrEqualTo.new(@field, from)
|
30
|
+
end
|
25
31
|
end
|
26
32
|
end
|
27
33
|
end
|
@@ -22,13 +22,18 @@ module Conditions
|
|
22
22
|
|
23
23
|
private
|
24
24
|
def condition
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
25
|
+
if @math_condition.blank?
|
26
|
+
And.new [
|
27
|
+
GreaterThanOrEqualTo.new(@field, from),
|
28
|
+
LessThan.new(@field, to)
|
29
|
+
]
|
30
|
+
else
|
31
|
+
case @math_condition
|
32
|
+
when :greater_than
|
33
|
+
And.new([GreaterThanOrEqualTo.new(@field, from), LessThan.new(@field, to)])
|
34
|
+
when :less_than
|
35
|
+
GreaterThanOrEqualTo.new(@field, from)
|
36
|
+
end
|
32
37
|
end
|
33
38
|
end
|
34
39
|
end
|
@@ -4,7 +4,7 @@ module Rules
|
|
4
4
|
table = Arel::Table.new(model.table_name)
|
5
5
|
scope = @condition.scope(table)
|
6
6
|
query = table.where(scope).project(Arel.sql('id')).to_sql
|
7
|
-
ids =
|
7
|
+
ids = ActiveRecord::Base.connection.execute(query).map { |r| r['id'] }
|
8
8
|
models = model.where(id: ids)
|
9
9
|
|
10
10
|
models.each {|object| actions.each {|a| a.run_for!(object, name)} }
|
data/lib/triggerable/version.rb
CHANGED
@@ -22,7 +22,7 @@ describe 'Automations' do
|
|
22
22
|
Engine.run_automations(1.hour)
|
23
23
|
expect(TestTask.count).to eq(1)
|
24
24
|
|
25
|
-
constantize_time_now Time.utc 2012, 9, 2,
|
25
|
+
constantize_time_now Time.utc 2012, 9, 2, 12, 00
|
26
26
|
Engine.run_automations(1.hour)
|
27
27
|
|
28
28
|
expect(TestTask.count).to eq(2)
|
@@ -52,7 +52,7 @@ describe 'Automations' do
|
|
52
52
|
end
|
53
53
|
|
54
54
|
it 'after 30 mins with 30 mins interval' do
|
55
|
-
constantize_time_now Time.utc 2012, 9, 1,
|
55
|
+
constantize_time_now Time.utc 2012, 9, 1, 12, 00
|
56
56
|
|
57
57
|
TestTask.automation if: {and: [{updated_at: {after: 30.minutes}}, {status: {is: :solved}}, {kind: {is: :service}}]} do
|
58
58
|
TestTask.create kind: 'follow up'
|
@@ -63,11 +63,11 @@ describe 'Automations' do
|
|
63
63
|
task.update_attributes status: 'solved', kind: 'service'
|
64
64
|
expect(TestTask.count).to eq(1)
|
65
65
|
|
66
|
-
constantize_time_now Time.utc 2012, 9, 1, 12,
|
66
|
+
constantize_time_now Time.utc 2012, 9, 1, 12, 29
|
67
67
|
Engine.run_automations(30.minutes)
|
68
68
|
expect(TestTask.count).to eq(1)
|
69
69
|
|
70
|
-
constantize_time_now Time.utc 2012, 9, 1, 12,
|
70
|
+
constantize_time_now Time.utc 2012, 9, 1, 12, 30
|
71
71
|
Engine.run_automations(30.minutes)
|
72
72
|
|
73
73
|
expect(TestTask.count).to eq(2)
|