Commit Graph

31 Commits

Author SHA1 Message Date
Joshua Peek f9a792396c Set X-Cascade header when using pass
Setting X-Cascade: pass allows middleware outside the Sinatra stack
to continue trying to match the request.

Signed-off-by: Ryan Tomayko <rtomayko@gmail.com>
2009-12-23 20:48:19 -08:00
Blake Mizerany e20797047d passing a block to #pass will not 404, but eval the block
This is huge for writing extensions that install routes.
The developer can set the block to do default behaviour
if the app that registered the extension has not, or does
not want to, customize the route.

example:

  # MyFooExt
  ...
  def self.registered(app)
    app.get "/foo" do
      do_foo_things
      pass do
        "You hit foo!"
      end
    end
  end

At this point, as the user of MyFooExt, I can let the default
behaviour happen or override:

  # MySinatraApp
  require 'sinatra/my_foo_ext'

  class MySinatraApp < Sinatra::Base
    register MyFooExt

    get "/foo" do
      # MyFooExt has done do_foo_things
      do_our_foo_things
      "All foo things done"
    end
  end
2009-12-13 20:50:12 -08:00
Ryan Tomayko d5c5aca35f Better route and filter inheritance [#180] 2009-06-07 04:11:14 -07:00
Simon Rozet ecdd24adbe Another use of blake's custom options conditions
Can you come up with a better test name/description?
2009-05-18 03:37:28 -07:00
Blake Mizerany b8b9072a1a Allow custom options for conditions
Example:

module Sinatra
  module CustomConditionFu
    def authorized_for(*roles)
      condition { roles.include?(user.role) }
    end
  end
  register CustomConditionFu
end

delete '/everything', :authorized_for => [:admin] do
  everything.delete
end
2009-05-18 03:37:28 -07:00
Bob Aman 452a03045c Allow extensions to the routing system 2009-05-18 03:11:53 -07:00
Simon Rozet 2fa9fd81bb Use Rack::Test instead of Sinatra::Test for tests 2009-05-18 02:51:44 -07:00
Ryan Tomayko f3ce689965 set RACK_ENV in test/helper.rb to ensure sane environment 2009-04-25 09:17:11 -07:00
Ryan Tomayko da8271f05b clean up routing spec description 2009-04-25 06:14:11 -07:00
Simon Rozet 87bf495b11 Ensure development NotFound handler always returns text/html 2009-04-19 20:01:33 -07:00
Simon Rozet ff0d068687 Use contest instead of test/spec/mini
See <http://github.com/citrusbyte/contest> for more info. The
contest.rb file is included under the test/ directory.
2009-03-31 02:23:48 -07:00
Ryan Tomayko 6fd8aaadd1 Move a few specs out of base_test and into more appropriate tests 2009-02-22 01:04:01 -08:00
Ryan Tomayko a2f5803ec6 Allow dot in named param capture [#153] 2009-02-17 09:32:58 -08:00
Ryan Tomayko d212de6abf Fix routes don't match with certain forms of URL encoding [#147]
We no longer store routes in URL encoded form and unescape the
PATH_INFO before attempting to match routes. This allows matching
all variations of encoded characters but does not allow matching
encoded "/" characters in the PATH_INFO.

See also:

http://sinatra.lighthouseapp.com/projects/9779/tickets/147
http://groups.google.com/group/sinatrarb/browse_thread/thread/baab6ea877d7c2e4
2009-02-17 08:07:38 -08:00
Brandon Dimcheff e8d36e8c51 fixed 1.9 too many values test case 2009-02-02 19:07:16 -08:00
Ryan Tomayko dfcb252773 Fix block param arity handling under 1.9
This modifies the way block params are handled so that block params
have 1.8 semantics under 1.8 and 1.9 semantics under 1.9.

* Spec Ruby 1.9 such that mismatched arity raises an ArgumentError.

* Spec Ruby 1.8 such that mismatched arity does not raise an
  ArgumentError.

* Do not attempt to pass block params to handlers defined with 0
  arity. This avoids the ArgumentError for 0 arity blocks on 1.9
  with the common case route that defines no block params but does
  include parameter captures/splats.

Coding for Ruby 1.9 results in code that is compatible with both
versions.
2009-02-02 18:49:12 -08:00
bmizerany 33c1a76891 Always make sure you're asserting that assertions were run. 2009-01-31 15:07:13 -08:00
Brandon Dimcheff 6569d1b0fd Added route block params in routing statements [#140] 2009-01-31 14:52:59 -08:00
Devlin Daley a1d9001a7a Fix :provides crashes with no Accept header [#139]
An exception was raised on every request that did not have an
Accept header due to the Accept parsing code calling split on
nil.

The Sinatra::Request#accept method now returns an empty collection
if the HTTP Accept header is not present.
2009-01-29 03:15:55 -08:00
Ryan Tomayko 0ade0beec8 Much needed refactoring in dispatching code [#131]/[#127]
This moves the :halt catch out so that all routing code runs
within one giant catch block instead of running each type
of handler in its own catch block. This required some cleanup
in the error handling code, which cleaned things up quite a bit.

This corrects two issues:

1. halt with > 1 args causes ArgumentError
   http://sinatra.lighthouseapp.com/projects/9779/tickets/131

2. halting in a before filter doesn't modify response
   http://sinatra.lighthouseapp.com/projects/9779/tickets/127

We still need to split up the more epic methods (#route!, #invoke)
but the logic is pretty sound at this point.
2009-01-24 23:57:20 -08:00
Markus Prinz 12eced8414 Escape '.', '+', '$' and parens in literal paths [#124]
Since Sinatra turns literal paths into a regular expression,
we need to escape dots and pluses, as they have special
meanings inside a regex, but not ?, since we need that
for optional parameters.
2009-01-23 01:49:27 -08:00
Pat Nakajima 40cd096b4f Preserve non-nested params in nested params hash [#117] 2009-01-22 00:56:32 -08:00
Ryan Tomayko bc7a939ce2 General spec coverage improvements (rcov: 98%) 2009-01-19 17:58:26 -08:00
Ryan Tomayko e9a784299b Use Rack's build_query; remove Sinatra::Test#env_for (unused) 2009-01-18 17:30:11 -08:00
Nicolas Sanguinetti 1fa9807f4b Nested params (e.g., "post[title]=Hello") [#70]
This is based largely on manveru's example implementation:

http://paste.linuxhelp.tv/pastes/view/15309

NOTE: we should plan on ripping this out once nested params
makes it into Rack.
2009-01-16 08:26:31 -08:00
Ryan Tomayko 661090eb53 Allow assertions in mock_app request context
I changed the ".should." style to use "fail" when we
converted to test/unit style but I'd rather use asserts
here.
2009-01-15 04:18:18 -08:00
Ryan Tomayko 72a6e01daf use Test::Unit style assertions in Sinatra specs 2009-01-14 14:00:26 -08:00
Ryan Tomayko c00a25ee41 Test framework refactoring
* Adds test/helper.rb and moves mock_app and other code specific
  to testing the framework out of Sinatra::Test.
* Do not require test/unit. The sinatra/test/unit,
  sinatra/test/spec, and sinatra/test/rspec files can be used to
  choose the framework.
* Add Sinatra::TestHarness, which should act similar to the
  Rack::Session proposal here: http://gist.github.com/41270
* Update the README with information on using the different test
  frameworks.
2009-01-14 07:52:04 -08:00
Ryan Tomayko 49c60151bf Fix ruby warnings
Cleans up all warnings generated from Sinatra. There's still
a bunch of warnings coming from HAML, though. It would be nice
if we could use Kernel#warn for deprecation notices but that's
going to be annoying if there's a bunch of unrelated warnings
from other libs.
2009-01-09 01:49:50 -08:00
Markus Prinz 38778eddda Add filtering support for Accept HTTP header.
Adds an "provides"-option to a route definition, which can either be
a string specifying a MIME type, a symbol that Rack can resolve to
a MIME type, or an array of either.
2009-01-07 15:15:12 -08:00
Ryan Tomayko a734cf38ac I knew I shoulda taken that left turn at Hoboken
This is a fairly large reworking of Sinatra's innards. Although
most of the internal implementation has been modified, it
provides the same basic feature set and is meant to be compatible
with Sinatra 0.3.2.

* The Event and EventContext classes have been removed. Sinatra
  applications are now defined within the class context of a
  Sinatra::Base subclass; each request is processed within a new
  instance.

* Sinatra::Base can be used as a base class for multiple
  Rack applications within a single process and can be used as
  Rack middleware.

* The routing and result type processing implementation has been
  simplified and enhanced a bit. There's a new route conditions
  system for things like :agent/:host matching and a request
  level #pass method has been added to allow an event handler to
  exit immediately, passing control to the next matching route.

* Regular expressions may now be used in route patterns. Captures
  are available as an array from "params[:captures]".

* The #body helper method now takes a block. The block is not
  evaluated until an attempt is made to read the body.

* Options are now dynamically generated class attributes on the
  Sinatra::Base subclass (instead of OpenStruct); options are
  inherited by subclasses and may be overridden up the
  inheritance hierarchy. The Base.set manages all option related
  stuff.

* The application file (app_file) detection heuristics are bit
  more sane now. This fixes some bugs with reloading and
  public/views directory detection. All thin / passenger issues
  of these type should be better now.

* Error mappings are now split into to distinct layers: exception
  mappings and custom error pages. Exception mappings are registered
  with 'error(Exception)' and are run only when the app raises an
  exception. Custom error pages are registered with error(status_code)
  and are run any time the response has the status code specified.
  It's also possible to register an error page for a range of status
  codes: 'error(500..599)'.

* The spec and unit testing extensions have been modified to take
  advantage of the ability to have multiple Sinatra applications.
  The Sinatra::Test module must be included within the TestCase
  in order to take advantage of these methods (unless the
  'sinatra/compat' library has been required).

* Rebuilt specs from scratch for better coverage and
  organization. Sinatra 3.2 unit tests have been retained
  under ./compat to ensure a baseline level of compatibility with
  previous versions; use the 'rake compat' task to run these.

A large number of existing Sinatra idioms have been deprecated but
continue to be supported through the 'sinatra/compat' library.

* The "set_option" and "set_options" methods have been deprecated
  due to redundancy; use "set".

* The "env" option (Sinatra::Base.env) has been renamed to "environment"
  and deprecated because it's too easy to confuse with the request-level
  Rack environment Hash (Sinatra::Base#env).

* The request level "stop" method has been renamed "halt" and
  deprecated. This is for consistency with `throw :halt`.

* The request level "entity_tag" method has been renamed "etag" and
  deprecated. Both versions were previously supported.

* The request level "headers" method has been deprecated. Use
  response['Header-Name'] to access and modify response headers.

* Sinatra.application is deprecated. Use Sinatra::Application instead.

* Setting Sinatra.application = nil to reset an application is
  deprecated. You shouldn't have to reset objects anymore.

* The Sinatra.default_options Hash is deprecated. Modifying this object now
  results in "set(key, value)" invocations on the Sinatra::Base
  subclass.

* The "body.to_result" convention has been deprecated.

* The ServerError exception has been deprecated. Any Exception is now
  considered a ServerError.
2008-12-20 18:45:28 -08:00