ar_after_transaction 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Readme.md +5 -1
- data/lib/ar_after_transaction.rb +2 -0
- data/lib/ar_after_transaction/version.rb +1 -1
- metadata +100 -34
- data/.travis.yml +0 -4
- data/Appraisals +0 -8
- data/Gemfile +0 -9
- data/Gemfile.lock +0 -51
- data/Rakefile +0 -13
- data/ar_after_transaction.gemspec +0 -12
- data/gemfiles/rails2.gemfile +0 -12
- data/gemfiles/rails2.gemfile.lock +0 -39
- data/gemfiles/rails3.gemfile +0 -13
- data/gemfiles/rails3.gemfile.lock +0 -89
- data/spec/after_initialize_spec.rb +0 -96
- data/spec/ar_after_transaction_spec.rb +0 -148
- data/spec/setup_database.rb +0 -19
- data/spec/spec_helper.rb +0 -2
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b424a149e55b8cbc4975249856cae410c9618533
|
4
|
+
data.tar.gz: c2c6cced324cdddab51ad689e64cb5722212fc64
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2395d07fa007b42f1f3ad6d241eba4cf013800925ae2acfa3e31a53597b57550264e16d1ccbb01b85b429576a78458cb0ed28077f4f1ca341340331b8cdffbc3
|
7
|
+
data.tar.gz: ef988f3834fd49816f06903636de29f54fee94ce4b2587393aac2993201ca71b8f53611c540a49097daba2af701f20a0173b1f93fc745b04abaa2c26f0f3d5a2
|
data/Readme.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/ar_after_transaction.png)](http://badge.fury.io/rb/ar_after_transaction)
|
2
|
+
[![Build Status](https://travis-ci.org/grosser/ar_after_transaction.png)](https://travis-ci.org/grosser/ar_after_transaction)
|
3
|
+
[![Dependency Status](https://gemnasium.com/grosser/ar_after_transaction.png)](https://gemnasium.com/grosser/ar_after_transaction)
|
4
|
+
|
1
5
|
Do something only after the currently open transactions have finished.
|
2
6
|
|
3
7
|
Normally everything gets rolled back when a transaction fails, but you cannot roll back sending an email or adding a job to Resque.
|
@@ -78,9 +82,9 @@ Authors
|
|
78
82
|
- [Benedikt Deicke](http://blog.synatic.net)
|
79
83
|
- [Tyler Rick](https://github.com/TylerRick)
|
80
84
|
- [Michael Wu](https://github.com/michaelmwu)
|
85
|
+
- [C.W.](https://github.com/compwron)
|
81
86
|
|
82
87
|
[Michael Grosser](http://grosser.it)<br/>
|
83
88
|
michael@grosser.it<br/>
|
84
89
|
License: MIT<br/>
|
85
|
-
[![Build Status](https://travis-ci.org/grosser/ar_after_transaction.png)](https://travis-ci.org/grosser/ar_after_transaction)
|
86
90
|
|
data/lib/ar_after_transaction.rb
CHANGED
metadata
CHANGED
@@ -1,30 +1,117 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ar_after_transaction
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
5
|
-
prerelease:
|
4
|
+
version: 0.4.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Michael Grosser
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2016-11-29 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: activerecord
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">"
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
19
|
+
version: 3.2.0
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '5.0'
|
22
23
|
type: :runtime
|
23
24
|
prerelease: false
|
24
25
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - ">"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.2.0
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '5.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: wwtd
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: bump
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rake
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: rspec
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '2'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '2'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: sqlite3
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: rails
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
28
115
|
- !ruby/object:Gem::Version
|
29
116
|
version: '0'
|
30
117
|
description:
|
@@ -33,52 +120,31 @@ executables: []
|
|
33
120
|
extensions: []
|
34
121
|
extra_rdoc_files: []
|
35
122
|
files:
|
36
|
-
- .travis.yml
|
37
|
-
- Appraisals
|
38
|
-
- Gemfile
|
39
|
-
- Gemfile.lock
|
40
|
-
- Rakefile
|
41
123
|
- Readme.md
|
42
|
-
- ar_after_transaction.gemspec
|
43
|
-
- gemfiles/rails2.gemfile
|
44
|
-
- gemfiles/rails2.gemfile.lock
|
45
|
-
- gemfiles/rails3.gemfile
|
46
|
-
- gemfiles/rails3.gemfile.lock
|
47
124
|
- lib/ar_after_transaction.rb
|
48
125
|
- lib/ar_after_transaction/version.rb
|
49
|
-
- spec/after_initialize_spec.rb
|
50
|
-
- spec/ar_after_transaction_spec.rb
|
51
|
-
- spec/setup_database.rb
|
52
|
-
- spec/spec_helper.rb
|
53
126
|
homepage: http://github.com/grosser/ar_after_transaction
|
54
127
|
licenses:
|
55
128
|
- MIT
|
129
|
+
metadata: {}
|
56
130
|
post_install_message:
|
57
131
|
rdoc_options: []
|
58
132
|
require_paths:
|
59
133
|
- lib
|
60
134
|
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
-
none: false
|
62
135
|
requirements:
|
63
|
-
- -
|
136
|
+
- - ">="
|
64
137
|
- !ruby/object:Gem::Version
|
65
138
|
version: '0'
|
66
|
-
segments:
|
67
|
-
- 0
|
68
|
-
hash: 2099536990730070045
|
69
139
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
-
none: false
|
71
140
|
requirements:
|
72
|
-
- -
|
141
|
+
- - ">="
|
73
142
|
- !ruby/object:Gem::Version
|
74
143
|
version: '0'
|
75
|
-
segments:
|
76
|
-
- 0
|
77
|
-
hash: 2099536990730070045
|
78
144
|
requirements: []
|
79
145
|
rubyforge_project:
|
80
|
-
rubygems_version:
|
146
|
+
rubygems_version: 2.4.5.1
|
81
147
|
signing_key:
|
82
|
-
specification_version:
|
148
|
+
specification_version: 4
|
83
149
|
summary: Execute irreversible actions only when transactions are not rolled back
|
84
150
|
test_files: []
|
data/.travis.yml
DELETED
data/Appraisals
DELETED
data/Gemfile
DELETED
data/Gemfile.lock
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
ar_after_transaction (0.4.0)
|
5
|
-
activerecord
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: https://rubygems.org/
|
9
|
-
specs:
|
10
|
-
activemodel (3.2.13)
|
11
|
-
activesupport (= 3.2.13)
|
12
|
-
builder (~> 3.0.0)
|
13
|
-
activerecord (3.2.13)
|
14
|
-
activemodel (= 3.2.13)
|
15
|
-
activesupport (= 3.2.13)
|
16
|
-
arel (~> 3.0.2)
|
17
|
-
tzinfo (~> 0.3.29)
|
18
|
-
activesupport (3.2.13)
|
19
|
-
i18n (= 0.6.1)
|
20
|
-
multi_json (~> 1.0)
|
21
|
-
appraisal (0.5.1)
|
22
|
-
bundler
|
23
|
-
rake
|
24
|
-
arel (3.0.2)
|
25
|
-
builder (3.0.4)
|
26
|
-
bump (0.3.5)
|
27
|
-
diff-lcs (1.1.3)
|
28
|
-
i18n (0.6.1)
|
29
|
-
multi_json (1.7.7)
|
30
|
-
rake (10.0.2)
|
31
|
-
rspec (2.12.0)
|
32
|
-
rspec-core (~> 2.12.0)
|
33
|
-
rspec-expectations (~> 2.12.0)
|
34
|
-
rspec-mocks (~> 2.12.0)
|
35
|
-
rspec-core (2.12.0)
|
36
|
-
rspec-expectations (2.12.0)
|
37
|
-
diff-lcs (~> 1.1.3)
|
38
|
-
rspec-mocks (2.12.0)
|
39
|
-
sqlite3 (1.3.6)
|
40
|
-
tzinfo (0.3.37)
|
41
|
-
|
42
|
-
PLATFORMS
|
43
|
-
ruby
|
44
|
-
|
45
|
-
DEPENDENCIES
|
46
|
-
appraisal
|
47
|
-
ar_after_transaction!
|
48
|
-
bump
|
49
|
-
rake
|
50
|
-
rspec (~> 2)
|
51
|
-
sqlite3
|
data/Rakefile
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
|
2
|
-
require 'ar_after_transaction/version'
|
3
|
-
|
4
|
-
Gem::Specification.new "ar_after_transaction", ARAfterTransaction::VERSION do |s|
|
5
|
-
s.summary = "Execute irreversible actions only when transactions are not rolled back"
|
6
|
-
s.authors = ["Michael Grosser"]
|
7
|
-
s.email = "michael@grosser.it"
|
8
|
-
s.homepage = "http://github.com/grosser/ar_after_transaction"
|
9
|
-
s.files = `git ls-files`.split("\n")
|
10
|
-
s.add_runtime_dependency "activerecord"
|
11
|
-
s.license = "MIT"
|
12
|
-
end
|
data/gemfiles/rails2.gemfile
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: /Users/mgrosser/code/tools/ar_after_transaction
|
3
|
-
specs:
|
4
|
-
ar_after_transaction (0.3.0)
|
5
|
-
activerecord
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: https://rubygems.org/
|
9
|
-
specs:
|
10
|
-
activerecord (2.3.14)
|
11
|
-
activesupport (= 2.3.14)
|
12
|
-
activesupport (2.3.14)
|
13
|
-
appraisal (0.4.1)
|
14
|
-
bundler
|
15
|
-
rake
|
16
|
-
bump (0.3.5)
|
17
|
-
diff-lcs (1.1.3)
|
18
|
-
rake (0.9.2.2)
|
19
|
-
rspec (2.11.0)
|
20
|
-
rspec-core (~> 2.11.0)
|
21
|
-
rspec-expectations (~> 2.11.0)
|
22
|
-
rspec-mocks (~> 2.11.0)
|
23
|
-
rspec-core (2.11.1)
|
24
|
-
rspec-expectations (2.11.3)
|
25
|
-
diff-lcs (~> 1.1.3)
|
26
|
-
rspec-mocks (2.11.3)
|
27
|
-
sqlite3 (1.3.6)
|
28
|
-
|
29
|
-
PLATFORMS
|
30
|
-
ruby
|
31
|
-
|
32
|
-
DEPENDENCIES
|
33
|
-
activerecord (~> 2.3.14)
|
34
|
-
appraisal
|
35
|
-
ar_after_transaction!
|
36
|
-
bump
|
37
|
-
rake
|
38
|
-
rspec (~> 2)
|
39
|
-
sqlite3
|
data/gemfiles/rails3.gemfile
DELETED
@@ -1,89 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: /Users/mgrosser/code/tools/ar_after_transaction
|
3
|
-
specs:
|
4
|
-
ar_after_transaction (0.3.0)
|
5
|
-
activerecord
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: https://rubygems.org/
|
9
|
-
specs:
|
10
|
-
actionpack (3.2.8)
|
11
|
-
activemodel (= 3.2.8)
|
12
|
-
activesupport (= 3.2.8)
|
13
|
-
builder (~> 3.0.0)
|
14
|
-
erubis (~> 2.7.0)
|
15
|
-
journey (~> 1.0.4)
|
16
|
-
rack (~> 1.4.0)
|
17
|
-
rack-cache (~> 1.2)
|
18
|
-
rack-test (~> 0.6.1)
|
19
|
-
sprockets (~> 2.1.3)
|
20
|
-
activemodel (3.2.8)
|
21
|
-
activesupport (= 3.2.8)
|
22
|
-
builder (~> 3.0.0)
|
23
|
-
activerecord (3.2.8)
|
24
|
-
activemodel (= 3.2.8)
|
25
|
-
activesupport (= 3.2.8)
|
26
|
-
arel (~> 3.0.2)
|
27
|
-
tzinfo (~> 0.3.29)
|
28
|
-
activesupport (3.2.8)
|
29
|
-
i18n (~> 0.6)
|
30
|
-
multi_json (~> 1.0)
|
31
|
-
appraisal (0.4.1)
|
32
|
-
bundler
|
33
|
-
rake
|
34
|
-
arel (3.0.2)
|
35
|
-
builder (3.0.4)
|
36
|
-
bump (0.3.5)
|
37
|
-
diff-lcs (1.1.3)
|
38
|
-
erubis (2.7.0)
|
39
|
-
hike (1.2.3)
|
40
|
-
i18n (0.6.1)
|
41
|
-
journey (1.0.4)
|
42
|
-
json (1.8.0)
|
43
|
-
multi_json (1.3.6)
|
44
|
-
rack (1.4.5)
|
45
|
-
rack-cache (1.2)
|
46
|
-
rack (>= 0.4)
|
47
|
-
rack-ssl (1.3.3)
|
48
|
-
rack
|
49
|
-
rack-test (0.6.2)
|
50
|
-
rack (>= 1.0)
|
51
|
-
railties (3.2.8)
|
52
|
-
actionpack (= 3.2.8)
|
53
|
-
activesupport (= 3.2.8)
|
54
|
-
rack-ssl (~> 1.3.2)
|
55
|
-
rake (>= 0.8.7)
|
56
|
-
rdoc (~> 3.4)
|
57
|
-
thor (>= 0.14.6, < 2.0)
|
58
|
-
rake (0.9.2.2)
|
59
|
-
rdoc (3.12.2)
|
60
|
-
json (~> 1.4)
|
61
|
-
rspec (2.11.0)
|
62
|
-
rspec-core (~> 2.11.0)
|
63
|
-
rspec-expectations (~> 2.11.0)
|
64
|
-
rspec-mocks (~> 2.11.0)
|
65
|
-
rspec-core (2.11.1)
|
66
|
-
rspec-expectations (2.11.3)
|
67
|
-
diff-lcs (~> 1.1.3)
|
68
|
-
rspec-mocks (2.11.3)
|
69
|
-
sprockets (2.1.3)
|
70
|
-
hike (~> 1.2)
|
71
|
-
rack (~> 1.0)
|
72
|
-
tilt (~> 1.1, != 1.3.0)
|
73
|
-
sqlite3 (1.3.6)
|
74
|
-
thor (0.18.1)
|
75
|
-
tilt (1.4.1)
|
76
|
-
tzinfo (0.3.33)
|
77
|
-
|
78
|
-
PLATFORMS
|
79
|
-
ruby
|
80
|
-
|
81
|
-
DEPENDENCIES
|
82
|
-
activerecord (~> 3.2.7)
|
83
|
-
appraisal
|
84
|
-
ar_after_transaction!
|
85
|
-
bump
|
86
|
-
railties
|
87
|
-
rake
|
88
|
-
rspec (~> 2)
|
89
|
-
sqlite3
|
@@ -1,96 +0,0 @@
|
|
1
|
-
require 'active_record'
|
2
|
-
require File.expand_path '../setup_database', __FILE__
|
3
|
-
|
4
|
-
if ActiveRecord::VERSION::MAJOR > 2
|
5
|
-
require 'action_controller/railtie'
|
6
|
-
|
7
|
-
Rack::Session::Cookie
|
8
|
-
|
9
|
-
module Passthrough
|
10
|
-
def self.extended( base )
|
11
|
-
base.class_eval do
|
12
|
-
class << self
|
13
|
-
alias_method :transaction_without_passthrough, :transaction
|
14
|
-
alias_method :transaction, :transaction_with_passthrough
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def transaction_with_passthrough(*args, &block)
|
20
|
-
transaction_without_passthrough(*args, &block)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
class Railtie < ::Rails::Railtie
|
25
|
-
config.after_initialize do
|
26
|
-
ActiveRecord::Base.send(:extend, Passthrough)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
module ARAfterTransaction
|
31
|
-
class Application < ::Rails::Application
|
32
|
-
config.active_support.deprecation = :log
|
33
|
-
|
34
|
-
config.after_initialize do
|
35
|
-
require 'ar_after_transaction'
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
Rack::Session::Cookie.send(:define_method, :warn){|_|} # seilence secret warning
|
41
|
-
ARAfterTransaction::Application.initialize! # initialize app
|
42
|
-
|
43
|
-
class AnExpectedError < Exception
|
44
|
-
end
|
45
|
-
|
46
|
-
class User
|
47
|
-
cattr_accessor :test_callbacks, :test_stack
|
48
|
-
self.test_stack = []
|
49
|
-
self.test_callbacks = []
|
50
|
-
|
51
|
-
after_create :do_it
|
52
|
-
def do_it
|
53
|
-
self.class.test_callbacks.map{|callback| send(callback)}.last
|
54
|
-
end
|
55
|
-
|
56
|
-
def do_after
|
57
|
-
after_transaction do
|
58
|
-
ActiveRecord::Base.transaction do
|
59
|
-
# nested transaction should not cause infinitive recursion
|
60
|
-
end
|
61
|
-
self.class.test_stack << :after
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def do_normal
|
66
|
-
self.class.test_stack << :normal
|
67
|
-
end
|
68
|
-
|
69
|
-
def oops
|
70
|
-
raise AnExpectedError
|
71
|
-
end
|
72
|
-
|
73
|
-
def raise_rollback
|
74
|
-
raise ActiveRecord::Rollback
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
describe ARAfterTransaction do
|
79
|
-
before do
|
80
|
-
User.normally_open_transactions = nil
|
81
|
-
User.send(:transactions_open?).should == false
|
82
|
-
User.test_stack.clear
|
83
|
-
User.test_callbacks.clear
|
84
|
-
end
|
85
|
-
|
86
|
-
it "has a VERSION" do
|
87
|
-
ARAfterTransaction::VERSION.should =~ /^\d+\.\d+\.\d+$/
|
88
|
-
end
|
89
|
-
|
90
|
-
it "executes after a transaction" do
|
91
|
-
User.test_callbacks = [:do_after, :do_normal]
|
92
|
-
User.create!
|
93
|
-
User.test_stack.should == [:normal, :after]
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
@@ -1,148 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
class AnExpectedError < Exception
|
4
|
-
end
|
5
|
-
|
6
|
-
class User
|
7
|
-
cattr_accessor :test_callbacks, :test_stack
|
8
|
-
self.test_stack = []
|
9
|
-
self.test_callbacks = []
|
10
|
-
|
11
|
-
after_create :do_it
|
12
|
-
def do_it
|
13
|
-
self.class.test_callbacks.map{|callback| send(callback)}.last
|
14
|
-
end
|
15
|
-
|
16
|
-
def do_after
|
17
|
-
after_transaction do
|
18
|
-
ActiveRecord::Base.transaction do
|
19
|
-
# nested transaction should not cause infinitive recursion
|
20
|
-
end
|
21
|
-
self.class.test_stack << :after
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def do_normal
|
26
|
-
self.class.test_stack << :normal
|
27
|
-
end
|
28
|
-
|
29
|
-
def oops
|
30
|
-
raise AnExpectedError
|
31
|
-
end
|
32
|
-
|
33
|
-
def raise_rollback
|
34
|
-
raise ActiveRecord::Rollback
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
describe ARAfterTransaction do
|
39
|
-
before do
|
40
|
-
User.normally_open_transactions = nil
|
41
|
-
User.send(:transactions_open?).should == false
|
42
|
-
User.test_stack.clear
|
43
|
-
User.test_callbacks.clear
|
44
|
-
end
|
45
|
-
|
46
|
-
it "has a VERSION" do
|
47
|
-
ARAfterTransaction::VERSION.should =~ /^\d+\.\d+\.\d+$/
|
48
|
-
end
|
49
|
-
|
50
|
-
it "executes after a transaction" do
|
51
|
-
User.test_callbacks = [:do_after, :do_normal]
|
52
|
-
User.create!
|
53
|
-
User.test_stack.should == [:normal, :after]
|
54
|
-
end
|
55
|
-
|
56
|
-
it "does not execute when transaction was rolled back" do
|
57
|
-
User.test_callbacks = [:do_after, :do_normal, :oops]
|
58
|
-
lambda{
|
59
|
-
User.create!
|
60
|
-
}.should raise_error(AnExpectedError)
|
61
|
-
User.test_stack.should == [:normal]
|
62
|
-
end
|
63
|
-
|
64
|
-
it "does not execute when transaction gets rolled back by ActiveRecord::Rollback raised in an after_create callback" do
|
65
|
-
User.test_callbacks = [:do_after, :do_normal, :raise_rollback]
|
66
|
-
user = User.create!
|
67
|
-
User.test_stack.should == [:normal]
|
68
|
-
end
|
69
|
-
|
70
|
-
it "does not execute when transaction gets rolled back by ActiveRecord::Rollback outside of the model" do
|
71
|
-
User.test_callbacks = [:do_after, :do_normal]
|
72
|
-
user = nil
|
73
|
-
ActiveRecord::Base.transaction do
|
74
|
-
user = User.create!
|
75
|
-
raise ActiveRecord::Rollback
|
76
|
-
end
|
77
|
-
User.test_stack.should == [:normal]
|
78
|
-
end
|
79
|
-
|
80
|
-
it "clears transaction callbacks when transaction fails" do
|
81
|
-
User.test_callbacks = [:do_after, :do_normal, :oops]
|
82
|
-
lambda{
|
83
|
-
User.create!
|
84
|
-
}.should raise_error(AnExpectedError)
|
85
|
-
User.test_callbacks = [:do_normal]
|
86
|
-
User.create!
|
87
|
-
User.test_stack.should == [:normal, :normal]
|
88
|
-
end
|
89
|
-
|
90
|
-
it "executes when no transaction is open" do
|
91
|
-
user = User.new
|
92
|
-
user.do_after
|
93
|
-
user.do_normal
|
94
|
-
User.test_stack.should == [:after, :normal]
|
95
|
-
end
|
96
|
-
|
97
|
-
it "executes when open transactions are normal" do
|
98
|
-
User.normally_open_transactions = 1
|
99
|
-
User.test_callbacks = [:do_after, :do_normal]
|
100
|
-
User.create!
|
101
|
-
User.test_stack.should == [:after, :normal]
|
102
|
-
end
|
103
|
-
|
104
|
-
it "does not execute the same callback twice when successful" do
|
105
|
-
User.test_callbacks = [:do_after, :do_normal]
|
106
|
-
User.create!
|
107
|
-
User.create!
|
108
|
-
User.test_stack.should == [:normal, :after, :normal, :after]
|
109
|
-
end
|
110
|
-
|
111
|
-
it "does not execute the same callback twice when failed" do
|
112
|
-
User.test_callbacks = [:do_after, :do_normal, :oops]
|
113
|
-
lambda{
|
114
|
-
User.create!
|
115
|
-
}.should raise_error(AnExpectedError)
|
116
|
-
lambda{
|
117
|
-
User.create!
|
118
|
-
}.should raise_error(AnExpectedError)
|
119
|
-
User.test_stack.should == [:normal, :normal]
|
120
|
-
end
|
121
|
-
|
122
|
-
it "does not crash with additional options" do
|
123
|
-
User.transaction(:requires_new => true){}
|
124
|
-
end
|
125
|
-
|
126
|
-
describe :normally_open_transactions do
|
127
|
-
it "uses 0 by default" do
|
128
|
-
User.normally_open_transactions.should == 0
|
129
|
-
end
|
130
|
-
|
131
|
-
it "can set normally open transactions" do
|
132
|
-
User.normally_open_transactions = 5
|
133
|
-
User.normally_open_transactions.should == 5
|
134
|
-
end
|
135
|
-
|
136
|
-
it "sets them globally" do
|
137
|
-
User.normally_open_transactions = 5
|
138
|
-
ActiveRecord::Base.normally_open_transactions.should == 5
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
describe "A normal ActiveRecord subclass" do
|
144
|
-
it "does not get polluted" do
|
145
|
-
User.const_defined?(:VERSION).should be_false
|
146
|
-
User.const_defined?(:Version).should be_false
|
147
|
-
end
|
148
|
-
end
|
data/spec/setup_database.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
ActiveRecord::Base.establish_connection(
|
2
|
-
:adapter => 'sqlite3',
|
3
|
-
:database => ':memory:'
|
4
|
-
)
|
5
|
-
|
6
|
-
ActiveRecord::Migration.verbose = false
|
7
|
-
ActiveRecord::Schema.define(:version => 1) do
|
8
|
-
create_table :users do |t|
|
9
|
-
t.string :name
|
10
|
-
t.timestamps
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
# for detailed debugging:
|
15
|
-
#require 'logger'
|
16
|
-
#ActiveRecord::Base.logger = Logger.new(STDOUT)
|
17
|
-
|
18
|
-
class User < ActiveRecord::Base
|
19
|
-
end
|
data/spec/spec_helper.rb
DELETED