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