activerecord-after-transaction 0.1.1 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 13b1839b4cea12bd935bd31f7fd7d2a70b73faa2
4
- data.tar.gz: ea8486b878ef73152c2788a4d15a111367117d83
3
+ metadata.gz: 8c7628dfc2746e467f424e85396a743ef483bb63
4
+ data.tar.gz: fc7f8a21fce29ec827dda67d9c7ad4124845631b
5
5
  SHA512:
6
- metadata.gz: 6992f5baa3a47fc8d45ff34575df6337fa71a371b5908d86818cdb096dcda2965063d588860dc066fe6f0fefe03e0b52cbd07004cba58c41e91b96037189a6cf
7
- data.tar.gz: 672442a654d24ff95bc05795f7f750b0288a425ea389e5227b8ebb3e32f574d2a738b9df131e19d6a5de48f42c5814ef7c4484804353f6f64a394dc15cf5072a
6
+ metadata.gz: 5680857fc20de8921ec1f709bf07264a4951b6a5ec44ed879111ec99983cfcde671ca9cf08b2ad129c197b7883ef6ac397a766b802fde14a82b11e810be3d7b2
7
+ data.tar.gz: 8a64d651643698a3768d9c7a9a6b9b17ef6df7e1f3d3de24536d3f6c1908222b6368f0aed1625cf47508b99aefd401ac7b19f9845b54accb73331aec91491a4c
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -16,8 +16,10 @@ module ActiveRecord::AfterTransaction
16
16
  logger && logger.debug("Push #{block}")
17
17
  end
18
18
 
19
+ private
20
+
19
21
  def execute_after_transaction
20
- queue = @after_transaction_queue
22
+ queue = @after_transaction_queue ||= []
21
23
  if !queue.empty?
22
24
  logger && logger.debug("Execute the queue")
23
25
  queue = queue.dup
@@ -31,6 +33,7 @@ module ActiveRecord::AfterTransaction
31
33
 
32
34
  def clear_after_transaction
33
35
  logger && logger.debug("Clear the queue")
36
+ @after_transaction_queue ||= []
34
37
  @after_transaction_queue.clear
35
38
  end
36
39
  end
@@ -9,6 +9,34 @@ describe ActiveRecord::AfterTransaction::Methods do
9
9
  end
10
10
  subject { klass.new }
11
11
 
12
+ shared_examples 'without error' do
13
+ it 'does not raise error in the after_commit callback' do
14
+ step = 1
15
+ subject.class_eval do
16
+ after_commit do
17
+ step = 2
18
+ end
19
+ end
20
+ klass.transaction do
21
+ subject.save!
22
+ end
23
+ expect(step).to eq 2
24
+ end
25
+ it 'does not raise error in the after_rollback callback' do
26
+ step = 1
27
+ subject.class_eval do
28
+ after_rollback do
29
+ step = 2
30
+ end
31
+ end
32
+ klass.transaction do
33
+ subject.save!
34
+ raise ActiveRecord::Rollback
35
+ end
36
+ expect(step).to eq 2
37
+ end
38
+ end
39
+
12
40
  describe 'in a transaction' do
13
41
  it 'executes the proc after transaction' do
14
42
  step = 1
@@ -43,6 +71,10 @@ describe ActiveRecord::AfterTransaction::Methods do
43
71
  end
44
72
  expect(step).to eq 1
45
73
  end
74
+ it_behaves_like 'without error'
75
+ describe 'with empty queue' do
76
+ it_behaves_like 'without error'
77
+ end
46
78
  end
47
79
  describe 'not in a transaction' do
48
80
  it 'executes the proc immediately' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-after-transaction
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daisuke Taniwaki