Commit 0d9dfcfa522caea587355b2ea2d7c01f5911362c

Authored by Victor Costa
1 parent 1400bce5

oauth_client: fix tests

plugins/oauth_client/controllers/public/oauth_client_plugin_public_controller.rb
... ... @@ -40,17 +40,18 @@ class OauthClientPluginPublicController < PublicController
40 40 session[:notice] = _("Can't login with %s") % provider.name
41 41 end
42 42 session[:oauth_client_popup] = true if request.env.fetch("omniauth.params", {})['oauth_client_popup']
43   - session[:return_to] = url_for(
44   - :controller => :oauth_client_plugin_public,
45   - :action => :finish,
46   - :user => {
47   - :login => current_user.login,
48   - :person => {:identifier => current_user.person.identifier, :name => current_user.person.name}
49   - } ,
50   - :profile_data => {:name => current_user.person.name},
51   - :oauth_client_popup => session[:oauth_client_popup]
  43 + if current_user.present?
  44 + session[:return_to] = url_for(
  45 + :controller => :oauth_client_plugin_public,
  46 + :action => :finish,
  47 + :user => {
  48 + :login => current_user.login,
  49 + :person => {:identifier => current_user.person.identifier, :name => current_user.person.name}
  50 + } ,
  51 + :profile_data => {:name => current_user.person.name},
  52 + :oauth_client_popup => session[:oauth_client_popup]
52 53 )
53   -
  54 + end
54 55 redirect_to :controller => :account, :action => :login
55 56 end
56 57  
... ...
plugins/oauth_client/lib/ext/user.rb
... ... @@ -16,7 +16,7 @@ class User
16 16  
17 17 def store_oauth_providers
18 18 @oauth_providers.each do |provider|
19   - self.person.oauth_auths.create!(profile: self.person, provider: provider, enabled: true)
  19 + self.person.oauth_auths.create!(profile: self.person, provider: provider, enabled: true, oauth_data: oauth_data)
20 20 end
21 21 end
22 22  
... ...
plugins/oauth_client/models/oauth_client_plugin/auth.rb
1 1 class OauthClientPlugin::Auth < ActiveRecord::Base
2 2  
3 3 attr_accessible :profile, :provider, :enabled,
4   - :access_token, :expires_in
  4 + :access_token, :expires_in, :oauth_data
5 5  
6 6 belongs_to :profile, class_name: 'Profile'
7 7 belongs_to :provider, class_name: 'OauthClientPlugin::Provider'
... ... @@ -12,6 +12,8 @@ class OauthClientPlugin::Auth &lt; ActiveRecord::Base
12 12  
13 13 acts_as_having_settings field: :data
14 14  
  15 + serialize :oauth_data, Hash
  16 +
15 17 def expires_in
16 18 self.expires_at - Time.now
17 19 end
... ...
plugins/oauth_client/test/functional/oauth_client_plugin_public_controller_test.rb
... ... @@ -14,6 +14,7 @@ class OauthClientPluginPublicControllerTest &lt; ActionController::TestCase
14 14 should 'redirect to signup when user is not found' do
15 15 auth.info.stubs(:email).returns("xyz123@noosfero.org")
16 16 auth.info.stubs(:name).returns('xyz123')
  17 + auth.stubs(:to_hash).returns({})
17 18 session[:provider_id] = provider.id
18 19  
19 20 get :callback
... ...
plugins/oauth_client/test/unit/user_test.rb
... ... @@ -57,7 +57,7 @@ class UserTest &lt; ActiveSupport::TestCase
57 57 })
58 58 user = User.create!(:email => 'testoauth@example.com', :login => 'testoauth', :oauth_providers => [], :oauth_signup_token => 'token')
59 59 user.oauth_signup_token = 'token'
60   - assert user.oauth_user_providers.first.oauth_data.present?
  60 + assert user.oauth_auths.first.oauth_data.present?
61 61 end
62 62  
63 63 should 'save oauth as a hash when creating user with oauth' do
... ... @@ -72,12 +72,12 @@ class UserTest &lt; ActiveSupport::TestCase
72 72 }
73 73 )
74 74 user = User.create!(:email => 'testoauth@example.com', :login => 'testoauth', :oauth_providers => [], :oauth_signup_token => 'token')
75   - assert user.oauth_user_providers.first.oauth_data.is_a? Hash
  75 + assert user.oauth_auths.first.oauth_data.is_a? Hash
76 76 end
77 77  
78 78 should 'note save oauth user provider when user is not originated from oauth' do
79 79 user = User.create!(:email => 'testoauth@example.com', :login => 'testoauth', :password => 'test', :password_confirmation => 'test')
80   - assert user.oauth_user_providers.count.eql? 0
  80 + assert user.oauth_auths.count.eql? 0
81 81 end
82 82  
83 83 end
... ...