Permalink
Browse files

Merge pull request #790 from GateGuru/feature/enable-options-in-stati…

…c-method

Feature/enable options in static method
  • Loading branch information...
2 parents 525319b + 8fb79ac commit faf2efc670bf4c6076c26d5234c577950c19b699 @rkh rkh committed Feb 21, 2014
Showing with 20 additions and 3 deletions.
  1. +2 −2 lib/sinatra/base.rb
  2. +18 −1 test/static_test.rb
View
@@ -1023,14 +1023,14 @@ def route_missing
# Attempt to serve static files from public directory. Throws :halt when
# a matching file is found, returns nil otherwise.
- def static!
+ def static!(options = {})
return if (public_dir = settings.public_folder).nil?
path = File.expand_path("#{public_dir}#{unescape(request.path_info)}" )
return unless File.file?(path)
env['sinatra.static_file'] = path
cache_control(*settings.static_cache_control) if settings.static_cache_control?
- send_file path, :disposition => nil
+ send_file path, options.merge(:disposition => nil)
end
# Enable string or symbol key access to the nested params hash.
View
@@ -216,4 +216,21 @@ def assert_valid_range(http_range, range, path, file)
)
end
-end
+ it 'renders static assets with custom status via options' do
+ mock_app do
+ set :static, true
+ set :public_folder, File.dirname(__FILE__)
+
+ post '/*' do
+ static!(:status => params[:status])
+ end
+ end
+
+ post "/#{File.basename(__FILE__)}?status=422"
+ assert_equal response.status, 422
+ assert_equal File.read(__FILE__), body
+ assert_equal File.size(__FILE__).to_s, response['Content-Length']
+ assert response.headers.include?('Last-Modified')
+ end
+
+end

0 comments on commit faf2efc

Please sign in to comment.