Sha256: 16a6a95b0795326f435ac5adce9f648b041f15940e48e032aaf1918cb5e8c347

Contents?: true

Size: 1.7 KB

Versions: 14

Compression:

Stored size: 1.7 KB

Contents

require 'spec/helper'

describe 'Dispatcher::File' do
  behaves_like 'http'
  @public_root = 'spec/ramaze/dispatcher/public'
  ramaze :public_root => @public_root

  it 'should serve from Global.public_root' do
    css = File.read(@public_root/'test_download.css')
    re_css = get('/test_download.css')
    re_css.body.should == css
    re_css.status.should == 200
  end

  it 'should give priority to Global.public_root' do
    file = (@public_root/'favicon.ico')
    if RUBY_VERSION >= '1.9.0'
      original = File.open(file, 'r:ASCII'){|f| f.read}
    else
      original = File.read(file)
    end
    get('/favicon.ico').body.should == original
  end

  it 'should work on files with spaces' do
    res = get('/file%20name.txt')
    res.status.should == 200
    res.body.should == 'hi'
  end

  it 'should send ETag' do
    res = get '/test_download.css'
    res.headers['ETag'].should.not.be == nil
    res.headers['ETag'].length.should == 34  # "32 hash"
  end

  it 'should send Last-Modified' do
    res = get '/test_download.css'
    res.headers['Last-Modified'].should.not.be == nil
    res.headers['Last-Modified'].should == File.mtime(@public_root/'test_download.css').httpdate
  end

  it 'should respect ETag with IF_NONE_MATCHES' do
    res = get '/test_download.css'
    etag = res.headers['ETag']
    etag.should.not.be == nil
    res = get '/test_download.css', :if_none_match=>etag
    res.status.should == 304
    res.body.should == ''
  end

  it 'should respect If-Modified' do
    res = get '/test_download.css'
    mtime = res.headers['Last-Modified']
    mtime.should.not.be == nil
    res = get '/test_download.css', :if_modified_since=>mtime
    res.status.should == 304
    res.body.should == ''
  end
end

Version data entries

14 entries across 14 versions & 4 rubygems

Version Path
Pistos-ramaze-2008.09 spec/ramaze/dispatcher/file.rb
Pistos-ramaze-2008.12 spec/ramaze/dispatcher/file.rb
Pistos-ramaze-2009.01 spec/ramaze/dispatcher/file.rb
Pistos-ramaze-2009.02 spec/ramaze/dispatcher/file.rb
manveru-ramaze-2008.09 spec/ramaze/dispatcher/file.rb
manveru-ramaze-2008.10 spec/ramaze/dispatcher/file.rb
manveru-ramaze-2008.12 spec/ramaze/dispatcher/file.rb
manveru-ramaze-2009.01 spec/ramaze/dispatcher/file.rb
ptomato-ramaze-2009.02.1 spec/ramaze/dispatcher/file.rb
ptomato-ramaze-2009.02 spec/ramaze/dispatcher/file.rb
ramaze-2009.01 spec/ramaze/dispatcher/file.rb
ramaze-2008.11 spec/ramaze/dispatcher/file.rb
ramaze-2009.03 spec/ramaze/dispatcher/file.rb
ramaze-2009.02 spec/ramaze/dispatcher/file.rb