0

そのせいで髪を引っ張ってきました。

私のきゅうりのステップは、facebook のログインをクリックします。次の記事に従って omniauth を嘲笑しました。

http://pivotallabs.com/users/mgehard/blog/articles/1595-testing-omniauth-based-login-via-cucumber

私の omniauth_callbacks_controller.rb には次のコードがあります:

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController

  def my_logger
    @@my_logger = Logger.new("#{Rails.root}/log/my.log")
  end


  def facebook
    @user = User.find_for_facebook_oauth(env["omniauth.auth"], current_user)

    if @user.persisted?
      flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Facebook"
      sign_in_and_redirect @user, :event => :authentication
    else
      session["devise.facebook_data"] = env["omniauth.auth"]
      redirect_to new_user_registration_url
    end
  end
end

ただし、次のエラーが表示されます。

When I follow "facebook_login_button"            # features/step_definitions/basic.rb:14
      undefined method `extra' for #<Hash:0x007fda6d7cd950> (NoMethodError)
      ./app/models/user.rb:13:in `find_for_facebook_oauth'
      ./app/controllers/users/omniauth_callbacks_controller.rb:8:in `facebook'
      (eval):2:in `click_link'
      ./features/step_definitions/basic.rb:15:in `/^(?:|I )follow "([^"]*)"$/'
      features/homepage.feature:30:in `When I follow "facebook_login_button"'

私が読んだ他の記事: Devise 1.5 + Omniauth 1.0 + Facebook: undefined method `extra` - 問題: これは rspec を使用して omniauth を嘲笑しています - キュウリに適用できるかどうかわかりません

https: /

編集:私のモデル/ user.rb

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :token_authenticatable, :lockable, :timeoutable, :confirmable and :activatable
  devise :database_authenticatable, :registerable, 
         :recoverable, :rememberable, :trackable, :validatable

  devise :omniauthable

  # Setup accessible (or protected) attributes for your model
  attr_accessible :email, :password, :password_confirmation, :remember_me

  def self.find_for_facebook_oauth(access_token, signed_in_resource=nil)
           data = access_token.extra.raw_info
            if user = User.where(:email => data.email).first
                user
            else 
                User.create!(:email => data.email, :password => Devise.friendly_token[0,20]) 
            end
  end
end
4

1 に答える 1

1

https://github.com/intridea/omniauth/issues/558 これはあなたのせいではなく、omniauthの小さなバグです。本番モードと開発モードではaccess_token.extraのようなメソッドを使用できますが、テストモードで機能させるには、access_token["extra"]に変更する必要があります。

于 2012-05-05T09:28:19.103 に答える