How to test routes that don't include controller?
- by Darren Green
I'm using minitest in Rails to do testing, but I'm running into a problem that I hope a more seasoned tester can help me out with because I've tried looking everywhere for the answer, but it doesn't seem that anyone has run into this problem or if they have, they opted for an integration test.
Let's say I have a controller called Foo and action in it called bar. So the foo_controller.rb file looks like this:
class FooController < ApplicationController
def bar
render 'bar', :layout => 'application'
end
end
The thing is that I don't want people to access the "foo/bar" route directly. So I have a route that is get 'baz' => 'foo#bar'.
Now I want to test the FooController:
require 'minitest_helper'
class FooControllerTest < ActionController::TestCase
def test_should_get_index
get '/baz'
end
end
But the test results in an error that No route matches {:controller=>"foo", :action=>"/baz"}. How do I specify the controller for the GET request?
Sorry if this is a dumb question. It's been very hard for me to find the answer.