From f0151cdea6f03b54d05ab83cbd8e811d30e1b982 Mon Sep 17 00:00:00 2001 From: Leo McArdle Date: Wed, 6 Sep 2017 23:15:10 +0100 Subject: [PATCH] add spec --- spec/plugin_spec.rb | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 spec/plugin_spec.rb diff --git a/spec/plugin_spec.rb b/spec/plugin_spec.rb new file mode 100644 index 0000000..dfe7607 --- /dev/null +++ b/spec/plugin_spec.rb @@ -0,0 +1,43 @@ +require 'rails_helper' + +# This is ugly... but it works! +# Need to load plugin.rb to avoid: +# +# NameError: +# uninitialized constant OAuth2BasicAuthenticator +# +# And need to mock various methods to avoid: +# +# NoMethodError: +# undefined method `enabled_site_setting' for main:Object +# +# etc. + +def enabled_site_setting(arg) +end + +def auth_provider(arg) +end + +def register_css(arg) +end + +require_relative '../plugin.rb' + +describe OAuth2BasicAuthenticator do + context 'after_authenticate' do + it 'finds user by email' do + authenticator = OAuth2BasicAuthenticator.new('oauth2_basic') + user = Fabricate(:user) + authenticator.expects(:fetch_user_details).returns(email: user.email) + SiteSetting.oauth2_email_verified = true + auth = { 'credentials' => { 'token': 'token' }, + 'info' => { id: 'id' }, + 'extra' => {} } + + result = authenticator.after_authenticate(auth) + + expect(result.user).to eq(user) + end + end +end