Migrate controller type specs to request types for omniauth.

This commit is contained in:
Guo Xiang Tan 2018-03-01 15:33:00 +08:00
parent 81ca3677f7
commit 0fabf80dca
2 changed files with 24 additions and 26 deletions

View File

@ -1,26 +0,0 @@
require 'rails_helper'
describe Users::OmniauthCallbacksController do
context ".find_authenticator" do
it "fails if a provider is disabled" do
SiteSetting.enable_twitter_logins = false
expect {
Users::OmniauthCallbacksController.find_authenticator("twitter")
}.to raise_error(Discourse::InvalidAccess)
end
it "fails for unknown" do
expect {
Users::OmniauthCallbacksController.find_authenticator("twitter1")
}.to raise_error(Discourse::InvalidAccess)
end
it "finds an authenticator when enabled" do
SiteSetting.enable_twitter_logins = true
expect(Users::OmniauthCallbacksController.find_authenticator("twitter")).not_to eq(nil)
end
end
end

View File

@ -12,6 +12,29 @@ RSpec.describe Users::OmniauthCallbacksController do
OmniAuth.config.test_mode = false
end
describe ".find_authenticator" do
it "fails if a provider is disabled" do
SiteSetting.enable_twitter_logins = false
expect do
Users::OmniauthCallbacksController.find_authenticator("twitter")
end.to raise_error(Discourse::InvalidAccess)
end
it "fails for unknown" do
expect do
Users::OmniauthCallbacksController.find_authenticator("twitter1")
end.to raise_error(Discourse::InvalidAccess)
end
it "finds an authenticator when enabled" do
SiteSetting.enable_twitter_logins = true
expect(Users::OmniauthCallbacksController.find_authenticator("twitter"))
.not_to eq(nil)
end
end
context 'Google Oauth2' do
before do
SiteSetting.enable_google_oauth2_logins = true
@ -176,6 +199,7 @@ RSpec.describe Users::OmniauthCallbacksController do
Rails.application.env_config["omniauth.auth"] = OmniAuth.config.mock_auth[:google_oauth2]
get "/auth/google_oauth2/callback.json"
expect(response.status).to eq(200)
JSON.parse(response.body)
end