From 0fabf80dcad81d64ed26f0964e17dd030869f786 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Thu, 1 Mar 2018 15:33:00 +0800 Subject: [PATCH] Migrate controller type specs to request types for omniauth. --- .../omniauth_callbacks_controller_spec.rb | 26 ------------------- .../omniauth_callbacks_controller_spec.rb | 24 +++++++++++++++++ 2 files changed, 24 insertions(+), 26 deletions(-) delete mode 100644 spec/controllers/omniauth_callbacks_controller_spec.rb diff --git a/spec/controllers/omniauth_callbacks_controller_spec.rb b/spec/controllers/omniauth_callbacks_controller_spec.rb deleted file mode 100644 index df05b2c2f17..00000000000 --- a/spec/controllers/omniauth_callbacks_controller_spec.rb +++ /dev/null @@ -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 diff --git a/spec/requests/omniauth_callbacks_controller_spec.rb b/spec/requests/omniauth_callbacks_controller_spec.rb index 20ca66324b4..a648d4952cb 100644 --- a/spec/requests/omniauth_callbacks_controller_spec.rb +++ b/spec/requests/omniauth_callbacks_controller_spec.rb @@ -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