outside_transaction 0.0.1 → 0.0.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.
- data/README.md +23 -0
- data/lib/outside_transaction.rb +7 -1
- data/lib/outside_transaction/version.rb +1 -1
- data/spec/outside_transaction_spec.rb +30 -3
- metadata +4 -4
data/README.md
CHANGED
@@ -28,3 +28,26 @@ end
|
|
28
28
|
```
|
29
29
|
|
30
30
|
This example is using [Resque](https://github.com/defunkt/resque).
|
31
|
+
|
32
|
+
## Testing
|
33
|
+
|
34
|
+
`rake`
|
35
|
+
|
36
|
+
## Testing your app
|
37
|
+
|
38
|
+
When testing your Rails app with `use_transactional_fixtures` on
|
39
|
+
(meaning that all your tests are wrapped in a transaction that is rolled
|
40
|
+
back after the test), you need to disbale `OutsideTransaction`, otherwise
|
41
|
+
your blocks wrapped in `outside_transaction` will not be run.
|
42
|
+
|
43
|
+
Example for RSpec:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
# spec/spec_helper.rb
|
47
|
+
|
48
|
+
RSpec.configure do |config|
|
49
|
+
config.before(:each) do
|
50
|
+
OutsideTransaction.disable
|
51
|
+
end
|
52
|
+
end
|
53
|
+
```
|
data/lib/outside_transaction.rb
CHANGED
@@ -16,6 +16,10 @@ module OutsideTransaction
|
|
16
16
|
@@disabled = true
|
17
17
|
end
|
18
18
|
|
19
|
+
def self.enable
|
20
|
+
@@disabled = false
|
21
|
+
end
|
22
|
+
|
19
23
|
module Connection
|
20
24
|
def self.included(base)
|
21
25
|
unless base.method_defined? :commit_db_transaction_without_outside_transaction
|
@@ -88,7 +92,9 @@ ActiveRecord::Base.instance_eval do
|
|
88
92
|
}
|
89
93
|
end
|
90
94
|
|
91
|
-
|
95
|
+
unless method_defined? :establish_connection_without_outside_transaction
|
96
|
+
alias_method_chain :establish_connection, :outside_transaction
|
97
|
+
end
|
92
98
|
|
93
99
|
end
|
94
100
|
end
|
@@ -1,13 +1,14 @@
|
|
1
1
|
require 'outside_transaction'
|
2
2
|
|
3
|
-
ROOT_DIR = File.expand_path('../..')
|
3
|
+
ROOT_DIR = File.expand_path('../..', __FILE__)
|
4
4
|
FileUtils.makedirs "#{ROOT_DIR}/tmp"
|
5
|
-
|
5
|
+
DB_CONFIG = {
|
6
6
|
:adapter => 'sqlite3',
|
7
7
|
:database => "#{ROOT_DIR}/tmp/test_db.sqlite3",
|
8
8
|
:pool => 5,
|
9
9
|
:timeout => 5000
|
10
|
-
|
10
|
+
}
|
11
|
+
ActiveRecord::Base.establish_connection(DB_CONFIG)
|
11
12
|
|
12
13
|
describe OutsideTransaction do
|
13
14
|
|
@@ -61,4 +62,30 @@ describe OutsideTransaction do
|
|
61
62
|
end
|
62
63
|
end
|
63
64
|
|
65
|
+
context "when disabled" do
|
66
|
+
it "runs the block immediately even when inside a transaction" do
|
67
|
+
OutsideTransaction.disable
|
68
|
+
transaction do
|
69
|
+
outside_transaction(&test_block)
|
70
|
+
should_have_been_run
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context "when disabled, then enabled" do
|
76
|
+
it "runs the block when the transaction is commited" do
|
77
|
+
OutsideTransaction.disable
|
78
|
+
OutsideTransaction.enable
|
79
|
+
transaction do
|
80
|
+
outside_transaction(&test_block)
|
81
|
+
should_not_have_been_run
|
82
|
+
end
|
83
|
+
should_have_been_run
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
it "doesn't crash when reloading file and reconnecting" do
|
88
|
+
load "#{ROOT_DIR}/lib/outside_transaction.rb"
|
89
|
+
ActiveRecord::Base.establish_connection(DB_CONFIG)
|
90
|
+
end
|
64
91
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: outside_transaction
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Levente Bagi
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-11-
|
18
|
+
date: 2011-11-10 00:00:00 +00:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|