test_after_commit 0.4.2 → 0.5.0

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: be5c7c35e9b83e1cf522ca5c7cfd3f046a56ca33
4
- data.tar.gz: e2cb178b2b1584c88d607db6540bbe17e3834a71
3
+ metadata.gz: f0c33d45bb130525ad374d2829fc825e45306aa7
4
+ data.tar.gz: 3e04fd9445ffc157141bf77d34346f6e5530fb87
5
5
  SHA512:
6
- metadata.gz: f8a232c5bbb1bfbcefa6c4772cb4d01d7a95f55bdb8e3732bfcef90ccf2f512ec55e76d87e36e6eda0dda6b9dac644abef0088562adc401c673cf198b96cb871
7
- data.tar.gz: 2047d7d6342337a640a222e45d79616c9c14af4f8184e01db39fb1cbfc8828ec7e9b210bec851afacc623df026cb5e82f5b37c504acc4fc57c334a82d2fd99b2
6
+ metadata.gz: b7a67f0068b761afc604941b655b75e525c3f2eb9232a36fb5c45b987e5e5fbe9d749759dffecb1a8bc755282b0768301edb055d0907a6a4867b7208df3cf324
7
+ data.tar.gz: 23515300ab9f8c87fd68ae4fee7ca308cb910ff70061893309d8ec1f2408d193e8269cc0b3d86e6ec8ea67314713c04b5a3430e29caf6dc298a2ee7da2c7899b
data/Readme.md CHANGED
@@ -70,6 +70,7 @@ Inspired by https://gist.github.com/1305285
70
70
  - [Tony Novak](https://github.com/afn)
71
71
  - [Brian Palmer](https://github.com/codekitchen)
72
72
  - [Oleg Dashevskii](https://github.com/be9)
73
+ - [Jonathan Spies](https://github.com/jspies)
73
74
 
74
75
  [Michael Grosser](http://grosser.it)<br/>
75
76
  michael@grosser.it<br/>
@@ -1,5 +1,13 @@
1
1
  require 'test_after_commit/version'
2
2
 
3
+ if ActiveRecord::VERSION::MAJOR >= 4
4
+ require 'test_after_commit/with_transaction_state'
5
+ ActiveRecord::Base.prepend(TestAfterCommit::WithTransactionState)
6
+ end
7
+
8
+ require 'test_after_commit/database_statements'
9
+ ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend(TestAfterCommit::DatabaseStatements)
10
+
3
11
  module TestAfterCommit
4
12
  @enabled = true
5
13
  class << self
@@ -14,61 +22,3 @@ module TestAfterCommit
14
22
  end
15
23
  end
16
24
  end
17
-
18
- ActiveRecord::ConnectionAdapters::DatabaseStatements.class_eval do
19
- def transaction_with_transactional_fixtures(*args)
20
- @test_open_transactions ||= 0
21
- transaction_without_transactional_fixtures(*args) do
22
- begin
23
- @test_open_transactions += 1
24
- if ActiveRecord::VERSION::MAJOR == 3
25
- @_current_transaction_records.push([]) if @_current_transaction_records.empty?
26
- end
27
- result = yield
28
- rescue Exception => e
29
- rolled_back = true
30
- raise e
31
- ensure
32
- begin
33
- @test_open_transactions -= 1
34
- if TestAfterCommit.enabled && @test_open_transactions == 0 && !rolled_back
35
- test_commit_records
36
- end
37
- ensure
38
- result
39
- end
40
- end
41
- end
42
- end
43
- alias_method_chain :transaction, :transactional_fixtures
44
-
45
- def test_commit_records
46
- if ActiveRecord::VERSION::MAJOR == 3
47
- commit_transaction_records
48
- else
49
- # To avoid an infinite loop, we need to copy the transaction locally, and clear out
50
- # `records` on the copy that stays in the AR stack. Otherwise new
51
- # transactions inside a commit callback will cause an infinite loop.
52
- #
53
- # This is because we're re-using the transaction on the stack, before
54
- # it's been popped off and re-created by the AR code.
55
- original = @transaction || @transaction_manager.current_transaction
56
- transaction = original.dup
57
- transaction.instance_variable_set(:@records, transaction.records.dup) # deep clone of records array
58
- original.records.clear # so that this clear doesn't clear out both copies
59
- transaction.commit_records
60
- end
61
- end
62
- end
63
-
64
- if ActiveRecord::VERSION::MAJOR >= 4
65
- # disable parts of the sync code that starts looping
66
- ActiveRecord::Base.class_eval do
67
- alias_method :sync_with_transaction_state_with_state, :sync_with_transaction_state
68
- def sync_with_transaction_state
69
- @reflects_state ||= []
70
- @reflects_state[0] = true
71
- sync_with_transaction_state_with_state
72
- end
73
- end
74
- end
@@ -0,0 +1,45 @@
1
+ module TestAfterCommit::DatabaseStatements
2
+ def transaction(*)
3
+ @test_open_transactions ||= 0
4
+
5
+ super do
6
+ begin
7
+ @test_open_transactions += 1
8
+ if ActiveRecord::VERSION::MAJOR == 3
9
+ @_current_transaction_records.push([]) if @_current_transaction_records.empty?
10
+ end
11
+ result = yield
12
+ rescue Exception
13
+ rolled_back = true
14
+ raise
15
+ ensure
16
+ begin
17
+ @test_open_transactions -= 1
18
+ if TestAfterCommit.enabled && @test_open_transactions == 0 && !rolled_back
19
+ test_commit_records
20
+ end
21
+ ensure
22
+ result
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ def test_commit_records
29
+ if ActiveRecord::VERSION::MAJOR == 3
30
+ commit_transaction_records
31
+ else
32
+ # To avoid an infinite loop, we need to copy the transaction locally, and clear out
33
+ # `records` on the copy that stays in the AR stack. Otherwise new
34
+ # transactions inside a commit callback will cause an infinite loop.
35
+ #
36
+ # This is because we're re-using the transaction on the stack, before
37
+ # it's been popped off and re-created by the AR code.
38
+ original = @transaction || @transaction_manager.current_transaction
39
+ transaction = original.dup
40
+ transaction.instance_variable_set(:@records, transaction.records.dup) # deep clone of records array
41
+ original.records.clear # so that this clear doesn't clear out both copies
42
+ transaction.commit_records
43
+ end
44
+ end
45
+ end
@@ -1,3 +1,3 @@
1
1
  module TestAfterCommit
2
- VERSION = '0.4.2'
2
+ VERSION = '0.5.0'
3
3
  end
@@ -0,0 +1,10 @@
1
+ # disable parts of the sync code that starts looping
2
+ module TestAfterCommit
3
+ module WithTransactionState
4
+ def sync_with_transaction_state
5
+ @reflects_state ||= []
6
+ @reflects_state[0] = true
7
+ super
8
+ end
9
+ end
10
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: test_after_commit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-16 00:00:00.000000000 Z
11
+ date: 2016-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -103,7 +103,9 @@ files:
103
103
  - MIT-LICENSE
104
104
  - Readme.md
105
105
  - lib/test_after_commit.rb
106
+ - lib/test_after_commit/database_statements.rb
106
107
  - lib/test_after_commit/version.rb
108
+ - lib/test_after_commit/with_transaction_state.rb
107
109
  homepage: https://github.com/grosser/test_after_commit
108
110
  licenses:
109
111
  - MIT
@@ -116,7 +118,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
118
  requirements:
117
119
  - - ">="
118
120
  - !ruby/object:Gem::Version
119
- version: '0'
121
+ version: 2.0.0
120
122
  required_rubygems_version: !ruby/object:Gem::Requirement
121
123
  requirements:
122
124
  - - ">="