avdi-rack_base_uri 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -26,7 +26,16 @@ module Rack
26
26
 
27
27
  result = @app.call(env)
28
28
  headers = result[1]
29
- doc = Hpricot(result[2].to_s)
29
+
30
+ # We have to get the content this way because the Rack spec only
31
+ # guarantees the presence of an #each method that yields Strings. We
32
+ # can't expect #inject or #to_s or anything.
33
+ content = ""
34
+ result[2].each do |chunk|
35
+ content << chunk
36
+ end
37
+
38
+ doc = Hpricot(content)
30
39
  case headers['Content-Type']
31
40
  when 'text/html'
32
41
  (doc/'head').append("<base href='#{base}'>")
@@ -5,6 +5,21 @@ require 'rack/urlmap'
5
5
  require 'hpricot'
6
6
 
7
7
  describe Rack::BaseUri do
8
+
9
+ # This class is used to keep us honest... we can only depend on the content
10
+ # responding to each, not necessarily that it is Array-like.
11
+ class ContentStream
12
+ def initialize(content)
13
+ @content = content
14
+ end
15
+
16
+ def each
17
+ @content.each do |chunk|
18
+ yield chunk
19
+ end
20
+ end
21
+ end
22
+
8
23
  before :each do
9
24
  @headers = {'Content-Type' => 'text/html'}
10
25
  @body = <<-HTML
@@ -18,7 +33,7 @@ describe Rack::BaseUri do
18
33
  @result = [
19
34
  200,
20
35
  @headers,
21
- [@body]
36
+ ContentStream.new(@body)
22
37
  ]
23
38
  @app = stub("app", :call => @result)
24
39
  @it = Rack::BaseUri.new(@app)
@@ -29,7 +44,7 @@ describe Rack::BaseUri do
29
44
  def do_request
30
45
  @map = Rack::URLMap.new({@base => @it})
31
46
  @request = Rack::MockRequest.new(@map)
32
- @response = @request.get("/subdir/foo", 'HTTP_HOST' => @host)
47
+ @response = @request.get("/subdir/foo", 'HTTP_HOST' => @host, :lint => true)
33
48
  @doc = Hpricot(@response.body)
34
49
  end
35
50
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avdi-rack_base_uri
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Avdi Grimm