Facebook omniauth 原始信息验证额外的模拟配置设置
Facebook omniauth raw info auth extra mock config setup
我正在尝试使用 omniauth
测试一个简单的 facebook
登录。但是,收到一条错误消息,指出“auth
”未定义 variable
或 method
。 omniauth
测试文档不包含 facebook
个示例
运行黄瓜功能测试
undefined local variable or method `auth' for #<Cucumber::Rails::World:0x007fa17eeafc78> (NameError)
./features/step_definitions/microsites/quiz/microsites_quiz_entrant_sign_in_facebook_steps.rb:26:in `/^I log in with my facebook email and password quiz$/'
steps.rb 文件
Then(/^I log in with my facebook email and password quiz$/) do
OmniAuth.config.add_mock(:facebook, {
:provider => "facebook",
:uid => '12345',
:name => "John Smith",
info: {
email: "test@test.com",
first_name: "Test",
last_name: "Tester",
gender: "male",
dob: auth.extra.raw_info.birthday
}
})
end
config/environments/test.rb
OmniAuth.config.test_mode = true
OmniAuth.config.mock_auth[:twitter] = OmniAuth::AuthHash.new({
:provider => 'twitter',
:uid => '123545'
})
模型文件
def self.from_facebook auth, campaign, password
campaign.entrants.where(fb_uid: auth.uid).first_or_create do |entrant|
entrant.fb_uid = auth.uid
entrant.email = auth.info.email
entrant.first_name = auth.info.first_name
entrant.last_name = auth.info.last_name
entrant.password = password
entrant.password_confirmation = password
entrant.campaign_id = campaign.id
# DOB is not returned from FB consistently, or not at all
entrant.dob = auth.extra.raw_info.birthday
# If DOB is returned, this create will pass, and this line should fire:
entrant.skip_confirmation!
end
end
您正在模拟身份验证响应,因此您无权访问 auth
对象以从中获取 Dob - 相反,您想要类似
的东西
OmniAuth.config.add_mock(:facebook, {
:provider => "facebook",
:uid => '12345',
:name => "John Smith",
info: {
email: "test@test.com",
first_name: "Test",
last_name: "Tester",
gender: "male"
},
'extra' => {
'raw_info' => { 'dob' => '1980-01-01 or whatever format is returned by Facebook'}
}
})
我正在尝试使用 omniauth
测试一个简单的 facebook
登录。但是,收到一条错误消息,指出“auth
”未定义 variable
或 method
。 omniauth
测试文档不包含 facebook
个示例
运行黄瓜功能测试
undefined local variable or method `auth' for #<Cucumber::Rails::World:0x007fa17eeafc78> (NameError)
./features/step_definitions/microsites/quiz/microsites_quiz_entrant_sign_in_facebook_steps.rb:26:in `/^I log in with my facebook email and password quiz$/'
steps.rb 文件
Then(/^I log in with my facebook email and password quiz$/) do
OmniAuth.config.add_mock(:facebook, {
:provider => "facebook",
:uid => '12345',
:name => "John Smith",
info: {
email: "test@test.com",
first_name: "Test",
last_name: "Tester",
gender: "male",
dob: auth.extra.raw_info.birthday
}
})
end
config/environments/test.rb
OmniAuth.config.test_mode = true
OmniAuth.config.mock_auth[:twitter] = OmniAuth::AuthHash.new({
:provider => 'twitter',
:uid => '123545'
})
模型文件
def self.from_facebook auth, campaign, password
campaign.entrants.where(fb_uid: auth.uid).first_or_create do |entrant|
entrant.fb_uid = auth.uid
entrant.email = auth.info.email
entrant.first_name = auth.info.first_name
entrant.last_name = auth.info.last_name
entrant.password = password
entrant.password_confirmation = password
entrant.campaign_id = campaign.id
# DOB is not returned from FB consistently, or not at all
entrant.dob = auth.extra.raw_info.birthday
# If DOB is returned, this create will pass, and this line should fire:
entrant.skip_confirmation!
end
end
您正在模拟身份验证响应,因此您无权访问 auth
对象以从中获取 Dob - 相反,您想要类似
OmniAuth.config.add_mock(:facebook, {
:provider => "facebook",
:uid => '12345',
:name => "John Smith",
info: {
email: "test@test.com",
first_name: "Test",
last_name: "Tester",
gender: "male"
},
'extra' => {
'raw_info' => { 'dob' => '1980-01-01 or whatever format is returned by Facebook'}
}
})