1
0
Fork 0
mirror of https://github.com/thoughtbot/shoulda-matchers.git synced 2022-11-09 12:01:38 -05:00
thoughtbot--shoulda-matchers/spec/shoulda/matchers/action_controller/route_matcher_spec.rb

66 lines
1.9 KiB
Ruby
Raw Normal View History

require 'spec_helper'
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
get 'examples/*id', :to => 'examples#example'
end
2012-03-16 12:15:23 -04:00
controller.should route(:get, '/examples/foo/bar').
to(:action => 'example', :id => 'foo/bar')
end
end
2012-12-20 00:04:27 -05:00
context 'given a controller with a defined route' do
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')
end
2012-12-20 00:04:27 -05:00
it 'accepts a symbol controller' do
route_examples_to_examples
Object.new.should route(:get, '/examples/1').
2012-12-20 00:04:27 -05:00
to(:controller => :examples, :action => 'example', :id => '1')
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')
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)
end
2012-12-20 00:04:27 -05:00
it 'rejects an undefined route' do
route_examples_to_examples.
should_not route(:get, '/bad_route').to(:var => 'value')
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')
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')
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
end
end