mirror of
https://github.com/sinatra/sinatra
synced 2023-03-27 23:18:01 -04:00
491023a17b
Execute the before filters before looking up the event. Makes it possible for filters to rewrite request variables such as PATH_INFO and REQUEST_METHOD and have it effect which route is chosen.
30 lines
678 B
Ruby
30 lines
678 B
Ruby
require File.dirname(__FILE__) + '/helper'
|
|
|
|
context "before filters" do
|
|
|
|
setup do
|
|
Sinatra.application = nil
|
|
@app = Sinatra.application
|
|
end
|
|
|
|
specify "should be executed in the order defined" do
|
|
invoked = 0x0
|
|
@app.before { invoked = 0x01 }
|
|
@app.before { invoked |= 0x02 }
|
|
@app.get('/') { 'Hello World' }
|
|
get_it '/'
|
|
should.be.ok
|
|
body.should.be == 'Hello World'
|
|
invoked.should.be == 0x03
|
|
end
|
|
|
|
specify "should be capable of modifying the request" do
|
|
@app.get('/foo') { 'foo' }
|
|
@app.get('/bar') { 'bar' }
|
|
@app.before { request.path_info = '/bar' }
|
|
get_it '/foo'
|
|
should.be.ok
|
|
body.should.be == 'bar'
|
|
end
|
|
|
|
end
|