after_transaction_commit 1.0.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 56c48c8c9e81949229577761e9a809c3a1d9c85e
4
+ data.tar.gz: 21d319d2bca26f53af130397f7d3d8af31c9a23c
5
+ SHA512:
6
+ metadata.gz: 2e78c2df20e47c66339aa93d1e41bd00d6462278298dd77a47f329a0a366692195425d073fc822ed55404d998f2484f3a5a9c22b3d583e334870c2c28c99fcd4
7
+ data.tar.gz: b07e0ab521d17eee1b09760963c837bcd2f609b8c7f2ab2ac422d71a46d469104b198d08f889350b280f8e31fff006aa4a88cc7232b941b4c94216edc5880d1f
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,17 @@
1
+ bundler_args: ""
2
+ language: ruby
3
+ gemfile:
4
+ - spec/gemfiles/32.gemfile
5
+ - spec/gemfiles/40.gemfile
6
+ - spec/gemfiles/41.gemfile
7
+ - spec/gemfiles/42.gemfile
8
+ rvm:
9
+ - 1.9.3
10
+ - 2.0.0
11
+ - 2.1.3
12
+ env:
13
+ - REAL=1
14
+ - TEST=1
15
+ matrix:
16
+ exclude:
17
+ script: bundle exec rake spec
@@ -0,0 +1,6 @@
1
+ # Change Log
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ ## 1.0.0 - 2014-09-26
5
+ ### Added
6
+ - Initial release.
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :test do
4
+ gem 'test_after_commit', git: 'https://github.com/codekitchen/test_after_commit.git', branch: 'nested-commit-callbacks'
5
+ end
6
+
7
+ # Specify your gem's dependencies in after_transaction_commit.gemspec
8
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Instructure, Inc.
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,48 @@
1
+ # After Transaction Commit
2
+
3
+ ```ruby
4
+ ActiveRecord::Base.connection.after_transaction_commit { ... }
5
+ ```
6
+
7
+ An ActiveRecord extension that allows writing callbacks to run after the
8
+ current transaction commits. This is similar to the built-in
9
+ ActiveRecord::Base#after_commit functionality, but more flexible, and
10
+ doesn't require putting the callback on a specific model.
11
+
12
+ Callbacks will only run *once*, on the next commit, not after every
13
+ subsequent commit. Callbacks will never run if the transaction rolls
14
+ back.
15
+
16
+ ## Installation
17
+
18
+ Add this line to your application's Gemfile:
19
+
20
+ ```ruby
21
+ gem 'after_transaction_commit'
22
+ ```
23
+
24
+ And then execute:
25
+
26
+ $ bundle
27
+
28
+ Or install it yourself as:
29
+
30
+ $ gem install after_transaction_commit
31
+
32
+ ## Usage
33
+
34
+ ```ruby
35
+ ActiveRecord::Base.transaction do
36
+ ActiveRecord::Base.after_transaction_commit { run_some_background_job }
37
+ # run_some_background_job has not run yet
38
+ end
39
+ # now, it has run
40
+ ```
41
+
42
+ ## Contributing
43
+
44
+ 1. Fork it ( https://github.com/instructure/after_transaction_commit/fork )
45
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
46
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
47
+ 4. Push to the branch (`git push origin my-new-feature`)
48
+ 5. Create a new Pull Request
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+ require 'wwtd/tasks'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task default: "wwtd:local"
8
+
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'after_transaction_commit/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "after_transaction_commit"
8
+ spec.version = AfterTransactionCommit::VERSION
9
+ spec.authors = ["Brian Palmer"]
10
+ spec.email = ["brianp@instructure.com"]
11
+ spec.summary = %q{ActiveRecord::Base.connection.after_transaction_commit { ... }}
12
+ spec.homepage = "https://github.com/instructure/after_transaction_commit"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "activerecord", ">= 3.2"
21
+
22
+ spec.add_development_dependency "wwtd"
23
+ spec.add_development_dependency "bundler", "~> 1.6"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "sqlite3"
26
+ spec.add_development_dependency "rspec"
27
+ end
@@ -0,0 +1,14 @@
1
+ module AfterTransactionCommit
2
+ end
3
+
4
+ require "after_transaction_commit/version"
5
+ require "after_transaction_commit/database_statements"
6
+
7
+ case ActiveRecord::VERSION::MAJOR
8
+ when 3
9
+ require "after_transaction_commit/rails3"
10
+ when 4
11
+ require "after_transaction_commit/rails4"
12
+ else
13
+ raise "Unsupported rails version"
14
+ end
@@ -0,0 +1,43 @@
1
+ ActiveRecord::ConnectionAdapters::DatabaseStatements.class_eval do
2
+ def after_transaction_commit(&block)
3
+ if !_in_transaction_for_callbacks?
4
+ block.call
5
+ else
6
+ @after_transaction_commit ||= []
7
+ @after_transaction_commit << block
8
+ end
9
+ end
10
+
11
+ private
12
+
13
+ def _run_after_transaction_commit_callbacks
14
+ if @after_transaction_commit.present?
15
+ # the callback could trigger a new transaction on this connection,
16
+ # and leaving the callbacks in @after_transaction_commit could put us in an
17
+ # infinite loop.
18
+ # so we store off the callbacks to a local var here.
19
+ callbacks = @after_transaction_commit
20
+ @after_transaction_commit = []
21
+ callbacks.each { |cb| cb.call() }
22
+ end
23
+ ensure
24
+ @after_transaction_commit = [] if @after_transaction_commit
25
+ end
26
+
27
+ def _remove_after_transaction_commit_callbacks
28
+ @after_transaction_commit = [] if @after_transaction_commit
29
+ end
30
+
31
+ def _transaction_test_mode?
32
+ defined?(TestAfterCommit)
33
+ end
34
+
35
+ def _in_transaction_for_callbacks?
36
+ txn = _transaction_test_mode? ? _test_open_transactions : open_transactions
37
+ txn > 0
38
+ end
39
+
40
+ def _test_open_transactions
41
+ @test_open_transactions || 0
42
+ end
43
+ end
@@ -0,0 +1,16 @@
1
+ ActiveRecord::ConnectionAdapters::DatabaseStatements.class_eval do
2
+ def commit_transaction_records_with_callbacks(*a)
3
+ commit_transaction_records_without_callbacks(*a)
4
+ _run_after_transaction_commit_callbacks
5
+ end
6
+
7
+ def rollback_transaction_records_with_callbacks(rollback)
8
+ rollback_transaction_records_without_callbacks(rollback)
9
+ if rollback || (_transaction_test_mode? && (@test_open_transactions || 0) == 0)
10
+ _remove_after_transaction_commit_callbacks
11
+ end
12
+ end
13
+
14
+ alias_method_chain :commit_transaction_records, :callbacks
15
+ alias_method_chain :rollback_transaction_records, :callbacks
16
+ end
@@ -0,0 +1,21 @@
1
+ klass = defined?(ActiveRecord::ConnectionAdapters::OpenTransaction) ?
2
+ ActiveRecord::ConnectionAdapters::OpenTransaction : # rails < 4.2
3
+ ActiveRecord::ConnectionAdapters::Transaction # rails >= 4.2
4
+
5
+ klass.class_eval do
6
+ def rollback_records_with_callbacks
7
+ rollback_records_without_callbacks
8
+ if self.is_a?(ActiveRecord::ConnectionAdapters::RealTransaction) ||
9
+ (connection.send(:_transaction_test_mode?) && connection.send(:_test_open_transactions) == 0)
10
+ connection.send(:_remove_after_transaction_commit_callbacks)
11
+ end
12
+ end
13
+
14
+ def commit_records_with_callbacks
15
+ commit_records_without_callbacks
16
+ connection.send(:_run_after_transaction_commit_callbacks)
17
+ end
18
+
19
+ alias_method_chain :rollback_records, :callbacks
20
+ alias_method_chain :commit_records, :callbacks
21
+ end
@@ -0,0 +1,3 @@
1
+ module AfterTransactionCommit
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ describe AfterTransactionCommit do
4
+ it 'has a version number' do
5
+ expect(AfterTransactionCommit::VERSION).not_to be nil
6
+ end
7
+
8
+ it "should execute the callback immediately if not in a transaction" do
9
+ a = 0
10
+ User.connection.after_transaction_commit { a += 1 }
11
+ expect(a).to eql 1
12
+ end
13
+
14
+ it "should execute the callback after commit if in a transaction" do
15
+ a = 0
16
+ User.connection.transaction do
17
+ User.connection.after_transaction_commit { a += 1 }
18
+ expect(a).to eql 0
19
+ end
20
+ expect(a).to eql 1
21
+ end
22
+
23
+ it "should not execute the callbacks on rollback" do
24
+ a = 0
25
+ User.connection.transaction do
26
+ User.connection.after_transaction_commit { a += 1 }
27
+ expect(a).to eql 0
28
+ raise ActiveRecord::Rollback
29
+ end
30
+ expect(a).to eql 0
31
+ User.connection.transaction do
32
+ # verify that the callback gets cleared out, so this second transaction won't trigger it
33
+ end
34
+ expect(a).to eql 0
35
+ end
36
+
37
+ it "should avoid loops due to callbacks causing a new transaction" do
38
+ a = 0
39
+ User.connection.transaction do
40
+ User.connection.after_transaction_commit { User.connection.transaction { a += 1 } }
41
+ expect(a).to eql 0
42
+ end
43
+ expect(a).to eql 1
44
+ end
45
+
46
+ it "should execute the callback immediately if created during commit callback" do
47
+ a = 0
48
+ User.connection.transaction do
49
+ User.connection.after_transaction_commit { User.connection.after_transaction_commit { a += 1 } }
50
+ expect(a).to eql 0
51
+ end
52
+ expect(a).to eql 1
53
+ end
54
+
55
+ it "should execute the callback after an inner transaction rollback" do
56
+ a = 0
57
+ User.connection.transaction do
58
+ User.connection.after_transaction_commit { a += 1 }
59
+ User.connection.transaction(:requires_new => true) { raise ActiveRecord::Rollback }
60
+ end
61
+ expect(a).to eql 1
62
+ end
63
+ end
@@ -0,0 +1,18 @@
1
+ # setup database
2
+ require 'active_record'
3
+
4
+ ActiveRecord::Base.establish_connection(
5
+ :adapter => 'sqlite3',
6
+ :database => ':memory:'
7
+ )
8
+
9
+ ActiveRecord::Migration.verbose = false
10
+
11
+ ActiveRecord::Schema.define(:version => 1) do
12
+ create_table "users", :force => true do |t|
13
+ t.string :name
14
+ end
15
+ end
16
+
17
+ class User < ActiveRecord::Base
18
+ end
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec :path=>"../../"
4
+
5
+ gem "activerecord", "~> 3.2.19"
6
+
7
+ group :test do
8
+ gem 'test_after_commit', git: 'https://github.com/codekitchen/test_after_commit.git', branch: 'nested-commit-callbacks'
9
+ end
@@ -0,0 +1,62 @@
1
+ GIT
2
+ remote: https://github.com/codekitchen/test_after_commit.git
3
+ revision: 899ec8b6c699330d7804f91253e37beb610d097e
4
+ branch: nested-commit-callbacks
5
+ specs:
6
+ test_after_commit (0.3.0)
7
+ activerecord (>= 3.2)
8
+
9
+ PATH
10
+ remote: ../../
11
+ specs:
12
+ after_transaction_commit (1.0.0)
13
+ activerecord (>= 3.2)
14
+
15
+ GEM
16
+ remote: https://rubygems.org/
17
+ specs:
18
+ activemodel (3.2.19)
19
+ activesupport (= 3.2.19)
20
+ builder (~> 3.0.0)
21
+ activerecord (3.2.19)
22
+ activemodel (= 3.2.19)
23
+ activesupport (= 3.2.19)
24
+ arel (~> 3.0.2)
25
+ tzinfo (~> 0.3.29)
26
+ activesupport (3.2.19)
27
+ i18n (~> 0.6, >= 0.6.4)
28
+ multi_json (~> 1.0)
29
+ arel (3.0.3)
30
+ builder (3.0.4)
31
+ diff-lcs (1.2.5)
32
+ i18n (0.6.11)
33
+ multi_json (1.10.1)
34
+ rake (10.3.2)
35
+ rspec (3.1.0)
36
+ rspec-core (~> 3.1.0)
37
+ rspec-expectations (~> 3.1.0)
38
+ rspec-mocks (~> 3.1.0)
39
+ rspec-core (3.1.4)
40
+ rspec-support (~> 3.1.0)
41
+ rspec-expectations (3.1.2)
42
+ diff-lcs (>= 1.2.0, < 2.0)
43
+ rspec-support (~> 3.1.0)
44
+ rspec-mocks (3.1.2)
45
+ rspec-support (~> 3.1.0)
46
+ rspec-support (3.1.1)
47
+ sqlite3 (1.3.9)
48
+ tzinfo (0.3.41)
49
+ wwtd (0.5.5)
50
+
51
+ PLATFORMS
52
+ ruby
53
+
54
+ DEPENDENCIES
55
+ activerecord (~> 3.2.19)
56
+ after_transaction_commit!
57
+ bundler (~> 1.6)
58
+ rake (~> 10.0)
59
+ rspec
60
+ sqlite3
61
+ test_after_commit!
62
+ wwtd
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec :path=>"../../"
4
+
5
+ gem "activerecord", "~> 4.0.0"
6
+
7
+ group :test do
8
+ gem 'test_after_commit', git: 'https://github.com/codekitchen/test_after_commit.git', branch: 'nested-commit-callbacks'
9
+ end
@@ -0,0 +1,68 @@
1
+ GIT
2
+ remote: https://github.com/codekitchen/test_after_commit.git
3
+ revision: 899ec8b6c699330d7804f91253e37beb610d097e
4
+ branch: nested-commit-callbacks
5
+ specs:
6
+ test_after_commit (0.3.0)
7
+ activerecord (>= 3.2)
8
+
9
+ PATH
10
+ remote: ../../
11
+ specs:
12
+ after_transaction_commit (1.0.0)
13
+ activerecord (>= 3.2)
14
+
15
+ GEM
16
+ remote: https://rubygems.org/
17
+ specs:
18
+ activemodel (4.0.10)
19
+ activesupport (= 4.0.10)
20
+ builder (~> 3.1.0)
21
+ activerecord (4.0.10)
22
+ activemodel (= 4.0.10)
23
+ activerecord-deprecated_finders (~> 1.0.2)
24
+ activesupport (= 4.0.10)
25
+ arel (~> 4.0.0)
26
+ activerecord-deprecated_finders (1.0.3)
27
+ activesupport (4.0.10)
28
+ i18n (~> 0.6, >= 0.6.9)
29
+ minitest (~> 4.2)
30
+ multi_json (~> 1.3)
31
+ thread_safe (~> 0.1)
32
+ tzinfo (~> 0.3.37)
33
+ arel (4.0.2)
34
+ builder (3.1.4)
35
+ diff-lcs (1.2.5)
36
+ i18n (0.6.11)
37
+ minitest (4.7.5)
38
+ multi_json (1.10.1)
39
+ rake (10.3.2)
40
+ rspec (3.1.0)
41
+ rspec-core (~> 3.1.0)
42
+ rspec-expectations (~> 3.1.0)
43
+ rspec-mocks (~> 3.1.0)
44
+ rspec-core (3.1.4)
45
+ rspec-support (~> 3.1.0)
46
+ rspec-expectations (3.1.2)
47
+ diff-lcs (>= 1.2.0, < 2.0)
48
+ rspec-support (~> 3.1.0)
49
+ rspec-mocks (3.1.2)
50
+ rspec-support (~> 3.1.0)
51
+ rspec-support (3.1.1)
52
+ sqlite3 (1.3.9)
53
+ thread_safe (0.3.4)
54
+ tzinfo (0.3.41)
55
+ wwtd (0.5.5)
56
+
57
+ PLATFORMS
58
+ ruby
59
+
60
+ DEPENDENCIES
61
+ activerecord (~> 4.0.0)
62
+ after_transaction_commit!
63
+ bundler (~> 1.6)
64
+ rake (~> 10.0)
65
+ rspec
66
+ sqlite3
67
+ test_after_commit!
68
+ wwtd
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec :path=>"../../"
4
+
5
+ gem "activerecord", "~> 4.1.0"
6
+
7
+ group :test do
8
+ gem 'test_after_commit', git: 'https://github.com/codekitchen/test_after_commit.git', branch: 'nested-commit-callbacks'
9
+ end
@@ -0,0 +1,67 @@
1
+ GIT
2
+ remote: https://github.com/codekitchen/test_after_commit.git
3
+ revision: 899ec8b6c699330d7804f91253e37beb610d097e
4
+ branch: nested-commit-callbacks
5
+ specs:
6
+ test_after_commit (0.3.0)
7
+ activerecord (>= 3.2)
8
+
9
+ PATH
10
+ remote: ../../
11
+ specs:
12
+ after_transaction_commit (1.0.0)
13
+ activerecord (>= 3.2)
14
+
15
+ GEM
16
+ remote: https://rubygems.org/
17
+ specs:
18
+ activemodel (4.1.6)
19
+ activesupport (= 4.1.6)
20
+ builder (~> 3.1)
21
+ activerecord (4.1.6)
22
+ activemodel (= 4.1.6)
23
+ activesupport (= 4.1.6)
24
+ arel (~> 5.0.0)
25
+ activesupport (4.1.6)
26
+ i18n (~> 0.6, >= 0.6.9)
27
+ json (~> 1.7, >= 1.7.7)
28
+ minitest (~> 5.1)
29
+ thread_safe (~> 0.1)
30
+ tzinfo (~> 1.1)
31
+ arel (5.0.1.20140414130214)
32
+ builder (3.2.2)
33
+ diff-lcs (1.2.5)
34
+ i18n (0.6.11)
35
+ json (1.8.1)
36
+ minitest (5.4.1)
37
+ rake (10.3.2)
38
+ rspec (3.1.0)
39
+ rspec-core (~> 3.1.0)
40
+ rspec-expectations (~> 3.1.0)
41
+ rspec-mocks (~> 3.1.0)
42
+ rspec-core (3.1.4)
43
+ rspec-support (~> 3.1.0)
44
+ rspec-expectations (3.1.2)
45
+ diff-lcs (>= 1.2.0, < 2.0)
46
+ rspec-support (~> 3.1.0)
47
+ rspec-mocks (3.1.2)
48
+ rspec-support (~> 3.1.0)
49
+ rspec-support (3.1.1)
50
+ sqlite3 (1.3.9)
51
+ thread_safe (0.3.4)
52
+ tzinfo (1.2.2)
53
+ thread_safe (~> 0.1)
54
+ wwtd (0.5.5)
55
+
56
+ PLATFORMS
57
+ ruby
58
+
59
+ DEPENDENCIES
60
+ activerecord (~> 4.1.0)
61
+ after_transaction_commit!
62
+ bundler (~> 1.6)
63
+ rake (~> 10.0)
64
+ rspec
65
+ sqlite3
66
+ test_after_commit!
67
+ wwtd
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec :path=>"../../"
4
+
5
+ gem "activerecord", "~> 4.2.0.beta2"
6
+
7
+ group :test do
8
+ gem 'test_after_commit', git: 'https://github.com/codekitchen/test_after_commit.git', branch: 'nested-commit-callbacks'
9
+ end
@@ -0,0 +1,67 @@
1
+ GIT
2
+ remote: https://github.com/codekitchen/test_after_commit.git
3
+ revision: 899ec8b6c699330d7804f91253e37beb610d097e
4
+ branch: nested-commit-callbacks
5
+ specs:
6
+ test_after_commit (0.3.0)
7
+ activerecord (>= 3.2)
8
+
9
+ PATH
10
+ remote: ../../
11
+ specs:
12
+ after_transaction_commit (1.0.0)
13
+ activerecord (>= 3.2)
14
+
15
+ GEM
16
+ remote: https://rubygems.org/
17
+ specs:
18
+ activemodel (4.2.0.beta2)
19
+ activesupport (= 4.2.0.beta2)
20
+ builder (~> 3.1)
21
+ activerecord (4.2.0.beta2)
22
+ activemodel (= 4.2.0.beta2)
23
+ activesupport (= 4.2.0.beta2)
24
+ arel (>= 6.0.0.beta1, < 6.1)
25
+ activesupport (4.2.0.beta2)
26
+ i18n (>= 0.7.0.beta1, < 0.8)
27
+ json (~> 1.7, >= 1.7.7)
28
+ minitest (~> 5.1)
29
+ thread_safe (~> 0.1)
30
+ tzinfo (~> 1.1)
31
+ arel (6.0.0.beta1)
32
+ builder (3.2.2)
33
+ diff-lcs (1.2.5)
34
+ i18n (0.7.0.beta1)
35
+ json (1.8.1)
36
+ minitest (5.4.1)
37
+ rake (10.3.2)
38
+ rspec (3.1.0)
39
+ rspec-core (~> 3.1.0)
40
+ rspec-expectations (~> 3.1.0)
41
+ rspec-mocks (~> 3.1.0)
42
+ rspec-core (3.1.4)
43
+ rspec-support (~> 3.1.0)
44
+ rspec-expectations (3.1.2)
45
+ diff-lcs (>= 1.2.0, < 2.0)
46
+ rspec-support (~> 3.1.0)
47
+ rspec-mocks (3.1.2)
48
+ rspec-support (~> 3.1.0)
49
+ rspec-support (3.1.1)
50
+ sqlite3 (1.3.9)
51
+ thread_safe (0.3.4)
52
+ tzinfo (1.2.2)
53
+ thread_safe (~> 0.1)
54
+ wwtd (0.5.5)
55
+
56
+ PLATFORMS
57
+ ruby
58
+
59
+ DEPENDENCIES
60
+ activerecord (~> 4.2.0.beta2)
61
+ after_transaction_commit!
62
+ bundler (~> 1.6)
63
+ rake (~> 10.0)
64
+ rspec
65
+ sqlite3
66
+ test_after_commit!
67
+ wwtd
@@ -0,0 +1,36 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require File.expand_path '../database', __FILE__
3
+
4
+ require 'after_transaction_commit'
5
+
6
+ if ENV['REAL']
7
+ puts 'using real transactions'
8
+ else
9
+ puts 'using test-style transactions (use_transactional_fixtures)'
10
+ require 'test_after_commit'
11
+ end
12
+
13
+ RSpec.configure do |config|
14
+ unless ENV['REAL']
15
+ config.around do |example|
16
+ # open a transaction without using .transaction as activerecord use_transactional_fixtures does
17
+ # code taken from https://github.com/grosser/test_after_commit/blob/master/spec/spec_helper.rb
18
+ if ActiveRecord::VERSION::MAJOR > 3
19
+ connection = ActiveRecord::Base.connection_handler.connection_pool_list.map(&:connection).first
20
+ connection.begin_transaction :joinable => false
21
+ else
22
+ connection = ActiveRecord::Base.connection_handler.connection_pools.values.map(&:connection).first
23
+ connection.increment_open_transactions
24
+ connection.transaction_joinable = false
25
+ connection.begin_db_transaction
26
+ end
27
+
28
+ example.call
29
+
30
+ connection.rollback_db_transaction
31
+ if ActiveRecord::VERSION::MAJOR == 3
32
+ connection.decrement_open_transactions
33
+ end
34
+ end
35
+ end
36
+ end
metadata ADDED
@@ -0,0 +1,165 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: after_transaction_commit
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Brian Palmer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: wwtd
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sqlite3
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - brianp@instructure.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - CHANGELOG.md
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - after_transaction_commit.gemspec
113
+ - lib/after_transaction_commit.rb
114
+ - lib/after_transaction_commit/database_statements.rb
115
+ - lib/after_transaction_commit/rails3.rb
116
+ - lib/after_transaction_commit/rails4.rb
117
+ - lib/after_transaction_commit/version.rb
118
+ - spec/after_transaction_commit_spec.rb
119
+ - spec/database.rb
120
+ - spec/gemfiles/32.gemfile
121
+ - spec/gemfiles/32.gemfile.lock
122
+ - spec/gemfiles/40.gemfile
123
+ - spec/gemfiles/40.gemfile.lock
124
+ - spec/gemfiles/41.gemfile
125
+ - spec/gemfiles/41.gemfile.lock
126
+ - spec/gemfiles/42.gemfile
127
+ - spec/gemfiles/42.gemfile.lock
128
+ - spec/spec_helper.rb
129
+ homepage: https://github.com/instructure/after_transaction_commit
130
+ licenses:
131
+ - MIT
132
+ metadata: {}
133
+ post_install_message:
134
+ rdoc_options: []
135
+ require_paths:
136
+ - lib
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ requirements: []
148
+ rubyforge_project:
149
+ rubygems_version: 2.4.1
150
+ signing_key:
151
+ specification_version: 4
152
+ summary: ActiveRecord::Base.connection.after_transaction_commit { ... }
153
+ test_files:
154
+ - spec/after_transaction_commit_spec.rb
155
+ - spec/database.rb
156
+ - spec/gemfiles/32.gemfile
157
+ - spec/gemfiles/32.gemfile.lock
158
+ - spec/gemfiles/40.gemfile
159
+ - spec/gemfiles/40.gemfile.lock
160
+ - spec/gemfiles/41.gemfile
161
+ - spec/gemfiles/41.gemfile.lock
162
+ - spec/gemfiles/42.gemfile
163
+ - spec/gemfiles/42.gemfile.lock
164
+ - spec/spec_helper.rb
165
+ has_rdoc: