triggerable 0.1.14 → 0.1.15
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/rules/automation.rb +4 -2
 - data/lib/triggerable/version.rb +1 -1
 - data/spec/integration/automations_spec.rb +19 -0
 - data/spec/models.rb +5 -1
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 3a1e847d6791f35c859f400d4a4004461f9e0d9c
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 3e84919f46ac7d801f6239ceb34d7e529fb5f49a
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 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. 
     | 
| 
      
 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
         
     | 
    
        data/lib/triggerable/version.rb
    CHANGED
    
    
| 
         @@ -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. 
     | 
| 
      
 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:  
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2016-02-11 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: bundler
         
     |