How to test routes that don't include controller?

Posted by Darren Green on Stack Overflow See other posts from Stack Overflow or by Darren Green
Published on 2014-05-29T21:00:38Z Indexed on 2014/05/29 21:26 UTC
Read the original article Hit count: 186

Filed under:
|
|

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.

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about minitest