after_commit_action 1.0.0 → 1.0.1

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: 7098526c08593ab256447fbe799f786c877e4831
4
- data.tar.gz: c090670e06e2edc562ffea54df197ffd9f947abb
3
+ metadata.gz: 9222b7ce5f9538d3823646319cdfd4a0a005d918
4
+ data.tar.gz: f6eca3b15daccf6681d58cc9dbcaf5e8bc8a53f8
5
5
  SHA512:
6
- metadata.gz: a89dfaec4db205f167749d6d8b49c9a419352c9ef70f7f2fb4c89c118e55c50a7539dd391ea25147ff2c3982b067860160ac6e7de97f1503336a01f0a41f8688
7
- data.tar.gz: 2505e04c3e9dc9e18263180925be6d8617d1b936adc8066e698a05e9eb6113e814fc93c62bb84ebfceca3294390a99d9dc42f749b3f9a0280da5ec4b9b0d242c
6
+ metadata.gz: 180205c0f74beb5fa377322dee5f68a2b748fb9301c35f1038c802ba6b74a82519427befb2477cd87b38b7269d07396c7e36ee5080fe189aa59fc4cd7b936c37
7
+ data.tar.gz: 40a229846a306df184fa56a573592500a43f6058dad311b0bdb6a208821634a4b7d7a30b75acc7d781f914b86770d401f993fbeac24d386dbfacc53b9e82f998
data/Gemfile CHANGED
@@ -3,13 +3,19 @@ source "http://rubygems.org"
3
3
  gem "activerecord", ">= 3.0.0"
4
4
  gem "activesupport", ">= 3.0.0"
5
5
 
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development, :test do
9
+ gem "rails"
10
+ end
11
+
6
12
  group :development do
7
13
  gem "rdoc", "~> 3.12"
8
14
  gem "bundler", ">= 1.1.3"
9
15
  gem "jeweler", "~> 2.0.1"
10
16
  end
11
17
 
12
- group :test do
18
+ group :development, :test do
13
19
  gem "rspec", "~> 2.8.0"
14
20
  gem "sqlite3"
15
21
  gem "rspec-extra-formatters"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.0.1
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: after_commit_action 1.0.0 ruby lib
5
+ # stub: after_commit_action 1.0.1 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "after_commit_action"
9
- s.version = "1.0.0"
9
+ s.version = "1.0.1"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["BestVendor"]
14
- s.date = "2015-03-07"
14
+ s.date = "2016-01-13"
15
15
  s.description = "Use this module to defer actions to the after-commit hook. This is useful if you want to trigger actions in after_create, after_destroy and after_update callbacks but want to execute them outside of the transaction (for example, to avoid deadlocks)."
16
16
  s.email = "magnus@bestvendor.com"
17
17
  s.extra_rdoc_files = [
@@ -23,7 +23,6 @@ Gem::Specification.new do |s|
23
23
  ".rspec",
24
24
  ".rvmrc",
25
25
  "Gemfile",
26
- "Gemfile.lock",
27
26
  "LICENSE.txt",
28
27
  "README.md",
29
28
  "Rakefile",
@@ -33,6 +32,7 @@ Gem::Specification.new do |s|
33
32
  "lib/after_commit_action.rb",
34
33
  "spec/after_commit_action_spec.rb",
35
34
  "spec/config/database.yml",
35
+ "spec/models/another_model.rb",
36
36
  "spec/models/tester.rb",
37
37
  "spec/rails_app/.gitignore",
38
38
  "spec/rails_app/Gemfile",
@@ -87,7 +87,7 @@ Gem::Specification.new do |s|
87
87
  ]
88
88
  s.homepage = "http://github.com/magnusvk/after_commit_action"
89
89
  s.licenses = ["MIT"]
90
- s.rubygems_version = "2.4.3"
90
+ s.rubygems_version = "2.2.2"
91
91
  s.summary = "Easily defer blocks of code to the after-commit action of an ActiveRecord model."
92
92
 
93
93
  if s.respond_to? :specification_version then
@@ -96,22 +96,34 @@ Gem::Specification.new do |s|
96
96
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
97
97
  s.add_runtime_dependency(%q<activerecord>, [">= 3.0.0"])
98
98
  s.add_runtime_dependency(%q<activesupport>, [">= 3.0.0"])
99
+ s.add_development_dependency(%q<rails>, [">= 0"])
99
100
  s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
100
101
  s.add_development_dependency(%q<bundler>, [">= 1.1.3"])
101
102
  s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
