2010-12-13 17:28:59 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2013-05-17 11:17:21 -04:00
|
|
|
describe Shoulda::Matchers::ActionController::RouteMatcher, type: :controller do
|
2012-12-20 00:04:27 -05:00
|
|
|
context 'given a controller with a defined glob url' do
|
|
|
|
it 'accepts glob route' do
|
|
|
|
controller = define_controller('Examples').new
|
2012-03-16 12:15:23 -04:00
|
|
|
|
2010-12-14 18:35:12 -05:00
|
|
|
define_routes do
|
2013-05-10 16:54:48 -04:00
|
|
|
get 'examples/*id', :to => 'examples#example'
|
2010-12-13 17:28:59 -05:00
|
|
|
end
|
|
|
|
|
2012-03-16 12:15:23 -04:00
|
|
|
controller.should route(:get, '/examples/foo/bar').
|
|
|
|
to(:action => 'example', :id => 'foo/bar')
|
2010-12-13 17:28:59 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-20 00:04:27 -05:00
|
|
|
context 'given a controller with a defined route' do
|
2010-12-13 17:28:59 -05:00
|
|
|
|
2012-12-20 00:04:27 -05:00
|
|
|
it 'accepts routing the correct path to the correct parameters' do
|
|
|
|
route_examples_to_examples.should route(:get, '/examples/1').
|
2012-03-16 12:15:23 -04:00
|
|
|
to(:action => 'example', :id => '1')
|
2010-12-13 17:28:59 -05:00
|
|
|
end
|
|
|
|
|
2012-12-20 00:04:27 -05:00
|
|
|
it 'accepts a symbol controller' do
|
|
|
|
route_examples_to_examples
|
2010-12-13 17:28:59 -05:00
|
|
|
Object.new.should route(:get, '/examples/1').
|
2012-12-20 00:04:27 -05:00
|
|
|
to(:controller => :examples, :action => 'example', :id => '1')
|
2010-12-13 17:28:59 -05:00
|
|
|
end
|
|
|
|
|
2012-12-20 00:04:27 -05:00
|
|
|
it 'accepts a symbol action' do
|
|
|
|
route_examples_to_examples.should route(:get, '/examples/1').
|
2012-03-16 12:15:23 -04:00
|
|
|
to(:action => :example, :id => '1')
|
2010-12-13 17:28:59 -05:00
|
|
|
end
|
|
|
|
|
2012-12-20 00:04:27 -05:00
|
|
|
it 'accepts a non-string parameter' do
|
|
|
|
route_examples_to_examples.should route(:get, '/examples/1').
|
2012-03-16 12:15:23 -04:00
|
|
|
to(:action => 'example', :id => 1)
|
2010-12-13 17:28:59 -05:00
|
|
|
end
|
|
|
|
|
2012-12-20 00:04:27 -05:00
|
|
|
it 'rejects an undefined route' do
|
2013-03-15 02:32:53 -04:00
|
|
|
route_examples_to_examples.
|
|
|
|
should_not route(:get, '/bad_route').to(:var => 'value')
|
2010-12-13 17:28:59 -05:00
|
|
|
end
|
|
|
|
|
2012-12-20 00:04:27 -05:00
|
|
|
it 'rejects a route for another controller' do
|
|
|
|
route_examples_to_examples
|
2012-03-16 12:15:23 -04:00
|
|
|
other = define_controller('Other').new
|
|
|
|
other.should_not route(:get, '/examples/1').
|
|
|
|
to(:action => 'example', :id => '1')
|
2010-12-13 17:28:59 -05:00
|
|
|
end
|
|
|
|
|
2012-12-20 00:04:27 -05:00
|
|
|
it 'rejects a route for different parameters' do
|
|
|
|
route_examples_to_examples.should_not route(:get, '/examples/1').
|
2012-03-16 12:15:23 -04:00
|
|
|
to(:action => 'other', :id => '1')
|
2010-12-13 17:28:59 -05:00
|
|
|
end
|
2012-12-20 00:04:27 -05:00
|
|
|
|
|
|
|
def route_examples_to_examples
|
|
|
|
define_routes do
|
|
|
|
get 'examples/:id', :to => 'examples#example'
|
|
|
|
end
|
|
|
|
|
|
|
|
define_controller('Examples').new
|
|
|
|
end
|
2010-12-13 17:28:59 -05:00
|
|
|
end
|
|
|
|
end
|