Skip to content

Loading…

Anonymous controller don't load named routes #339

Closed
petRUShka opened this Issue · 4 comments

4 participants

@petRUShka
require 'spec_helper'

describe Company::BaseController do
  controller do
    def index
      render :text => "text"
    end
  end

  it "should redirect to destroy" do
    get :index

    response.should redirect_to(destroy_user_session_path)
  end
end

I got an error:

 Failure/Error: response.should redirect_to(destroy_user_session_path)
 NameError:
   undefined local variable or method `destroy_user_session_path' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x0000000690b450>

But in other specs destroy_user_session_path works fine

P.S.

Bundle show

/usr/lib/ruby/gems/1.9.1/gems/rspec-2.5.0
/usr/lib/ruby/gems/1.9.1/gems/rspec-rails-2.5.0
/usr/lib/ruby/gems/1.9.1/gems/rails-3.0.1
@raskchanky

I'm also having this problem.

ruby = MRI 1.9.2-p0
rspec = 2.5.0
rails = 3.0.4

@alindeman

This is because defining a controller with controller do ... end stubs the routing. The solution may not be trivial, though I could be missing something.

@alindeman

Actually, I think I can get a patch going for this using method_missing :)

@alindeman

Interesting; did not realize commits in my forked repo would automatically push here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.