因爲這個,我一直拉我的頭髮。試着讓黃瓜和OmniAuth一起工作
我的黃瓜步驟點擊登錄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` - 問題:這是嘲笑omniauth使用rspec我噸hink - 不知道是否可應用於黃瓜它
https://github.com/intridea/omniauth/issues/558 --post通過benjamintanweihao作品 - 但它的黑客代碼與測試不同的工作 - 的Git分支建議不工作或者
編輯:我模型/ 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
您的回溯會立即跳至您的用戶模型,特別是在第13行。向我們顯示'User'。 – davidcelis 2012-04-06 18:12:11
補充,希望它有幫助 – Karan 2012-04-06 20:19:58
'access_token'是一個散列,這就是爲什麼你會得到這個錯誤。哈希沒有'額外'方法。我建議你檢查它,看看你正在處理什麼,並相應地使用哈希 – davidcelis 2012-04-06 22:11:30