我正在使用 rails 应用程序,并希望在我的 rails 应用程序中自动执行“使用 google 登录”流程。
这是我在谷歌搜索后编写的测试用例。但是,它没有将我带到我的主页,而是将我重定向到其他 URL。不明白为什么会这样。
test 'z' do
Rails.application.env_config["devise.mapping"] = Devise.mappings[:user]
Rails.application.env_config["omniauth.auth"] = OmniAuth.config.mock_auth[:google_oauth2]
stub_omniauth
get '/users/auth/google_oauth2_login'
print @response.body
# it prints: Redirecting to http://www.example.com/users/auth/google_oauth2_login/callback...nil
end
这是方法
def stub_omniauth
# first, set OmniAuth to run in test mode
OmniAuth.config.test_mode = true
# then, provide a set of fake oauth data that
# omniauth will use when a user tries to authenticate:
OmniAuth.config.mock_auth[:google] = OmniAuth::AuthHash.new({
provider: "google",
uid: "12345678910",
info: {
email: "jesse@mountainmantechnologies.com",
first_name: "Jesse",
last_name: "Spevack"
},
credentials: {
token: "abcdefg12345",
refresh_token: "12345abcdefg",
expires_at: DateTime.now,
}
})
end
它正在重定向到http://www.example.com/users/auth/google_oauth2_login/callback...nil