【发布时间】:2016-10-16 08:59:23
【问题描述】:
我目前正在编写一个使用 Rails 5 的 API,使用 devise_token_auth 和 omniauth 作为身份验证策略。
为了检查omniauth 身份验证是否有效,我编写了一个请求规范:
OmniAuth.config.test_mode = true
OmniAuth.config.mock_auth[:facebook] = OmniAuth::AuthHash.new(
{
provider: 'facebook',
uid: '123456'
})
Rails.application.env_config["devise.mapping"] = Devise.mappings[:user]
Rails.application.env_config["omniauth.auth"] = OmniAuth.config.mock_auth[:facebook]
get '/omniauth/facebook/callback'
expect(response).to have_http_status(:ok)
当我运行测试时,我必须出现以下错误:
NoMethodError: undefined method `[]' for nil:NilClass
/Users/gaetan/.rvm/gems/ruby-2.3.1/gems/devise_token_auth-0.1.39/app/controllers/devise_token_auth/omniauth_callbacks_controller.rb:14:in `redirect_callbacks'
这是第 14 行:
devise_mapping = [request.env['omniauth.params']['namespace_name'],
所以我猜这是因为omniauth.params 是nil。这是否意味着我也必须模拟参数?怎么样?
【问题讨论】:
-
您找到解决此问题的方法了吗?我仍然有这个问题。我已经测试了
Rails.application.env_config['omniauth.params'] = { key: 'value' },但它在控制器中返回了一个空哈希。 -
不,我没有...
标签: ruby-on-rails rspec devise omniauth ruby-on-rails-5