rack-test 0.3.0 → 0.4.0
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/History.txt +16 -0
- data/lib/rack/mock_session.rb +7 -0
- data/lib/rack/test.rb +6 -5
- data/lib/rack/test/cookie_jar.rb +1 -1
- data/lib/rack/test/methods.rb +33 -5
- metadata +3 -3
data/History.txt
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
== 0.4.0 / 2009-06-25
|
2
|
+
|
3
|
+
* Minor enhancements
|
4
|
+
|
5
|
+
* Expose hook for building Rack::MockSessions for frameworks that need
|
6
|
+
to configure them before use
|
7
|
+
* Support passing in arrays of raw cookies in addition to a newline
|
8
|
+
separated string
|
9
|
+
* Support after_request callbacks in MockSession for things like running
|
10
|
+
background jobs
|
11
|
+
* Allow multiple named sessions using with_session
|
12
|
+
* Initialize Rack::Test::Sessions with Rack::MockSessions instead of apps.
|
13
|
+
This change should help integration with other Ruby web frameworks
|
14
|
+
(like Merb).
|
15
|
+
* Support sending bodies for PUT requests (Larry Diehl)
|
16
|
+
|
1
17
|
== 0.3.0 / 2009-05-17
|
2
18
|
|
3
19
|
* Major enhancements
|
data/lib/rack/mock_session.rb
CHANGED
@@ -3,12 +3,18 @@ module Rack
|
|
3
3
|
class MockSession
|
4
4
|
attr_writer :cookie_jar
|
5
5
|
attr_reader :last_response
|
6
|
+
attr_reader :default_host
|
6
7
|
|
7
8
|
def initialize(app, default_host = Rack::Test::DEFAULT_HOST)
|
8
9
|
@app = app
|
10
|
+
@after_request = []
|
9
11
|
@default_host = default_host
|
10
12
|
end
|
11
13
|
|
14
|
+
def after_request(&block)
|
15
|
+
@after_request << block
|
16
|
+
end
|
17
|
+
|
12
18
|
def clear_cookies
|
13
19
|
@cookie_jar = Rack::Test::CookieJar.new([], @default_host)
|
14
20
|
end
|
@@ -24,6 +30,7 @@ module Rack
|
|
24
30
|
@last_response = MockResponse.new(status, headers, body, env["rack.errors"].flush)
|
25
31
|
cookie_jar.merge(last_response.headers["Set-Cookie"], uri)
|
26
32
|
|
33
|
+
@after_request.each { |hook| hook.call }
|
27
34
|
@last_response
|
28
35
|
end
|
29
36
|
|
data/lib/rack/test.rb
CHANGED
@@ -14,7 +14,7 @@ require "rack/test/uploaded_file"
|
|
14
14
|
module Rack
|
15
15
|
module Test
|
16
16
|
|
17
|
-
VERSION = "0.
|
17
|
+
VERSION = "0.4.0"
|
18
18
|
|
19
19
|
DEFAULT_HOST = "example.org"
|
20
20
|
MULTIPART_BOUNDARY = "----------XnJLe9ZIbbGUYtzPQJ16u1"
|
@@ -29,10 +29,10 @@ module Rack
|
|
29
29
|
def_delegators :@rack_mock_session, :clear_cookies, :set_cookie, :last_response, :last_request
|
30
30
|
|
31
31
|
# Initialize a new session for the given Rack app
|
32
|
-
def initialize(
|
32
|
+
def initialize(mock_session)
|
33
33
|
@headers = {}
|
34
|
-
@
|
35
|
-
@
|
34
|
+
@rack_mock_session = mock_session
|
35
|
+
@default_host = mock_session.default_host
|
36
36
|
end
|
37
37
|
|
38
38
|
# Issue a GET request for the given URI with the given params and Rack
|
@@ -147,7 +147,8 @@ module Rack
|
|
147
147
|
env.update("HTTPS" => "on") if URI::HTTPS === uri
|
148
148
|
env["X-Requested-With"] = "XMLHttpRequest" if env[:xhr]
|
149
149
|
|
150
|
-
if (env[:method] == "POST" || env["REQUEST_METHOD"] == "POST"
|
150
|
+
if (env[:method] == "POST" || env["REQUEST_METHOD"] == "POST" ||
|
151
|
+
env[:method] == "PUT" || env["REQUEST_METHOD"] == "PUT") && !env.has_key?(:input)
|
151
152
|
env["CONTENT_TYPE"] = "application/x-www-form-urlencoded"
|
152
153
|
|
153
154
|
multipart = (Hash === env[:params]) &&
|
data/lib/rack/test/cookie_jar.rb
CHANGED
@@ -116,7 +116,7 @@ module Rack
|
|
116
116
|
def merge(raw_cookies, uri = nil)
|
117
117
|
return unless raw_cookies
|
118
118
|
|
119
|
-
raw_cookies.
|
119
|
+
Array(raw_cookies).join("\n").split("\n").each do |raw_cookie|
|
120
120
|
cookie = Cookie.new(raw_cookie, uri, @default_host)
|
121
121
|
self << cookie if cookie.valid?(uri)
|
122
122
|
end
|
data/lib/rack/test/methods.rb
CHANGED
@@ -5,12 +5,40 @@ module Rack
|
|
5
5
|
module Methods
|
6
6
|
extend Forwardable
|
7
7
|
|
8
|
-
def
|
9
|
-
|
8
|
+
def rack_mock_session(name = :default)
|
9
|
+
return build_rack_mock_session unless name
|
10
|
+
|
11
|
+
@_rack_mock_sessions ||= {}
|
12
|
+
@_rack_mock_sessions[name] ||= build_rack_mock_session
|
13
|
+
end
|
14
|
+
|
15
|
+
def build_rack_mock_session
|
16
|
+
Rack::MockSession.new(app)
|
17
|
+
end
|
18
|
+
|
19
|
+
def rack_test_session(name = :default)
|
20
|
+
return build_rack_test_session(name) unless name
|
21
|
+
|
22
|
+
@_rack_test_sessions ||= {}
|
23
|
+
@_rack_test_sessions[name] ||= build_rack_test_session(name)
|
24
|
+
end
|
25
|
+
|
26
|
+
def build_rack_test_session(name)
|
27
|
+
Rack::Test::Session.new(rack_mock_session(name))
|
28
|
+
end
|
29
|
+
|
30
|
+
def current_session
|
31
|
+
rack_test_session(_current_session_names.last)
|
32
|
+
end
|
33
|
+
|
34
|
+
def with_session(name)
|
35
|
+
_current_session_names.push(name)
|
36
|
+
yield rack_test_session(name)
|
37
|
+
_current_session_names.pop
|
10
38
|
end
|
11
39
|
|
12
|
-
def
|
13
|
-
@
|
40
|
+
def _current_session_names
|
41
|
+
@_current_session_names ||= [:default]
|
14
42
|
end
|
15
43
|
|
16
44
|
METHODS = [
|
@@ -39,7 +67,7 @@ module Rack
|
|
39
67
|
:last_request
|
40
68
|
]
|
41
69
|
|
42
|
-
def_delegators :
|
70
|
+
def_delegators :current_session, *METHODS
|
43
71
|
end
|
44
72
|
end
|
45
73
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-test
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan Helmkamp
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-06-25 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -58,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
58
|
requirements: []
|
59
59
|
|
60
60
|
rubyforge_project:
|
61
|
-
rubygems_version: 1.3.
|
61
|
+
rubygems_version: 1.3.4
|
62
62
|
signing_key:
|
63
63
|
specification_version: 3
|
64
64
|
summary: Simple testing API built on Rack
|