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