【问题标题】:Rails/Cucumber - Hosting error testing omniauth (provider: facebook) - (URI::InvalidComponentError)Rails/Cucumber - 托管错误测试omniauth(提供者:facebook) - (URI::InvalidComponentError)
【发布时间】:2011-05-21 19:51:26
【问题描述】:

我在尝试配置omniauth 以使用黄瓜进行集成测试时遇到错误(我通过Wiki 提供的Devise 设置了Omniauth)

请看下面:

Scenario: Test                       # features/omniauth.feature:3
  Given I am signed in with facebook # features/step_definitions/omniauth_steps.rb:1
    bad component(expected host component): http://www.example.com (URI::InvalidComponentError)
    /Users/benoit/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/uri/generic.rb:395:in `check_host'
    /Users/benoit/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/uri/generic.rb:409:in `host='
    ./features/step_definitions/omniauth_steps.rb:2:in `/^I am signed in with facebook$/'
    features/omniauth.feature:4:in `Given I am signed in with facebook'
  Then I open the page               # features/step_definitions/debug_steps.rb:5

这是我的文件:

omniauth.feature

Feature: OmniAuth

  Scenario: Test
    Given I am signed in with facebook
    Then I open the page

omniauth_steps.rb

Given /^I am signed in with facebook$/ do
  visit "/auth/facebook"
end

支持/env.rb

OmniAuth.config.test_mode = true
OmniAuth.config.mock_auth[:facebook] = {
  'uid' => '12345',
  "user_info" => {
    "email" => "foobar@example.com",
    "first_name" => "foo",
    "last_name" => "Bar"
  }
}

初始化程序/devise.rb

case 
  when Rails.env.production?
    config.omniauth :facebook, 'XXXX', 'XXXX', 
    {:scope => 'email, offline_access', :client_options => {:ssl => {:ca_file => '/usr/lib/ssl/certs/ca-certificates.crt'}}}
  when Rails.env.development?
    config.omniauth :facebook, 'XXXX', 'XXXX'
  when Rails.env.test?
    config.omniauth :facebook, 'XXXX', 'XXXX'
        OmniAuth.config.full_host = 'http://example.com' # issue 257  
end

(参考:issue 257

路线

devise_scope :user do 
  get '/auth/:provider' => 'users/omniauth_callbacks#passthru'
end

devise_for :users, :path => "", :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }

作为信息,我还使用以下 URL 配置了我的 facebook test_app:http://example.com/

我很高兴知道是否有人对此有想法/经历过。 谢谢!

【问题讨论】:

    标签: ruby-on-rails facebook devise cucumber omniauth


    【解决方案1】:

    尝试添加:

    Before do
      Capybara.default_host = 'example.com'
    end
    

    到您的 support/env.rb 文件,也尝试注释掉:

    OmniAuth.config.full_host = 'http://example.com' # issue 257
    

    来自您的初始化程序/devise.rb 文件。

    【讨论】:

      【解决方案2】:

      也许我在这里假设的太少了,但以防万一……您是否设置了身份验证控制器和相关路由?

      # /config/routes.rb
      match "/auth/:provider/callback" => "authentications#create"
      

      编辑:抱歉,我刚刚意识到您说您按照 wiki 提供的方式设置了所有内容。我猜你已经这样做了。我想我还是把它留在这里。

      要了解如何设置身份验证控制器,您应该观看 Ryan Bates screencasts 关于该主题的内容。他们真的是一个很好的资源。

      我有一个编写了完整的 Facebook 身份验证的控制器,如果您愿意,我可以发布它吗?只需发表评论。

      【讨论】:

      • 嗨 Duckyfuzz,感谢您的回答!你是对的,我应该添加我的路线。 (我也改变了主机,你可以在这里看到github.com/intridea/omniauth/issues/257,反正给了我另一个错误)。我看到了 ryanb 截屏视频,但没有关注它,因为我认为 devise wiki 中的代码更简洁,因为 Devise 现在支持omniauth 集成。 (github.com/plataformatec/devise/wiki/OmniAuth:-Overview)。所以现在我有一个 URI::InvalidComponentError :(
      • 我不确定是否诚实。我从来没有使用设计模块设置omniauth,所以我很难说出它应该是什么样子。抱歉,我帮不上忙。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-12-30
      • 1970-01-01
      • 1970-01-01
      • 2017-01-23
      • 1970-01-01
      • 2012-11-05
      • 2017-09-24
      相关资源
      最近更新 更多