triggerable 0.1.14 → 0.1.15

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: deafcb6fe578aebcc41754cc791cb1ee73660a27
4
- data.tar.gz: 6589f945a4858adfb1be1bd6c127db37804edc79
3
+ metadata.gz: 3a1e847d6791f35c859f400d4a4004461f9e0d9c
4
+ data.tar.gz: 3e84919f46ac7d801f6239ceb34d7e529fb5f49a
5
5
  SHA512:
6
- metadata.gz: b3043f59f893d3d9596ce505c3300d9f825c2970215382e10bf0cc2f5cf87d3a26e623fefd4478a2942bd1b7275d52d1a74692b010af3edd2f242074209b71ce
7
- data.tar.gz: 9370eea0b8dc45d03a14df5141ab4ac5cf694f29934b4adccbd2f757420ecf2640a435699892d8da76bf06a9cba26f3f124c96a780ba43facab2d67bdae04800
6
+ metadata.gz: 44c6eb39c11620c769aefe764a987cae884c7871caba17d137e7b2f4280f51eeb522734363b3c2fe2aab8cee9b8b1cf74157b50639df6900c5e74da7a56f9f1c
7
+ data.tar.gz: 18deb64499de6b211b69775e2add3ef6ce364cd2cbd75d08a7e52a562e95bd9f6dc890afa27e6d49377a2e1ec193877c186ac0a51142a0c4c40c9650cacec068
@@ -6,11 +6,13 @@ module Triggerable
6
6
  def initialize model, options, block
7
7
  super(model, options, block)
8
8
  @pass_relation = options[:pass_relation]
9
+ @unscoped = options[:unscoped]
9
10
  end
10
11
 
11
12
  def execute!
12
13
  ids = ActiveRecord::Base.connection.execute(build_query).map { |r| r['id'] }
13
- models = model.where(id: ids)
14
+ models = @unscoped ? model.unscoped : model
15
+ models = models.where(id: ids)
14
16
 
15
17
  Triggerable::Engine.log(:debug, "#{desc}: processing #{models.count} object(s)")
16
18
 
@@ -43,4 +45,4 @@ module Triggerable
43
45
  end
44
46
  end
45
47
  end
46
- end
48
+ end
@@ -1,3 +1,3 @@
1
1
  module Triggerable
2
- VERSION = '0.1.14'
2
+ VERSION = '0.1.15'
3
3
  end
@@ -245,4 +245,23 @@ describe 'Automations' do
245
245
  task2.reload
246
246
  expect(task2.kind).to eq('other')
247
247
  end
248
+
249
+ it 'should unscope model for automation' do
250
+ constantize_time_now Time.utc 2012, 9, 1, 12, 00
251
+
252
+ ScopedTestTask.automation if: {and: [{updated_at: {after: 24.hours}}, {status: {is: :solved}}, {kind: {is: :service}}]}, unscoped: true do
253
+ ScopedTestTask.create kind: 'follow up'
254
+ end
255
+
256
+ task = ScopedTestTask.create
257
+ expect(ScopedTestTask.unscoped.count).to eq(1)
258
+ task.update_attributes status: 'solved', kind: 'service'
259
+ expect(ScopedTestTask.unscoped.count).to eq(1)
260
+
261
+ constantize_time_now Time.utc 2012, 9, 2, 12, 00
262
+ Triggerable::Engine.run_automations(1.hour)
263
+
264
+ expect(ScopedTestTask.unscoped.count).to eq(2)
265
+ expect(ScopedTestTask.unscoped.last.kind).to eq('follow up')
266
+ end
248
267
  end
data/spec/models.rb CHANGED
@@ -14,10 +14,14 @@ class TestTask < ActiveRecord::Base
14
14
  end
15
15
  end
16
16
 
17
+ class ScopedTestTask < TestTask
18
+ default_scope { where(id: nil) }
19
+ end
20
+
17
21
  class ParentModel < ActiveRecord::Base
18
22
  has_many :child_models
19
23
  end
20
24
 
21
25
  class ChildModel < ActiveRecord::Base
22
26
  belongs_to :parent_model
23
- end
27
+ 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.14
4
+ version: 0.1.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - DmitryTsepelev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-07 00:00:00.000000000 Z
11
+ date: 2016-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler