NullVoxPopuli
NullVoxPopuli

Reputation: 65173

undefined method relative_url_root for nil:NilClass when running rspec on namespaced controller

I'm working on a rails 2.3.18 to 3.2.x upgrade, and I've run into a problem with this one set of controller tests:

Error:

/actionpack-3.2.12/lib/action_controller/test_case.rb:514:in `build_request_uri'
/actionpack-3.2.12/lib/action_controller/test_case.rb:470:in `process'
/actionpack-3.2.12/lib/action_controller/test_case.rb:49:in `process'
/actionpack-3.2.12/lib/action_controller/test_case.rb:390:in `get'
# ./spec/controllers/integrations/formstack_controller_spec.rb:104:in `block (3 levels) in <top (required)>'

code triggering error:

it "should handle a failed access_token retreival" do
    FormStack::Oauth2Connection.any_instance.stub(:identify).and_return(nil)
    get "oauth_token"   # this line <---------------------------------------------------------------- 104
    response.should redirect_to(:controller => "/integrations/", :action => :index)
    flash[:error].should include("error")
end

the routes for this controller:

namespace :integrations, path: "/integrations" do
    match "formstack/oauth_token", :to => "formstack#oauth_token"
    resources :formstack
end

nothing special about my controller:

class Integrations::FormstackController < ApplicationController
    def oauth_token
       ...
    end
end

so what is it about

get "any_action_in_this_controller"

causes an this relative_url_root error? Every test for every action for this controller is bringing up the error.

what other information can I give that will help you guys help me debug this?

Upvotes: 2

Views: 438

Answers (1)

robbie613
robbie613

Reputation: 675

As mentioned by @marcario, if you have:

    def config
    end

in a controller, you will get this (obscure) error. Just rename config to something else and the route mapping to match and you're good to go.

Upvotes: 4

Related Questions