103
+ s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
104
+ s.add_development_dependency(%q<sqlite3>, [">= 0"])
105
+ s.add_development_dependency(%q<rspec-extra-formatters>, [">= 0"])
102
106
  else
103
107
  s.add_dependency(%q<activerecord>, [">= 3.0.0"])
104
108
  s.add_dependency(%q<activesupport>, [">= 3.0.0"])
109
+ s.add_dependency(%q<rails>, [">= 0"])
105
110
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
106
111
  s.add_dependency(%q<bundler>, [">= 1.1.3"])
107
112
  s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
113
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
114
+ s.add_dependency(%q<sqlite3>, [">= 0"])
115
+ s.add_dependency(%q<rspec-extra-formatters>, [">= 0"])
108
116
  end
109
117
  else
110
118
  s.add_dependency(%q<activerecord>, [">= 3.0.0"])
111
119
  s.add_dependency(%q<activesupport>, [">= 3.0.0"])
120
+ s.add_dependency(%q<rails>, [">= 0"])
112
121
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
113
122
  s.add_dependency(%q<bundler>, [">= 1.1.3"])
114
123
  s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
124
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
125
+ s.add_dependency(%q<sqlite3>, [">= 0"])
126
+ s.add_dependency(%q<rspec-extra-formatters>, [">= 0"])
115
127
  end
116
128
  end
117
129
 
@@ -17,6 +17,12 @@ module AfterCommitAction
17
17
  end
18
18
 
19
19
  def execute_after_commit(&block)
20
+ if ActiveRecord::Base.connection.open_transactions == 0
21
+ return block.call
22
+ else
23
+ ActiveRecord::Base.connection.add_transaction_record(self)
24
+ end
25
+
20
26
  @_execute_after_commit ||= []
21
27
  @_execute_after_commit<< block
22
28
  end
@@ -1,6 +1,7 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  require 'models/tester'
4
+ require 'models/another_model'
4
5
 
5
6
  describe "AfterCommitAction" do
6
7
  it "should correctly execute tasks after commit" do
@@ -18,4 +19,23 @@ describe "AfterCommitAction" do
18
19
  t.array.should include('before_update')
19
20
  t.array.should include('after_update')
20
21
  end
22
+
23
+ context 'when block is executed in another model transaction' do
24
+ let(:tester) { Tester.create count: 0 }
25
+ let(:another_model) { AnotherModel.new tester: tester }
26
+
27
+ subject {}
28
+
29
+ it "increments the counter" do
30
+ expect { another_model.save! }.to change { tester.reload.count }.from(0).to 1
31
+ end
32
+ end
33
+
34
+ context 'when there is no transaction' do
35
+ let(:tester) { Tester.create count: 0 }
36
+
37
+ it "increments the counter" do
38
+ expect { tester.increment_counter }.to change { tester.reload.count }.from(0).to 1
39
+ end
40
+ end
21
41
  end
@@ -0,0 +1,11 @@
1
+ class AnotherModel < ActiveRecord::Base
2
+ include AfterCommitAction
3
+
4
+ belongs_to :tester
5
+
6
+ after_save :increment_tester_counter
7
+
8
+ def increment_tester_counter
9
+ tester.increment_counter
10
+ end
11
+ end
@@ -29,4 +29,8 @@ class Tester < ActiveRecord::Base
29
29
  def after_update
30
30
  execute_after_commit { @array<< 'after_update' }
31
31
  end
32
+
33
+ def increment_counter
34
+ execute_after_commit { increment! :count }
35
+ end
32
36
  end
@@ -15,6 +15,11 @@ ActiveRecord::Schema.define(:version => 20120522160158) do
15
15
 
16
16
  create_table "testers", :force => true do |t|
17
17
  t.string "name"
18
+ t.integer "count", :default => 0
19
+ end
20
+
21
+ create_table "another_models", :force => true do |t|
22
+ t.string "tester_id"
18
23
  end
19
24
 
20
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: after_commit_action
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - BestVendor
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-07 00:00:00.000000000 Z
11
+ date: 2016-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: 3.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rdoc
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +94,48 @@ dependencies:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
96
  version: 2.0.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 2.8.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 2.8.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: sqlite3
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rspec-extra-formatters
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
83
139
  description: Use this module to defer actions to the after-commit hook. This is useful
84
140
  if you want to trigger actions in after_create, after_destroy and after_update callbacks
85
141
  but want to execute them outside of the transaction (for example, to avoid deadlocks).
