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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8c7628dfc2746e467f424e85396a743ef483bb63
4
- data.tar.gz: fc7f8a21fce29ec827dda67d9c7ad4124845631b
3
+ metadata.gz: 4d937a12554cf957268da29fb08a5d9536e00192
4
+ data.tar.gz: 7c063d5cfd5b0850870aacdd089c80e872c1ba36
5
5
  SHA512:
6
- metadata.gz: 5680857fc20de8921ec1f709bf07264a4951b6a5ec44ed879111ec99983cfcde671ca9cf08b2ad129c197b7883ef6ac397a766b802fde14a82b11e810be3d7b2
7
- data.tar.gz: 8a64d651643698a3768d9c7a9a6b9b17ef6df7e1f3d3de24536d3f6c1908222b6368f0aed1625cf47508b99aefd401ac7b19f9845b54accb73331aec91491a4c
6
+ metadata.gz: 757ecfc0da2a9ba53e41fa8ec26925d5c74fd2d3707b18bbf5347dbc7c7d8e487d06dfe9085c09ad6f4c804590d30d946da437320dcc12400359570accef3f78
7
+ data.tar.gz: b9181c500ef091a5e8aa4be4cffea455d27f7372cd54b8636f60d4bbd09e704778d7f182cfda6283a2571877dc681f41eb8f28f83b44f7183e22b78830986127
@@ -13,7 +13,7 @@ env:
13
13
  - ACTIVE_RECORD_VERSION=3.2.0
14
14
  - ACTIVE_RECORD_VERSION=4.0.0
15
15
  - ACTIVE_RECORD_VERSION=4.1.0
16
- - ACTIVE_RECORD_VERSION=4.2.0.beta4
16
+ - ACTIVE_RECORD_VERSION=4.2.0.rc1
17
17
 
18
18
  script: "bundle exec rake spec"
19
19
 
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'activerecord', "~> #{ENV['ACTION_RECORD_VERSION']}" if ENV['ACTION_RECORD_VERSION'].to_s != ''
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.2
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
- ActiveSupport.on_load :active_record do
6
- include ActiveRecord::AfterTransaction::Methods
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 unless self.class.connection.open_transactions
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.new }
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
- subject.class_eval do
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
- subject.class_eval do
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 1
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.2
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-08 00:00:00.000000000 Z
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