From 0d9dfcfa522caea587355b2ea2d7c01f5911362c Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Mon, 25 Jan 2016 17:39:46 -0300 Subject: [PATCH] oauth_client: fix tests --- plugins/oauth_client/controllers/public/oauth_client_plugin_public_controller.rb | 21 +++++++++++---------- plugins/oauth_client/lib/ext/user.rb | 2 +- plugins/oauth_client/models/oauth_client_plugin/auth.rb | 4 +++- plugins/oauth_client/test/functional/oauth_client_plugin_public_controller_test.rb | 1 + plugins/oauth_client/test/unit/user_test.rb | 6 +++--- 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/plugins/oauth_client/controllers/public/oauth_client_plugin_public_controller.rb b/plugins/oauth_client/controllers/public/oauth_client_plugin_public_controller.rb index 072e5bd..c3d8bca 100644 --- a/plugins/oauth_client/controllers/public/oauth_client_plugin_public_controller.rb +++ b/plugins/oauth_client/controllers/public/oauth_client_plugin_public_controller.rb @@ -40,17 +40,18 @@ class OauthClientPluginPublicController < PublicController session[:notice] = _("Can't login with %s") % provider.name end session[:oauth_client_popup] = true if request.env.fetch("omniauth.params", {})['oauth_client_popup'] - session[:return_to] = url_for( - :controller => :oauth_client_plugin_public, - :action => :finish, - :user => { - :login => current_user.login, - :person => {:identifier => current_user.person.identifier, :name => current_user.person.name} - } , - :profile_data => {:name => current_user.person.name}, - :oauth_client_popup => session[:oauth_client_popup] + if current_user.present? + session[:return_to] = url_for( + :controller => :oauth_client_plugin_public, + :action => :finish, + :user => { + :login => current_user.login, + :person => {:identifier => current_user.person.identifier, :name => current_user.person.name} + } , + :profile_data => {:name => current_user.person.name}, + :oauth_client_popup => session[:oauth_client_popup] ) - + end redirect_to :controller => :account, :action => :login end diff --git a/plugins/oauth_client/lib/ext/user.rb b/plugins/oauth_client/lib/ext/user.rb index 020e492..ba52326 100644 --- a/plugins/oauth_client/lib/ext/user.rb +++ b/plugins/oauth_client/lib/ext/user.rb @@ -16,7 +16,7 @@ class User def store_oauth_providers @oauth_providers.each do |provider| - self.person.oauth_auths.create!(profile: self.person, provider: provider, enabled: true) + self.person.oauth_auths.create!(profile: self.person, provider: provider, enabled: true, oauth_data: oauth_data) end end diff --git a/plugins/oauth_client/models/oauth_client_plugin/auth.rb b/plugins/oauth_client/models/oauth_client_plugin/auth.rb index 58d7f53..88820f7 100644 --- a/plugins/oauth_client/models/oauth_client_plugin/auth.rb +++ b/plugins/oauth_client/models/oauth_client_plugin/auth.rb @@ -1,7 +1,7 @@ class OauthClientPlugin::Auth < ActiveRecord::Base attr_accessible :profile, :provider, :enabled, - :access_token, :expires_in + :access_token, :expires_in, :oauth_data belongs_to :profile, class_name: 'Profile' belongs_to :provider, class_name: 'OauthClientPlugin::Provider' @@ -12,6 +12,8 @@ class OauthClientPlugin::Auth < ActiveRecord::Base acts_as_having_settings field: :data + serialize :oauth_data, Hash + def expires_in self.expires_at - Time.now end diff --git a/plugins/oauth_client/test/functional/oauth_client_plugin_public_controller_test.rb b/plugins/oauth_client/test/functional/oauth_client_plugin_public_controller_test.rb index 4757ddf..5cdda50 100644 --- a/plugins/oauth_client/test/functional/oauth_client_plugin_public_controller_test.rb +++ b/plugins/oauth_client/test/functional/oauth_client_plugin_public_controller_test.rb @@ -14,6 +14,7 @@ class OauthClientPluginPublicControllerTest < ActionController::TestCase should 'redirect to signup when user is not found' do auth.info.stubs(:email).returns("xyz123@noosfero.org") auth.info.stubs(:name).returns('xyz123') + auth.stubs(:to_hash).returns({}) session[:provider_id] = provider.id get :callback diff --git a/plugins/oauth_client/test/unit/user_test.rb b/plugins/oauth_client/test/unit/user_test.rb index b1363df..0228274 100644 --- a/plugins/oauth_client/test/unit/user_test.rb +++ b/plugins/oauth_client/test/unit/user_test.rb @@ -57,7 +57,7 @@ class UserTest < ActiveSupport::TestCase }) user = User.create!(:email => 'testoauth@example.com', :login => 'testoauth', :oauth_providers => [], :oauth_signup_token => 'token') user.oauth_signup_token = 'token' - assert user.oauth_user_providers.first.oauth_data.present? + assert user.oauth_auths.first.oauth_data.present? end should 'save oauth as a hash when creating user with oauth' do @@ -72,12 +72,12 @@ class UserTest < ActiveSupport::TestCase } ) user = User.create!(:email => 'testoauth@example.com', :login => 'testoauth', :oauth_providers => [], :oauth_signup_token => 'token') - assert user.oauth_user_providers.first.oauth_data.is_a? Hash + assert user.oauth_auths.first.oauth_data.is_a? Hash end should 'note save oauth user provider when user is not originated from oauth' do user = User.create!(:email => 'testoauth@example.com', :login => 'testoauth', :password => 'test', :password_confirmation => 'test') - assert user.oauth_user_providers.count.eql? 0 + assert user.oauth_auths.count.eql? 0 end end -- libgit2 0.21.2