Weird issue with missing route in app, but no missing in spec #495

Closed
theodorton opened this Issue Jan 24, 2012 · 3 comments

Projects

None yet

2 participants

@theodorton

Given the following three files:

# spec/controllers/app/entries_controller_spec.rb
describe App::EntriesController do
  describe "GET search" do
    it "should be successful" do
      get :search
      response.should be_successful
    end
  end

  describe "POST search" do
    it "should be successful" do
      post :search
      response.should be_successful
    end
  end
end
# routes.rb
MyRailsApplication::Application.routes.draw do
  namespace :app do
    resources :entries do
      collection do
        get  :search
      end
    end
  end
end
# app/controllers/app/entries_controller.rb
class App::EntriesController < App::BaseController
  def search ; end
end

I don't get "No route matches" for the second example, as I would expect (the app throws a No route matches [POST] "/app/entries/search") as "post :search" is not defined in my routes.rb file.

Shouldn't RSpec give the same results as the application when a route is missing?

I would love to fix this, but I had a hard time looking to the action controller TestCase-class and more, but couldn't pin point where this issue is based.

@justinko
Contributor

I created a vanilla rails app and setup your exact situation and tested it with test/unit. I get a "template not found" error when POST'ing to #search. Please report this to Rails, thank you.

@justinko justinko closed this Jan 25, 2012
@theodorton

I'm sorry.. There is a template as well...

# app/views/app/companies/search.html.haml
= semantic_form_for :search do |f|
  = f.inputs :criteria do
    = f.input :freetext
  = f.actions do
    = f.action(:submit)
@justinko
Contributor

Please try this with T/U and a template.

test 'search' do
  post :search
  assert_response :success
end

I'm very confident this is not an rspec-rails bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment