2014-05-09 06:39:16 +00:00
|
|
|
require 'spec_helper'
|
2011-09-05 01:13:27 +00:00
|
|
|
|
|
|
|
describe Sinatra::MultiRoute do
|
2012-12-09 16:47:08 +00:00
|
|
|
|
|
|
|
it 'does not break normal routing' do
|
2011-09-05 01:13:27 +00:00
|
|
|
mock_app do
|
|
|
|
register Sinatra::MultiRoute
|
|
|
|
get('/') { 'normal' }
|
|
|
|
end
|
|
|
|
|
|
|
|
get('/').should be_ok
|
|
|
|
body.should be == 'normal'
|
|
|
|
end
|
|
|
|
|
2012-12-09 16:35:15 +00:00
|
|
|
it 'supports multiple routes' do
|
2012-12-09 16:47:08 +00:00
|
|
|
mock_app do
|
|
|
|
register Sinatra::MultiRoute
|
|
|
|
get('/foo', '/bar') { 'paths' }
|
|
|
|
end
|
|
|
|
|
2011-09-05 01:13:27 +00:00
|
|
|
get('/foo').should be_ok
|
|
|
|
body.should be == 'paths'
|
|
|
|
get('/bar').should be_ok
|
|
|
|
body.should be == 'paths'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'triggers conditions' do
|
2012-12-09 16:47:08 +00:00
|
|
|
count = 0
|
|
|
|
mock_app do
|
|
|
|
register Sinatra::MultiRoute
|
|
|
|
set(:some_condition) { |_| count += 1 }
|
|
|
|
get('/foo', '/bar', :some_condition => true) { 'paths' }
|
|
|
|
end
|
|
|
|
|
|
|
|
count.should be == 4
|
2011-09-05 01:13:27 +00:00
|
|
|
end
|
|
|
|
|
2012-12-09 16:35:15 +00:00
|
|
|
it 'supports multiple verbs' do
|
2012-12-09 16:47:08 +00:00
|
|
|
mock_app do
|
|
|
|
register Sinatra::MultiRoute
|
|
|
|
route('PUT', 'POST', '/') { 'verb' }
|
|
|
|
end
|
|
|
|
|
2011-09-05 01:13:27 +00:00
|
|
|
post('/').should be_ok
|
|
|
|
body.should be == 'verb'
|
|
|
|
put('/').should be_ok
|
|
|
|
body.should be == 'verb'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'takes symbols as verbs' do
|
2012-12-09 16:47:08 +00:00
|
|
|
mock_app do
|
|
|
|
register Sinatra::MultiRoute
|
|
|
|
route(:get, '/baz') { 'symbol as verb' }
|
|
|
|
end
|
|
|
|
|
2011-09-05 01:13:27 +00:00
|
|
|
get('/baz').should be_ok
|
|
|
|
body.should be == 'symbol as verb'
|
|
|
|
end
|
2012-12-09 16:35:15 +00:00
|
|
|
end
|