request_store 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/README.md +17 -0
- data/lib/request_store/railtie.rb +6 -0
- data/lib/request_store/version.rb +1 -1
- data/request_store.gemspec +1 -1
- data/test/middleware_test.rb +4 -6
- data/test/request_store_test.rb +5 -9
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 348deb2b9d7db6347123b67d18b5d4eb2c8001ed
|
4
|
+
data.tar.gz: 8296b65a72b085eec44e257b018340e392d787ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7fe4a75ba1e5a5bd6c578c822b12d1982118178f95a391ac6a716e7364241e1b41e98eb4193032765c6a31103366fd497ccad181ee3d10aa44fbc4284175905
|
7
|
+
data.tar.gz: 645b2404581a8f991e38f4a83cf0fee31f4444ba7fddb2beaea8f0bd5e1f15ab16af281ee85acb105035e21308a011ecc1977ca35851b66d2f45411471ad8c54
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -81,6 +81,23 @@ You'll probably have to shove this somewhere:
|
|
81
81
|
use RequestStore::Middleware
|
82
82
|
```
|
83
83
|
|
84
|
+
#### No Rails + Rack::Test
|
85
|
+
|
86
|
+
In order to have `RequestStore` storage cleared between requests, add it to the
|
87
|
+
`app`:
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
# spec_helper.rb
|
91
|
+
|
92
|
+
def app
|
93
|
+
Rack::Builder.new do
|
94
|
+
use RequestStore::Middleware
|
95
|
+
run MyApp
|
96
|
+
end
|
97
|
+
end
|
98
|
+
```
|
99
|
+
|
100
|
+
|
84
101
|
## Contributing
|
85
102
|
|
86
103
|
1. Fork it
|
@@ -6,6 +6,12 @@ module RequestStore
|
|
6
6
|
else
|
7
7
|
app.config.middleware.insert_after Rack::MethodOverride, RequestStore::Middleware
|
8
8
|
end
|
9
|
+
|
10
|
+
if ActionDispatch.const_defined?(:Reloader) && ActionDispatch::Reloader.respond_to?(:to_cleanup)
|
11
|
+
ActionDispatch::Reloader.to_cleanup do
|
12
|
+
RequestStore.clear!
|
13
|
+
end
|
14
|
+
end
|
9
15
|
end
|
10
16
|
end
|
11
17
|
end
|
data/request_store.gemspec
CHANGED
data/test/middleware_test.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
+
require 'minitest/test'
|
1
2
|
require 'minitest/autorun'
|
2
3
|
|
3
4
|
require 'request_store'
|
4
5
|
|
5
|
-
class MiddlewareTest < Minitest::
|
6
|
+
class MiddlewareTest < Minitest::Test
|
6
7
|
def setup
|
7
8
|
@app = RackApp.new
|
8
9
|
@middleware = RequestStore::Middleware.new(@app)
|
@@ -16,14 +17,11 @@ class MiddlewareTest < Minitest::Unit::TestCase
|
|
16
17
|
end
|
17
18
|
|
18
19
|
def test_middleware_resets_store_on_error
|
19
|
-
|
20
|
-
begin
|
20
|
+
e = assert_raises RuntimeError do
|
21
21
|
@middleware.call({:error => true})
|
22
|
-
rescue => e
|
23
|
-
errors << e
|
24
22
|
end
|
25
23
|
|
26
|
-
assert_equal
|
24
|
+
assert_equal 'FAIL', e.message
|
27
25
|
assert_equal({}, RequestStore.store)
|
28
26
|
end
|
29
27
|
end
|
data/test/request_store_test.rb
CHANGED
@@ -2,40 +2,39 @@ require 'minitest/autorun'
|
|
2
2
|
|
3
3
|
require 'request_store'
|
4
4
|
|
5
|
-
class RequestStoreTest < Minitest::
|
5
|
+
class RequestStoreTest < Minitest::Test
|
6
|
+
def setup
|
7
|
+
RequestStore.clear!
|
8
|
+
end
|
9
|
+
|
6
10
|
def test_initial_state
|
7
11
|
Thread.current[:request_store] = nil
|
8
12
|
assert_equal RequestStore.store, Hash.new
|
9
13
|
end
|
10
14
|
|
11
15
|
def test_init_with_hash
|
12
|
-
RequestStore.clear!
|
13
16
|
assert_equal Hash.new, RequestStore.store
|
14
17
|
end
|
15
18
|
|
16
19
|
def test_clear
|
17
|
-
RequestStore.clear!
|
18
20
|
RequestStore.store[:foo] = 1
|
19
21
|
RequestStore.clear!
|
20
22
|
assert_equal Hash.new, RequestStore.store
|
21
23
|
end
|
22
24
|
|
23
25
|
def test_quacks_like_hash
|
24
|
-
RequestStore.clear!
|
25
26
|
RequestStore.store[:foo] = 1
|
26
27
|
assert_equal 1, RequestStore.store[:foo]
|
27
28
|
assert_equal 1, RequestStore.store.fetch(:foo)
|
28
29
|
end
|
29
30
|
|
30
31
|
def test_read
|
31
|
-
RequestStore.clear!
|
32
32
|
RequestStore.store[:foo] = 1
|
33
33
|
assert_equal 1, RequestStore.read(:foo)
|
34
34
|
assert_equal 1, RequestStore[:foo]
|
35
35
|
end
|
36
36
|
|
37
37
|
def test_write
|
38
|
-
RequestStore.clear!
|
39
38
|
RequestStore.write(:foo, 1)
|
40
39
|
assert_equal 1, RequestStore.store[:foo]
|
41
40
|
RequestStore[:foo] = 2
|
@@ -43,20 +42,17 @@ class RequestStoreTest < Minitest::Unit::TestCase
|
|
43
42
|
end
|
44
43
|
|
45
44
|
def test_fetch
|
46
|
-
RequestStore.clear!
|
47
45
|
assert_equal 2, RequestStore.fetch(:foo) { 1 + 1 }
|
48
46
|
assert_equal 2, RequestStore.fetch(:foo) { 2 + 2 }
|
49
47
|
end
|
50
48
|
|
51
49
|
def test_delete
|
52
|
-
RequestStore.clear!
|
53
50
|
assert_equal 2, RequestStore.fetch(:foo) { 1 + 1 }
|
54
51
|
assert_equal 2, RequestStore.delete(:foo) { 2 + 2 }
|
55
52
|
assert_equal 4, RequestStore.delete(:foo) { 2 + 2 }
|
56
53
|
end
|
57
54
|
|
58
55
|
def test_delegates_to_thread
|
59
|
-
RequestStore.clear!
|
60
56
|
RequestStore.store[:foo] = 1
|
61
57
|
assert_equal 1, Thread.current[:request_store][:foo]
|
62
58
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: request_store
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Klabnik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '5.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '5.0'
|
41
41
|
description: RequestStore gives you per-request global storage.
|
42
42
|
email:
|
43
43
|
- steve@steveklabnik.com
|