【问题标题】:Omniauth Cucumber Testing - Routing ErrorOmniauth Cucumber 测试 - 路由错误
【发布时间】:2012-10-13 03:20:15
【问题描述】:

我正在尝试在 Cucumber 中测试我的 Facebook 登录按钮。我正在使用 Omniauth。

这是我在 /features/support/env.rb 中的内容

Before do
  OmniAuth.config.test_mode = true
  OmniAuth.config.add_mock(:facebook, {
    provider: 'facebook',
    uid: '1259910065',
    info: {
      name: 'Test Name',
      email: 'test@example.com'
    }
  })
end

After do
  OmniAuth.config.test_mode = false
end

但是,当我尝试在测试中访问 /auth/facebook 时,我得到:

No route matches [GET] "/auth/facebook" (ActionController::RoutingError)

更新:

我也尝试在 env.rb 文件中require 'omniauth',但我不确定是否有必要。

【问题讨论】:

  • 你在使用omniauth-facebook gem吗? github.com/mkdynamic/omniauth-facebookomniauth 本身不支持facebook,你需要一个策略:github.com/intridea/omniauth/wiki/List-of-Strategies
  • 该网站运行良好。当我单击浏览器中的按钮时,它会转到'/auth/facebook' 并正确登录。所以是的,我正在使用facebook-omniauth gem。好问题。
  • 我只关心测试。
  • 嗨@ardavis,你是怎么解决这个问题的???请让我知道我一周以来就面临这个问题。
  • 不幸的是我没有。我没时间做那个项目,它被搁置了。

标签: ruby-on-rails cucumber omniauth


【解决方案1】:

我遇到了这个问题,我解决了在我的 routes.rb 中更改一些行

match 'auth/:provider/callback', to: 'sessions#create', via: [:get, :post]

如果您阅读 hereomniauth 说要在 routes.rb 中添加这一行 get '/auth/:provider/callback', to: 'sessions#create' 但回调将请求方法设置为使用名为 _method 的变量进行发布。

希望对你有帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-27
    • 2014-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-25
    相关资源
    最近更新 更多