activerecord-after-transaction 0.1.2 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/Gemfile +1 -1
- data/VERSION +1 -1
- data/lib/activerecord-after-transaction.rb +6 -2
- data/lib/activerecord-after-transaction/methods.rb +3 -1
- data/lib/activerecord-after-transaction/railtie.rb +12 -0
- data/spec/after_transaction/methods_spec.rb +22 -4
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d937a12554cf957268da29fb08a5d9536e00192
|
4
|
+
data.tar.gz: 7c063d5cfd5b0850870aacdd089c80e872c1ba36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 757ecfc0da2a9ba53e41fa8ec26925d5c74fd2d3707b18bbf5347dbc7c7d8e487d06dfe9085c09ad6f4c804590d30d946da437320dcc12400359570accef3f78
|
7
|
+
data.tar.gz: b9181c500ef091a5e8aa4be4cffea455d27f7372cd54b8636f60d4bbd09e704778d7f182cfda6283a2571877dc681f41eb8f28f83b44f7183e22b78830986127
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
gem 'activerecord', "~> #{ENV['
|
3
|
+
gem 'activerecord', "~> #{ENV['ACTIVE_RECORD_VERSION']}" if ENV['ACTIVE_RECORD_VERSION'].to_s != ''
|
4
4
|
|
5
5
|
gem "sqlite3"
|
6
6
|
gem "codeclimate-test-reporter", require: nil
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.4
|
@@ -2,6 +2,10 @@ require 'active_record'
|
|
2
2
|
require 'activerecord-after-transaction/version'
|
3
3
|
require 'activerecord-after-transaction/methods'
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
if defined?(::Rails)
|
6
|
+
require 'activerecord-after-transaction/railtie'
|
7
|
+
else
|
8
|
+
ActiveSupport.on_load :active_record do
|
9
|
+
include ActiveRecord::AfterTransaction::Methods
|
10
|
+
end
|
7
11
|
end
|
@@ -10,7 +10,9 @@ module ActiveRecord::AfterTransaction
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def after_transaction(&block)
|
13
|
-
return block.call
|
13
|
+
return block.call if self.class.connection.open_transactions == 0
|
14
|
+
self.class.connection.add_transaction_record self
|
15
|
+
|
14
16
|
@after_transaction_queue ||= []
|
15
17
|
@after_transaction_queue.push block
|
16
18
|
logger && logger.debug("Push #{block}")
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'active_record/railtie'
|
2
|
+
require 'activerecord-after-transaction/methods'
|
3
|
+
|
4
|
+
module ActiveRecordAfterTransaction
|
5
|
+
class Railtie < Rails::Railtie
|
6
|
+
initializer "active_record.include_after_transaction", after: "active_record.set_configs" do |app|
|
7
|
+
ActiveSupport.on_load :active_record do
|
8
|
+
include ActiveRecord::AfterTransaction::Methods
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -7,12 +7,12 @@ describe ActiveRecord::AfterTransaction::Methods do
|
|
7
7
|
include ActiveRecord::AfterTransaction::Methods
|
8
8
|
end
|
9
9
|
end
|
10
|
-
subject { klass.
|
10
|
+
subject { klass.create! }
|
11
11
|
|
12
12
|
shared_examples 'without error' do
|
13
13
|
it 'does not raise error in the after_commit callback' do
|
14
14
|
step = 1
|
15
|
-
|
15
|
+
klass.class_eval do
|
16
16
|
after_commit do
|
17
17
|
step = 2
|
18
18
|
end
|
@@ -24,7 +24,7 @@ describe ActiveRecord::AfterTransaction::Methods do
|
|
24
24
|
end
|
25
25
|
it 'does not raise error in the after_rollback callback' do
|
26
26
|
step = 1
|
27
|
-
|
27
|
+
klass.class_eval do
|
28
28
|
after_rollback do
|
29
29
|
step = 2
|
30
30
|
end
|
@@ -83,7 +83,25 @@ describe ActiveRecord::AfterTransaction::Methods do
|
|
83
83
|
subject.after_transaction do
|
84
84
|
step = 2
|
85
85
|
end
|
86
|
-
expect(step).to eq
|
86
|
+
expect(step).to eq 2
|
87
|
+
end
|
88
|
+
end
|
89
|
+
describe 'in another model transaction' do
|
90
|
+
let(:another_klass) do
|
91
|
+
create_tmp_model foo: :integer do
|
92
|
+
include ActiveRecord::AfterTransaction::Methods
|
93
|
+
end
|
94
|
+
end
|
95
|
+
it 'executes the proc after transaction' do
|
96
|
+
step = 1
|
97
|
+
|
98
|
+
another_klass.transaction do
|
99
|
+
subject.after_transaction do
|
100
|
+
step = 2
|
101
|
+
end
|
102
|
+
step = 3
|
103
|
+
end
|
104
|
+
expect(step).to eq 2
|
87
105
|
end
|
88
106
|
end
|
89
107
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-after-transaction
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daisuke Taniwaki
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -69,6 +69,7 @@ files:
|
|
69
69
|
- activerecord-after-transaction.gemspec
|
70
70
|
- lib/activerecord-after-transaction.rb
|
71
71
|
- lib/activerecord-after-transaction/methods.rb
|
72
|
+
- lib/activerecord-after-transaction/railtie.rb
|
72
73
|
- lib/activerecord-after-transaction/version.rb
|
73
74
|
- spec/after_transaction/methods_spec.rb
|
74
75
|
- spec/spec_helper.rb
|