thoughtbot--shoulda-matchers/spec/shoulda/matchers/action_controller/route_matcher_spec.rb

71 lines
2.1 KiB
Ruby
Raw Normal View History

require 'spec_helper'
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'
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')
end
end
2012-12-20 05:04:27 +00:00
context 'given a controller with a defined route' do
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')
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')
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')
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)
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')
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')
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')
end
2012-12-20 05:04:27 +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').
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
end
end