我在 rails 3.2.11 下使用 Devise 2.2.0 和 omniauth 1.1.1。
我在一个名为“HomepageController”的未经身份验证的(例如,没有“before_filter:authenticate_user!”)控制器上进行了一个名为“homepage”的操作的测试。这个控制器动作非常简单,除非用户登录,否则它会传递到它的视图,在这种情况下它会重定向到我们的“homebase”页面。这是控制器动作:
class HomepageController < ApplicationController
def homepage
if current_user then
redirect_to :homebase
end
end
end
这是我的测试:
require 'test_helper'
class HomepageControllerTest < ActionController::TestCase
def setup
@user = users(:donley)
end
test "should get homepage when signed in" do
sign_in @user
get :homepage
assert_redirected_to "/homebase"
end
test "should get homepage when not signed in" do
get :homepage
assert_response :success
end
end
第二次测试失败并出现以下错误:
No route matches {:controller=>"omniauth_callbacks", :action=>"passthru", :provider=>:facebook}
在视图中的这一行:
= link_to user_omniauth_authorize_path(:facebook) do
这是我的设计和omniauth路线:
resources :oauth_clients
match '/oauth/test_request', :to => 'oauth#test_request', :as => :test_request
match '/oauth/token', :to => 'oauth#token', :as => :token
match '/oauth/access_token', :to => 'oauth#access_token', :as => :access_token
match '/oauth/request_token', :to => 'oauth#request_token', :as => :request_token
match '/oauth/authorize', :to => 'oauth#authorize', :as => :authorize
match '/oauth', :to => 'oauth#index', :as => :oauth
devise_for :users, :controllers => {:omniauth_callbacks => "omniauth_callbacks"}
devise_scope :user do
get "sign_in", :to => "devise/sessions#new"
get "sign_up", :to => "devise/registrations#new"
match "sign_out", :to => "devise/sessions#destroy"
end
这是一条rake routes
看起来像错误消息中提到的路线:
user_omniauth_authorize /users/auth/:provider(.:format) omniauth_callbacks#passthru {:provider=>/facebook|linkedin/}
真正疯狂的是,所有这些代码rails server
在我的生产环境中的 Heroku 中或上运行时都能完美运行。它只是在测试中失败。
非常感谢您的任何见解!