@@ -94,7 +150,6 @@ files:
94
150
  - ".rspec"
95
151
  - ".rvmrc"
96
152
  - Gemfile
97
- - Gemfile.lock
98
153
  - LICENSE.txt
99
154
  - README.md
100
155
  - Rakefile
@@ -104,6 +159,7 @@ files:
104
159
  - lib/after_commit_action.rb
105
160
  - spec/after_commit_action_spec.rb
106
161
  - spec/config/database.yml
162
+ - spec/models/another_model.rb
107
163
  - spec/models/tester.rb
108
164
  - spec/rails_app/.gitignore
109
165
  - spec/rails_app/Gemfile
@@ -175,7 +231,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
175
231
  version: '0'
176
232
  requirements: []
177
233
  rubyforge_project:
178
- rubygems_version: 2.4.3
234
+ rubygems_version: 2.2.2
179
235
  signing_key:
180
236
  specification_version: 4
181
237
  summary: Easily defer blocks of code to the after-commit action of an ActiveRecord
@@ -1,90 +0,0 @@
1
- GEM
2
- remote: http://rubygems.org/
3
- specs:
4
- activemodel (4.2.0)
5
- activesupport (= 4.2.0)
6
- builder (~> 3.1)
7
- activerecord (4.2.0)
8
- activemodel (= 4.2.0)
9
- activesupport (= 4.2.0)
10
- arel (~> 6.0)
11
- activesupport (4.2.0)
12
- i18n (~> 0.7)
13
- json (~> 1.7, >= 1.7.7)
14
- minitest (~> 5.1)
15
- thread_safe (~> 0.3, >= 0.3.4)
16
- tzinfo (~> 1.1)
17
- addressable (2.3.6)
18
- arel (6.0.0)
19
- builder (3.2.2)
20
- descendants_tracker (0.0.4)
21
- thread_safe (~> 0.3, >= 0.3.1)
22
- diff-lcs (1.1.3)
23
- faraday (0.9.0)
24
- multipart-post (>= 1.2, < 3)
25
- git (1.2.8)
26
- github_api (0.12.2)
27
- addressable (~> 2.3)
28
- descendants_tracker (~> 0.0.4)
29
- faraday (~> 0.8, < 0.10)
30
- hashie (>= 3.3)
31
- multi_json (>= 1.7.5, < 2.0)
32
- nokogiri (~> 1.6.3)
33
- oauth2
34
- hashie (3.3.2)
35
- highline (1.6.21)
36
- i18n (0.7.0)
37
- jeweler (2.0.1)
38
- builder
39
- bundler (>= 1.0)
40
- git (>= 1.2.5)
41
- github_api
42
- highline (>= 1.6.15)
43
- nokogiri (>= 1.5.10)
44
- rake
45
- rdoc
46
- json (1.8.1)
47
- jwt (1.2.0)
48
- mini_portile (0.6.1)
49
- minitest (5.5.0)
50
- multi_json (1.10.1)
51
- multi_xml (0.5.5)
52
- multipart-post (2.0.0)
53
- nokogiri (1.6.5)
54
- mini_portile (~> 0.6.0)
55
- oauth2 (1.0.0)
56
- faraday (>= 0.8, < 0.10)
57
- jwt (~> 1.0)
58
- multi_json (~> 1.3)
59
- multi_xml (~> 0.5)
60
- rack (~> 1.2)
61
- rack (1.6.0)
62
- rake (10.4.2)
63
- rdoc (3.12.2)
64
- json (~> 1.4)
65
- rspec (2.8.0)
66
- rspec-core (~> 2.8.0)
67
- rspec-expectations (~> 2.8.0)
68
- rspec-mocks (~> 2.8.0)
69
- rspec-core (2.8.0)
70
- rspec-expectations (2.8.0)
71
- diff-lcs (~> 1.1.2)
72
- rspec-extra-formatters (1.0.0)
73
- rspec-mocks (2.8.0)
74
- sqlite3 (1.3.10)
75
- thread_safe (0.3.4)
76
- tzinfo (1.2.2)
77
- thread_safe (~> 0.1)
78
-
79
- PLATFORMS
80
- ruby
81
-
82
- DEPENDENCIES
83
- activerecord (>= 3.0.0)
84
- activesupport (>= 3.0.0)
85
- bundler (>= 1.1.3)
86
- jeweler (~> 2.0.1)
87
- rdoc (~> 3.12)
88
- rspec (~> 2.8.0)
89
- rspec-extra-formatters
90
- sqlite3