No routes "/authentications/auth/facebook" in tests

128 views
Skip to first unread message

Robin Boutros

unread,
May 29, 2012, 2:06:54 PM5/29/12
to plataforma...@googlegroups.com

Hey,

I've got this Authentication model which is :omniauthable.

In my app, I'm using the url helper authentication_omniauth_authorize_path(:facebook) and it works fine!
In my acceptance tests though, I get...

 No route matches [GET] "/authentications/auth/facebook"

...when I'm clicking the link.

Do I need to somehow set these env variables?

request.env["devise.mapping"] = Devise.mappings[:user] 
request.env["omniauth.auth"] = OmniAuth.config.mock_auth[:twitter]

If so, how, since I dont have access to the request in acceptance tests, I think.

Any ideas on what I'm missing?

Thanks

Carlos Antonio da Silva

unread,
May 29, 2012, 2:10:28 PM5/29/12
to plataforma...@googlegroups.com
For acceptance tests you shouldn't need to set anything of these variables. They're mostly required for controller ones. Also make sure you're setting up OmniAuth to test_mode. I haven't been seeing any big issues with omniauth tests, in fact, I have an app that works quite fine.

-- 
At.
Carlos Antonio

Robin Boutros

unread,
May 29, 2012, 2:21:46 PM5/29/12
to plataforma...@googlegroups.com
I have an acceptance/omniauth_helper.rb file:
 
OmniAuth.config.test_mode = true

def mock_with_facebook
  OmniAuth.config.add_mock(:facebook, {
    "info" => {
      "last_name"  => "Tester",
      "first_name" => "Some",
      "email"      => "somet...@example.com"
    },
    "uid"         => "12345",
    "extra" => {
      "raw_info" => {
        "location" => {
            "name" => "New York, NY",
        },
      }
    },
    "provider" => "facebook"
  })
end

And in my tests:

require 'acceptance/omniauth_helper'

feature "Authentications" do
      before do
          mock_with_facebook
      end

      #scenario...
end

Robin Boutros

unread,
May 29, 2012, 3:05:33 PM5/29/12
to plataforma...@googlegroups.com
Seems like `authentication_omniauth_authorize_path` is undefined in my acceptance tests. Can you see a reason why?


On Tuesday, May 29, 2012 2:10:28 PM UTC-4, Carlos Antonio da Silva wrote:

Carlos Antonio da Silva

unread,
May 29, 2012, 3:23:42 PM5/29/12
to plataforma...@googlegroups.com
Yes, now I see, this is not a real named route, but a helper Devise provides. It'll not be available for you, you'd have to use a string path or create a helper to handle that under your tests.


You can also try to include and call this define helper, manually by giving the devise mapping. I can't create an example right now, but the route is so simple that a manual helper would do imo.

-- 
At.
Carlos Antonio

Robin Boutros

unread,
May 29, 2012, 3:34:43 PM5/29/12
to plataforma...@googlegroups.com
Right, I realized it's not a real route (https://github.com/plataformatec/devise/blob/master/lib/devise/omniauth/url_helpers.rb) but I actually don't need to use this method in my acceptance tests, it was just a test and at the time I thought it could be meaningful.

But if I'm just using 'click_link "sign in with facebook"', then it should work, right?

And the error is "No route matches [GET] "/authentications/auth/facebook"" so it seems like the helper generated the route correctly. This route (/authentications/auth/facebook) is supposed to be picked up by omniauth, right?

Carlos Antonio da Silva

unread,
May 29, 2012, 3:37:45 PM5/29/12
to plataforma...@googlegroups.com
It should be handled by omniauth yeah. Does the app work normally when you go through this link? Does the path look like the same?

-- 
At.
Carlos Antonio

Robin Boutros

unread,
May 29, 2012, 3:44:08 PM5/29/12
to plataforma...@googlegroups.com
Yes, when using the app, everything works perfectly, and the path is the same (http://localhost:8080/authentications/auth/facebook)...

Robin Boutros

unread,
May 29, 2012, 3:57:47 PM5/29/12
to plataforma...@googlegroups.com
So I checked that Omniauth is in test mode in my test, and it is.

From the doc:
 
Once you have enabled test mode, all requests to OmniAuth will be short circuited to use the mock authentication hash as described below. A request to /auth/provider will redirect immediately to/auth/provider/callback

It will also redirect  /authentications/auth/provider to /authentications/auth/provider/callback right?

Robin Boutros

unread,
May 29, 2012, 6:01:33 PM5/29/12
to plataforma...@googlegroups.com
I've added:

as :authentication do
    get '/authentications/auth/:provider' => 'authentications/omniauth_callbacks#passthru'
end

to my routes, with the associated method that renders the 404 page (with a status of 404), and all it does in the tests is rendering the 404 page... So basically, Omniauth does not react for some reason...

Carlos Antonio da Silva

unread,
May 29, 2012, 6:25:30 PM5/29/12
to plataforma...@googlegroups.com
Devise just adds the mapping as a prefix, thus you get /authentications/auth/provider. Everything else should work the same for OmniAuth.

This #passthru route is only required if you have a glob route (*path, for instance).

-- 
At.
Carlos Antonio

Robin Boutros

unread,
May 31, 2012, 12:22:45 PM5/31/12
to plataforma...@googlegroups.com
I managed to make it work by setting the path_prefix in my tests: `OmniAuth.config.path_prefix = '/authentications/auth'`.

Any thoughts?

Carlos Antonio da Silva

unread,
May 31, 2012, 7:46:59 PM5/31/12
to plataforma...@googlegroups.com
Devise is supposed to handle setting the path_prefix with the omniauth routes, you shouldn't have to do that manually. But I don't get why is this required.

-- 
At.
Carlos Antonio

Reply all
Reply to author
Forward
0 new messages