Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

ActionController::TestCase fails to recognise valid routes

#5474

I'm unable to run controller and/or routing specs because ActionController::TestCase seems to fail to recognise valid routes, which work when requested via HTTP.

There is already a ticket on the rspec-rails issue tracker (http://github.com/rspec/rspec-rails/issues#issue/156). The following Rails template was used to demonstrate the issue stating it was to do with singular resources but it appears to also affect plural ones.

# Template for Rails 3.x apps.

gem 'rspec-rails', :version => ">= 2.0.0.beta.19"
run 'bundle install'

generate 'rspec:install'
rake 'db:migrate'

generate :controller, 'people'
route "resource :people, :singular => 'person'"

file 'spec/controllers/people_controller_spec.rb', <<-CODE
require 'spec_helper'

describe PeopleController do

  describe 'GET index' do
    before(:each) do
      get :index
    end

    it 'should be a success' do
      response.should be_sucess
    end
  end
end
CODE

Mr. David Chelimsky responded with the following…

Controller specs mix in ActionController::TestCase::Behavior, which is where this problem lies. The same example fails in an ActionController::TestCase:

require 'test_helper'

class PeopleControllerTest < ActionController::TestCase
  test "GET index" do
    get :index
    assert_response :success
  end
end

Reported by James Conroy-Finn · August 27th, 2010 @ 03:47 PM

State: stale
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Andrew White
    Andrew White
    • State changed from new to needs-more-info
    • Importance changed from to Low

    I can't reproduce this and your code has a number of errors. Firstly :singular is no longer a valid option for resources - any custom inflections should be defined in the inflections initializer. Secondly, you're using a singleton resource call but trying to call get :index and singleton resources don't have an index action. Finally you have a typo on response.should be_sucess.

    Testing in RC2 using resources instead of resource, removing the :singular option and fixing the typo and then running rake spec shows no errors. Additionally, make sure that you've actually implemented the action - I forgot to when trying to reproduce this.

    August 27th, 2010 @ 09:48 PM

  2. rails
    rails
    • State changed from needs-more-info to open

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    April 5th, 2011 @ 01:00 AM

  3. rails
    rails
    • State changed from open to stale

    April 5th, 2011 @ 01:00 AM