diff options
author | Alex Rakoczy & Matthew Horan <pair+arakoczy+mhoran@pivotallabs.com> | 2012-11-07 17:39:07 -0500 |
---|---|---|
committer | Alex Rakoczy & Matthew Horan <pair+arakoczy+mhoran@pivotallabs.com> | 2012-11-07 17:39:07 -0500 |
commit | 4d6cb5a09a65d27d67e4f691b572608d437af098 (patch) | |
tree | c0b8d419b6a08b1050c6d8e2e47975d19b91369e | |
parent | 98ab8e98741b86f1e569997978186692fa7ce422 (diff) | |
download | rack-4d6cb5a09a65d27d67e4f691b572608d437af098.tar.gz |
Additional Ruby 1.8 compaitiblity
Mappings are arrays of arrays to preserve order.
Define to_path on File objects in spec_sendfile.
-rw-r--r-- | lib/rack/sendfile.rb | 2 | ||||
-rw-r--r-- | test/spec_sendfile.rb | 26 |
2 files changed, 18 insertions, 10 deletions
diff --git a/lib/rack/sendfile.rb b/lib/rack/sendfile.rb index f24892fa..4cf6fa64 100644 --- a/lib/rack/sendfile.rb +++ b/lib/rack/sendfile.rb @@ -93,7 +93,7 @@ module Rack class Sendfile F = ::File - def initialize(app, variation=nil, mappings={}) + def initialize(app, variation=nil, mappings=[]) @app = app @variation = variation @mappings = mappings.map do |internal, external| diff --git a/test/spec_sendfile.rb b/test/spec_sendfile.rb index 21a49e79..0239de35 100644 --- a/test/spec_sendfile.rb +++ b/test/spec_sendfile.rb @@ -21,14 +21,22 @@ describe Rack::Sendfile do lambda { |env| [200, {'Content-Type' => 'text/plain'}, body] } end - def sendfile_app(body, mappings = {}) + def sendfile_app(body, mappings = []) Rack::Lint.new Rack::Sendfile.new(simple_app(body), nil, mappings) end - def request(headers={}, body=sendfile_body, mappings={}) + def request(headers={}, body=sendfile_body, mappings=[]) yield Rack::MockRequest.new(sendfile_app(body, mappings)).get('/', headers) end + def open_file(path) + Class.new(File) do + unless method_defined?(:to_path) + alias :to_path :path + end + end.open(path, 'w+') + end + it "does nothing when no X-Sendfile-Type header present" do request do |response| response.should.be.ok @@ -84,21 +92,21 @@ describe Rack::Sendfile do end end - it "sets X-Accel-Redirect response header and discards body when initialized with multiple mapping" do + it "sets X-Accel-Redirect response header and discards body when initialized with multiple mappings" do begin dir1 = Dir.mktmpdir dir2 = Dir.mktmpdir - first_body = File.open(File.join(dir1, 'rack_sendfile'), 'w+') + first_body = open_file(File.join(dir1, 'rack_sendfile')) first_body.puts 'hello world' - second_body = File.open(File.join(dir2, 'rack_sendfile'), 'w+') + second_body = open_file(File.join(dir2, 'rack_sendfile')) second_body.puts 'goodbye world' - mappings = { - "#{dir1}/" => '/foo/bar/', - "#{dir2}/" => '/wibble/' - } + mappings = [ + ["#{dir1}/", '/foo/bar/'], + ["#{dir2}/", '/wibble/'] + ] request({'HTTP_X_SENDFILE_TYPE' => 'X-Accel-Redirect'}, first_body, mappings) do |response| response.should.be.ok |