~michaelforrest/use-case-mapper/trunk

« back to all changes in this revision

Viewing changes to vendor/rails/actionpack/lib/action_controller/rack_lint_patch.rb

  • Committer: Richard Lee (Canonical)
  • Date: 2010-10-15 15:17:58 UTC
  • mfrom: (190.1.3 use-case-mapper)
  • Revision ID: richard.lee@canonical.com-20101015151758-wcvmfxrexsongf9d
Merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Rack 1.0 does not allow string subclass body. This does not play well with our ActionView::SafeBuffer.
2
 
# The next release of Rack will be allowing string subclass body - http://github.com/rack/rack/commit/de668df02802a0335376a81ba709270e43ba9d55
3
 
# TODO : Remove this monkey patch after the next release of Rack
4
 
 
5
 
module RackLintPatch
6
 
  module AllowStringSubclass
7
 
    def self.included(base)
8
 
      base.send :alias_method, :each, :each_with_hack
9
 
    end
10
 
 
11
 
    def each_with_hack
12
 
      @closed = false
13
 
 
14
 
      @body.each { |part|
15
 
        assert("Body yielded non-string value #{part.inspect}") {
16
 
          part.kind_of?(String)
17
 
        }
18
 
        yield part
19
 
      }
20
 
 
21
 
      if @body.respond_to?(:to_path)
22
 
        assert("The file identified by body.to_path does not exist") {
23
 
          ::File.exist? @body.to_path
24
 
        }
25
 
      end
26
 
    end
27
 
  end
28
 
 
29
 
  begin
30
 
    app = proc {|env| [200, {"Content-Type" => "text/plain", "Content-Length" => "12"}, [Class.new(String).new("Hello World!")]] }
31
 
    response = Rack::MockRequest.new(Rack::Lint.new(app)).get('/')
32
 
  rescue Rack::Lint::LintError => e
33
 
    raise(e) unless e.message =~ /Body yielded non-string value/
34
 
    Rack::Lint.send :include, AllowStringSubclass
35
 
  end
36
 
end