From 2a6a945e752c454d7471b75ab560a73e4ba0c9c1 Mon Sep 17 00:00:00 2001 From: Gabriel Silva Date: Sun, 7 Aug 2016 23:28:36 +0000 Subject: [PATCH] Adds tests for provider specific Auth classes --- plugins/oauth_client/models/oauth_client_plugin/noosfero_oauth2_auth.rb | 2 +- plugins/oauth_client/test/unit/auth_test.rb | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/plugins/oauth_client/models/oauth_client_plugin/noosfero_oauth2_auth.rb b/plugins/oauth_client/models/oauth_client_plugin/noosfero_oauth2_auth.rb index 84c2ccb..8dc79f3 100644 --- a/plugins/oauth_client/models/oauth_client_plugin/noosfero_oauth2_auth.rb +++ b/plugins/oauth_client/models/oauth_client_plugin/noosfero_oauth2_auth.rb @@ -1,6 +1,6 @@ class OauthClientPlugin::NoosferoOauth2Auth < OauthClientPlugin::Auth - def image_url(size = nil) + def image_url(size = "") URI.join("http://#{self.provider.client_options[:site]}/profile/#{self.external_person.identifier}/icon/", size) end diff --git a/plugins/oauth_client/test/unit/auth_test.rb b/plugins/oauth_client/test/unit/auth_test.rb index 4248425..18aa653 100644 --- a/plugins/oauth_client/test/unit/auth_test.rb +++ b/plugins/oauth_client/test/unit/auth_test.rb @@ -5,7 +5,12 @@ class AuthTest < ActiveSupport::TestCase def setup @person = fast_create(Person) @provider = fast_create(OauthClientPlugin::Provider, name: "GitHub") - @external_person = fast_create(ExternalPerson, name: "testuser", email: "test@email,com") + @external_person = fast_create(ExternalPerson, name: "testuser", email: "test@email.com", + identifier: "testuser") + + OauthClientPlugin::Auth.any_instance.stubs(:external_person_image_url).returns("http://some.host/image") + OauthClientPlugin::Auth.any_instance.stubs(:external_person_uid).returns("j4b25cj234hb5n235") + OauthClientPlugin::Provider.any_instance.stubs(:client_options).returns({site: "http://host.com"}) end should "not create an auth without a related profile or external person" do @@ -14,7 +19,8 @@ class AuthTest < ActiveSupport::TestCase end should "create an auth with an external person" do - auth = OauthClientPlugin::Auth.create!(external_person: @external_person, provider: @provider) + auth = OauthClientPlugin::Auth.create!(external_person: @external_person, + provider: @provider) assert auth.id.present? end @@ -25,9 +31,30 @@ class AuthTest < ActiveSupport::TestCase should "create an auth for a custom provider" do auth = OauthClientPlugin::Auth.create_for_strategy("github", provider: @provider, - profile: @person) + profile: @person) assert auth.id.present? assert auth.is_a? OauthClientPlugin::GithubAuth end + STRATEGIES = %w[facebook github google_oauth2 noosfero_oauth2 twitter] + STRATEGIES.each do |strategy| + should "override the external person's image url for #{strategy} strategy" do + auth = OauthClientPlugin::Auth.create_for_strategy(strategy, provider: @provider, + external_person: @external_person) + assert_not auth.image_url.nil? + end + + should "override the external person's profile url for #{strategy} strategy" do + auth = OauthClientPlugin::Auth.create_for_strategy(strategy, provider: @provider, + external_person: @external_person) + assert_not auth.profile_url.nil? + end + + should "override the external person's profile settings url for #{strategy} strategy" do + auth = OauthClientPlugin::Auth.create_for_strategy(strategy, provider: @provider, + external_person: @external_person) + assert_not auth.settings_url.nil? + end + end + end -- libgit2 0.21.2