sequel_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.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a6564ae557f5c934bd0243367f8f14b75167871
|
4
|
+
data.tar.gz: 4690ced67caa966276bf977dc1b9a8a8adfda5ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce76146f852a7370306a9534f82d561c6f837562799a3eb2ba3ea631aabe225ab9e2986557c4776b280e3a5a5ed5747fde7c2ddd3077b84e3a929a75ef890bed
|
7
|
+
data.tar.gz: fb9b1e64c07fdca63d8aaf90260079afb23a55069e93e33924694b9de6134db5882a286cd3f21dabb6cd45ecf0b5c769fb02eea9ab9d827b0df834cc1adefc40
|
@@ -6,15 +6,20 @@ module Rack
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def call(env)
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
req = Request.new env
|
10
|
+
if req.get? || req.head? || req.options?
|
11
|
+
@inner.call env
|
12
|
+
else
|
13
|
+
@connection.transaction do
|
14
|
+
result = @inner.call env
|
15
|
+
response = Response.new [], result[0]
|
16
|
+
err = env['sinatra.error']
|
13
17
|
|
14
|
-
|
15
|
-
|
18
|
+
if err || response.client_error? || response.server_error?
|
19
|
+
raise Sequel::Rollback
|
20
|
+
end
|
21
|
+
result
|
16
22
|
end
|
17
|
-
result
|
18
23
|
end
|
19
24
|
end
|
20
25
|
end
|
@@ -44,7 +44,7 @@ describe Rack::SequelTransaction do
|
|
44
44
|
dataset.wont_be :empty?
|
45
45
|
end
|
46
46
|
|
47
|
-
it 'rolls back
|
47
|
+
it 'rolls back on sinatra error' do
|
48
48
|
expect_call 200
|
49
49
|
env['sinatra.error'] = StandardError.new 'snap'
|
50
50
|
subject.call env
|
@@ -62,4 +62,37 @@ describe Rack::SequelTransaction do
|
|
62
62
|
subject.call env
|
63
63
|
dataset.must_be :empty?
|
64
64
|
end
|
65
|
+
|
66
|
+
%w{ GET HEAD OPTIONS }.each do |method|
|
67
|
+
# shouldn't be modifying anything on these types of requests; modifying for assertion purposes
|
68
|
+
|
69
|
+
describe "on #{method} request" do
|
70
|
+
before { env['REQUEST_METHOD'] = method }
|
71
|
+
|
72
|
+
it 'returns result' do
|
73
|
+
expect_call 200
|
74
|
+
result = subject.call(env)
|
75
|
+
result.must_equal [200, {}, []]
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'wont rollback on sinatra error' do
|
79
|
+
expect_call 200
|
80
|
+
env['sinatra.error'] = StandardError.new 'snap'
|
81
|
+
subject.call env
|
82
|
+
dataset.wont_be :empty?
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'wont rollback on server error' do
|
86
|
+
expect_call 500
|
87
|
+
subject.call env
|
88
|
+
dataset.wont_be :empty?
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'wont rollback on client error' do
|
92
|
+
expect_call 400
|
93
|
+
subject.call env
|
94
|
+
dataset.wont_be :empty?
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
65
98
|
end
|