Commit 2a6a945e752c454d7471b75ab560a73e4ba0c9c1

Authored by Gabriel Silva
1 parent ca65f5bd

Adds tests for provider specific Auth classes

Signed-off-by: Gabriel Silva <gabriel93.silva@gmail.com>
plugins/oauth_client/models/oauth_client_plugin/noosfero_oauth2_auth.rb
1 1 class OauthClientPlugin::NoosferoOauth2Auth < OauthClientPlugin::Auth
2 2  
3   - def image_url(size = nil)
  3 + def image_url(size = "")
4 4 URI.join("http://#{self.provider.client_options[:site]}/profile/#{self.external_person.identifier}/icon/", size)
5 5 end
6 6  
... ...
plugins/oauth_client/test/unit/auth_test.rb
... ... @@ -5,7 +5,12 @@ class AuthTest &lt; ActiveSupport::TestCase
5 5 def setup
6 6 @person = fast_create(Person)
7 7 @provider = fast_create(OauthClientPlugin::Provider, name: "GitHub")
8   - @external_person = fast_create(ExternalPerson, name: "testuser", email: "test@email,com")
  8 + @external_person = fast_create(ExternalPerson, name: "testuser", email: "test@email.com",
  9 + identifier: "testuser")
  10 +
  11 + OauthClientPlugin::Auth.any_instance.stubs(:external_person_image_url).returns("http://some.host/image")
  12 + OauthClientPlugin::Auth.any_instance.stubs(:external_person_uid).returns("j4b25cj234hb5n235")
  13 + OauthClientPlugin::Provider.any_instance.stubs(:client_options).returns({site: "http://host.com"})
9 14 end
10 15  
11 16 should "not create an auth without a related profile or external person" do
... ... @@ -14,7 +19,8 @@ class AuthTest &lt; ActiveSupport::TestCase
14 19 end
15 20  
16 21 should "create an auth with an external person" do
17   - auth = OauthClientPlugin::Auth.create!(external_person: @external_person, provider: @provider)
  22 + auth = OauthClientPlugin::Auth.create!(external_person: @external_person,
  23 + provider: @provider)
18 24 assert auth.id.present?
19 25 end
20 26  
... ... @@ -25,9 +31,30 @@ class AuthTest &lt; ActiveSupport::TestCase
25 31  
26 32 should "create an auth for a custom provider" do
27 33 auth = OauthClientPlugin::Auth.create_for_strategy("github", provider: @provider,
28   - profile: @person)
  34 + profile: @person)
29 35 assert auth.id.present?
30 36 assert auth.is_a? OauthClientPlugin::GithubAuth
31 37 end
32 38  
  39 + STRATEGIES = %w[facebook github google_oauth2 noosfero_oauth2 twitter]
  40 + STRATEGIES.each do |strategy|
  41 + should "override the external person's image url for #{strategy} strategy" do
  42 + auth = OauthClientPlugin::Auth.create_for_strategy(strategy, provider: @provider,
  43 + external_person: @external_person)
  44 + assert_not auth.image_url.nil?
  45 + end
  46 +
  47 + should "override the external person's profile url for #{strategy} strategy" do
  48 + auth = OauthClientPlugin::Auth.create_for_strategy(strategy, provider: @provider,
  49 + external_person: @external_person)
  50 + assert_not auth.profile_url.nil?
  51 + end
  52 +
  53 + should "override the external person's profile settings url for #{strategy} strategy" do
  54 + auth = OauthClientPlugin::Auth.create_for_strategy(strategy, provider: @provider,
  55 + external_person: @external_person)
  56 + assert_not auth.settings_url.nil?
  57 + end
  58 + end
  59 +
33 60 end
... ...