triggerable 0.1.16 → 0.1.17

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 028658b0ddf347d856dbeda24c96e39579f4b6c2
4
- data.tar.gz: c7818e0a0a5d22679f6132dba443d7eded262bde
3
+ metadata.gz: 5651abe1358e3baff71006b801a34a74ffd7d4b7
4
+ data.tar.gz: 4f90f9159253400b28a5f91d7688bf7c93847102
5
5
  SHA512:
6
- metadata.gz: 32583ca8a038bb161c9fe4226563b62e2460016fe3645c5340d48a6fe4d05629d1eb197c6b3e58dac994aa1ec20f4f9c28e089335876b2e85c200283e00d4053
7
- data.tar.gz: b2c484e8f0c4c87888c361fdecd2a2decc7d6c77289e56f5cb65f5b71a432a35831cab042e3f397685268afecaaf55a2fff873a3eca096babe5f3183a7332721
6
+ metadata.gz: d4e7b3c021870dc485a0e74f6d5e12deec8eb6f539b67a19b75168db0934afbdd4e447c57530c14fff5589bbd735dfd5574fe5220bd7507649b5ffec2292815e
7
+ data.tar.gz: 638911d10688242663d886676b024f685445c303898fe86fc0a2691cb937552fab616a50eec08256ba8adb447f9c54f61dc2884da136210836b0841778dddcfa
@@ -30,6 +30,18 @@ require "triggerable/actions/lambda_action"
30
30
  module Triggerable
31
31
  extend ActiveSupport::Concern
32
32
 
33
+ def self.enable!
34
+ @disabled = false
35
+ end
36
+
37
+ def self.disable!
38
+ @disabled = true
39
+ end
40
+
41
+ def self.enabled?
42
+ !@disabled
43
+ end
44
+
33
45
  included do
34
46
  CALLBACKS = [
35
47
  :before_create,
@@ -51,6 +63,7 @@ module Triggerable
51
63
  private
52
64
 
53
65
  def run_triggers callback
66
+ return unless Triggerable.enabled?
54
67
  Engine.triggers_for(self, callback).each { |t| t.execute!(self) }
55
68
  true
56
69
  end
@@ -25,6 +25,7 @@ module Triggerable
25
25
 
26
26
  def self.run_automations interval
27
27
  self.interval = interval
28
+ return unless Triggerable.enabled?
28
29
  automations.each(&:execute!)
29
30
  end
30
31
 
@@ -1,3 +1,3 @@
1
1
  module Triggerable
2
- VERSION = '0.1.16'
2
+ VERSION = '0.1.17'
3
3
  end
@@ -38,4 +38,26 @@ describe 'Actions' do
38
38
  expect(TestTask.all[-2].kind).to eq('follow up')
39
39
  expect(TestTask.all.last.kind).to eq('follow up')
40
40
  end
41
+
42
+ describe 'when Triggerable is disabled' do
43
+ before do
44
+ TestTask.trigger on: :after_create,
45
+ if: { status: 'solved' },
46
+ do: :create_follow_up
47
+ end
48
+
49
+ after { Triggerable.enable! }
50
+
51
+ it 'it does not run actions' do
52
+ expect {
53
+ TestTask.create status: 'solved'
54
+ }.to change(TestTask, :count).by(2)
55
+
56
+ Triggerable.disable!
57
+
58
+ expect {
59
+ TestTask.create status: 'solved'
60
+ }.to change(TestTask, :count).by(1)
61
+ end
62
+ end
41
63
  end
@@ -264,4 +264,29 @@ describe 'Automations' do
264
264
  expect(ScopedTestTask.unscoped.count).to eq(2)
265
265
  expect(ScopedTestTask.unscoped.last.kind).to eq('follow up')
266
266
  end
267
+
268
+ context 'when Triggerable is disabled' do
269
+ before do
270
+ TestTask.automation if: {and: [{updated_at: {after: 24.hours}}, {status: {is: :solved}}, {kind: {is: :service}}]} do
271
+ TestTask.create kind: 'follow up'
272
+ end
273
+ end
274
+
275
+ after { Triggerable.enable! }
276
+
277
+ it 'does not run automations' do
278
+ Triggerable.disable!
279
+
280
+ expect {
281
+ constantize_time_now Time.utc 2012, 9, 1, 12, 00
282
+
283
+ task = TestTask.create
284
+ task.update_attributes status: 'solved', kind: 'service'
285
+
286
+ constantize_time_now Time.utc 2012, 9, 2, 12, 00
287
+ Triggerable::Engine.run_automations(1.hour)
288
+
289
+ }.to change(TestTask, :count).by(1)
290
+ end
291
+ end
267
292
  end
@@ -89,4 +89,26 @@ describe 'Short syntax' do
89
89
  task.update_attributes status: 'solved'
90
90
  expect(task.status).to eq('confirmed')
91
91
  end
92
+
93
+ context 'when Triggerable is disabled' do
94
+ before do
95
+ TestTask.trigger on: :after_create, if: {status: ['solved']} do
96
+ TestTask.create kind: 'follow up'
97
+ end
98
+ end
99
+
100
+ after { Triggerable.enable! }
101
+
102
+ it 'does not run actions' do
103
+ expect {
104
+ TestTask.create status: 'solved'
105
+ }.to change(TestTask, :count).by(2)
106
+
107
+ Triggerable.disable!
108
+
109
+ expect {
110
+ TestTask.create status: 'solved'
111
+ }.to change(TestTask, :count).by(1)
112
+ end
113
+ end
92
114
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: triggerable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.16
4
+ version: 0.1.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - DmitryTsepelev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-08 00:00:00.000000000 Z
11
+ date: 2017-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -175,7 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
175
175
  version: '0'
176
176
  requirements: []
177
177
  rubyforge_project:
178
- rubygems_version: 2.6.6
178
+ rubygems_version: 2.6.11
179
179
  signing_key:
180
180
  specification_version: 4
181
181
  summary: Triggerable is a powerful engine for adding a conditional behaviour for ActiveRecord