sinatra/test
Mike Pastore 2128dcfb31 Add default_content_type setting
Historically, Sinatra::Response defaults to a text/html Content-Type.
However, in practice, Sinatra immediately clears this attribute after
instantiating a new Sinatra::Response object, so this default is some-
what suspect. Let's break this behavior and have Sinatra::Response
be Content-Type-less by default, and update the tests to reflect this.

Next, let's introduce a new default_content_type setting that will be
applied (instead of text/html) if the Content-Type is not set before the
response is finalized. This will be great for e.g. JSON API developers.
Let's also make it nil-able to indicate that a default Content-Type
should never be applied.

Wherever Sinatra is emitting HTML, e.g. in error pages, force the
Content-Type to text/html.

Finally, clean up the error-handling logic to behave as follows:

* Set the X-Cascade header as early as possible.
* If an error block matches and returns a value, stop processing and
  return that value.
* If we have a not found or bad request error, inspect the exception (if
  any) for an error message and present it as the response body if it
  exists, or present a default error message.

The remaining logic is the same otherwise. This should make error
handlers simpler to write and behave more consistently by not polluting
the body with a default message when none may be necessary.
2020-03-19 15:34:43 -04:00
..
integration Test added 2013-09-25 02:33:47 +04:00
public Used URI_INSTANCE unescape method instead of wild unescape function in the static files path computation 2015-07-20 17:10:34 +02:00
views Remove sass warnings 2018-02-20 01:17:50 +09:00
asciidoctor_test.rb Ruby 2: use __dir__ instead of File.dirname(__FILE__) (#1341) 2020-03-13 17:20:04 -04:00
base_test.rb - Removed test-unit dependency 2015-01-11 01:00:47 +05:30
builder_test.rb Ruby 2: use __dir__ instead of File.dirname(__FILE__) (#1341) 2020-03-13 17:20:04 -04:00
coffee_test.rb Ruby 2: use __dir__ instead of File.dirname(__FILE__) (#1341) 2020-03-13 17:20:04 -04:00
compile_test.rb Expose global and per-route Mustermann options 2017-01-13 18:01:47 -06:00
contest.rb - Removed test-unit dependency 2015-01-11 01:00:47 +05:30
creole_test.rb Ruby 2: use __dir__ instead of File.dirname(__FILE__) (#1341) 2020-03-13 17:20:04 -04:00
delegator_test.rb - Removed test-unit dependency 2015-01-11 01:00:47 +05:30
encoding_test.rb Ruby 2: use __dir__ instead of File.dirname(__FILE__) (#1341) 2020-03-13 17:20:04 -04:00
erb_test.rb Ruby 2: use __dir__ instead of File.dirname(__FILE__) (#1341) 2020-03-13 17:20:04 -04:00
extensions_test.rb - Removed test-unit dependency 2015-01-11 01:00:47 +05:30
filter_test.rb Ruby 2: use __dir__ instead of File.dirname(__FILE__) (#1341) 2020-03-13 17:20:04 -04:00
haml_test.rb Ruby 2: use __dir__ instead of File.dirname(__FILE__) (#1341) 2020-03-13 17:20:04 -04:00
helper.rb Ruby 2: use __dir__ instead of File.dirname(__FILE__) (#1341) 2020-03-13 17:20:04 -04:00
helpers_test.rb Use prepend instead of include for helpers. Fixes #1213 (#1214) 2020-03-18 10:13:24 -04:00
indifferent_hash_test.rb Merge pull request #1572 from iguchi1124/support-ruby26-merge 2020-01-02 04:44:44 +09:00
integration_helper.rb Move get_response and get_stream to Sinatra::Runner 2016-08-17 19:37:46 +09:00
integration_test.rb Update Rack handler call to use kw args 2020-03-18 15:49:49 -04:00
less_test.rb Ruby 2: use __dir__ instead of File.dirname(__FILE__) (#1341) 2020-03-13 17:20:04 -04:00
liquid_test.rb Ruby 2: use __dir__ instead of File.dirname(__FILE__) (#1341) 2020-03-13 17:20:04 -04:00
mapped_error_test.rb - Removed test-unit dependency 2015-01-11 01:00:47 +05:30
markaby_test.rb Ruby 2: use __dir__ instead of File.dirname(__FILE__) (#1341) 2020-03-13 17:20:04 -04:00
markdown_test.rb Ruby 2: use __dir__ instead of File.dirname(__FILE__) (#1341) 2020-03-13 17:20:04 -04:00
mediawiki_test.rb Ruby 2: use __dir__ instead of File.dirname(__FILE__) (#1341) 2020-03-13 17:20:04 -04:00
middleware_test.rb avoid multiple errors even if `params` contains special values 2019-04-22 22:39:32 +09:00
nokogiri_test.rb Ruby 2: use __dir__ instead of File.dirname(__FILE__) (#1341) 2020-03-13 17:20:04 -04:00
rabl_test.rb Ruby 2: use __dir__ instead of File.dirname(__FILE__) (#1341) 2020-03-13 17:20:04 -04:00
rack_test.rb - Removed test-unit dependency 2015-01-11 01:00:47 +05:30
radius_test.rb Ruby 2: use __dir__ instead of File.dirname(__FILE__) (#1341) 2020-03-13 17:20:04 -04:00
rdoc_test.rb Ruby 2: use __dir__ instead of File.dirname(__FILE__) (#1341) 2020-03-13 17:20:04 -04:00
readme_test.rb - Removed test-unit dependency 2015-01-11 01:00:47 +05:30
request_test.rb Add support for parameters when creating mime types (#1256) 2020-03-13 17:02:56 -04:00
response_test.rb Add default_content_type setting 2020-03-19 15:34:43 -04:00
result_test.rb change all Fixnum to Integer in readmes 2018-11-07 16:02:10 +08:00
route_added_hook_test.rb - Removed test-unit dependency 2015-01-11 01:00:47 +05:30
routing_test.rb Fix issue with passed routes and provides (#1606) 2020-03-16 15:18:58 -04:00
sass_test.rb Ruby 2: use __dir__ instead of File.dirname(__FILE__) (#1341) 2020-03-13 17:20:04 -04:00
scss_test.rb Ruby 2: use __dir__ instead of File.dirname(__FILE__) (#1341) 2020-03-13 17:20:04 -04:00
server_test.rb Changelog and test. 2016-11-22 10:13:13 -05:00
settings_test.rb Add default_content_type setting 2020-03-19 15:34:43 -04:00
sinatra_test.rb - Removed test-unit dependency 2015-01-11 01:00:47 +05:30
slim_test.rb Ruby 2: use __dir__ instead of File.dirname(__FILE__) (#1341) 2020-03-13 17:20:04 -04:00
static_test.rb Ruby 2: use __dir__ instead of File.dirname(__FILE__) (#1341) 2020-03-13 17:20:04 -04:00
streaming_test.rb - Removed test-unit dependency 2015-01-11 01:00:47 +05:30
stylus_test.rb Ruby 2: use __dir__ instead of File.dirname(__FILE__) (#1341) 2020-03-13 17:20:04 -04:00
templates_test.rb Ruby 2: use __dir__ instead of File.dirname(__FILE__) (#1341) 2020-03-13 17:20:04 -04:00
textile_test.rb Ruby 2: use __dir__ instead of File.dirname(__FILE__) (#1341) 2020-03-13 17:20:04 -04:00
wlang_test.rb Ruby 2: use __dir__ instead of File.dirname(__FILE__) (#1341) 2020-03-13 17:20:04 -04:00
yajl_test.rb Ruby 2: use __dir__ instead of File.dirname(__FILE__) (#1341) 2020-03-13 17:20:04 -04:00