1

I am trying to enable functional testing for custom Devise routes, but I keep hitting roadblocks that I am not sure how to solve. The routes I am trying to test are in the devise_scope :user block of my routes file (see below)

devise_for :users, :controllers => {:registrations => "registrations", 
                                    :confirmations => "confirmations",
                                    :sessions => "sessions"}
devise_scope :user do
    get '/trainer/:referral_trainer' => "registrations#new"
    get '*referral_trainer' => "registrations#new_client"
    post '/client_sign_up' => "registrations#create_client"
end

and my tests look like:

test "should get new" do
    params = {}
    params["referral_trainer"] = "trainer"

    get("new", params)
    assert_response :success

    params = {}
    params["trainer"] = "trainer"

    get("new_client", params)
    assert_response :success
end

But the error(s) I get are:

ActionController::RoutingError: No route matches {:referral_trainer=>"trainer", :controller=>"registrations", :action=>"/trainer/*referral_trainer"}

ActionController::RoutingError: No route matches {:trainer=>"trainer", :controller=>"registrations", :action=>"new_client"}

In my test I also have:

setup do
    @controller = RegistrationsController.new
    @request.env["devise.mapping"] = Devise.mappings[:user]
end

So that the right controller and Devise mappings are being used.

Rake routes returns:

GET    /trainer/:referral_trainer(.:format)              registrations#new
GET    /*referral_trainer(.:format)                      registrations#new_client

So I know the routes exist (and have used them in production), but I can not figure out how to test them programmatically.

Any help would be appreciated.

Thanks!

Hannele
  • 9,301
  • 6
  • 48
  • 68
Jason B
  • 11
  • 2

0 Answers0