[Git][noosfero/noosfero][master] Allow multi environment on remote user plugin
Daniela Feitosa
gitlab at mg.gitlab.com
Fri Dec 18 16:46:29 BRST 2015
Daniela Feitosa pushed to branch master at Noosfero / noosfero
Commits:
e9c353c4 by Daniela Soares Feitosa at 2015-12-18T15:29:05Z
Allow multi environment on remote user plugin
Adding tests for multi env remote user
Signed-off-by: Gabriel Silva <gabriel93.silva at gmail.com>
Signed-off-by: Tallys Martins <tallysmartins at gmail.com>
Signed-off-by: Macartur Sousa <macartur.sc at gmail.com
Closes !753
- - - - -
2 changed files:
- plugins/remote_user/lib/remote_user_plugin.rb
- plugins/remote_user/test/functional/remote_user_plugin_test.rb
Changes:
=====================================
plugins/remote_user/lib/remote_user_plugin.rb
=====================================
--- a/plugins/remote_user/lib/remote_user_plugin.rb
+++ b/plugins/remote_user/lib/remote_user_plugin.rb
@@ -28,9 +28,9 @@ class RemoteUserPlugin < Noosfero::Plugin
end
if !logged_in?
- self.current_user = User.find_by_login(remote_user)
+ self.current_user = User.where(environment_id: environment, login: remote_user).first
unless self.current_user
- self.current_user = User.create!(:login => remote_user, :email => remote_user_email, :name => remote_user_name, :password => ('pw4'+remote_user), :password_confirmation => ('pw4'+remote_user))
+ self.current_user = User.create!(:environment => environment, :login => remote_user, :email => remote_user_email, :name => remote_user_name, :password => ('pw4'+remote_user), :password_confirmation => ('pw4'+remote_user))
self.current_user.activate
end
self.current_user.save!
@@ -39,9 +39,9 @@ class RemoteUserPlugin < Noosfero::Plugin
self.current_user.forget_me
reset_session
- self.current_user = User.find_by_login(remote_user)
+ self.current_user = User.where(environment_id: environment, login: remote_user).first
unless self.current_user
- self.current_user = User.create!(:login => remote_user, :email => remote_user_email, :name => remote_user_name, :password => ('pw4'+remote_user), :password_confirmation => ('pw4'+remote_user))
+ self.current_user = User.create!(:environment => environment, :login => remote_user, :email => remote_user_email, :name => remote_user_name, :password => ('pw4'+remote_user), :password_confirmation => ('pw4'+remote_user))
self.current_user.activate
end
self.current_user.save!
=====================================
plugins/remote_user/test/functional/remote_user_plugin_test.rb
=====================================
--- a/plugins/remote_user/test/functional/remote_user_plugin_test.rb
+++ b/plugins/remote_user/test/functional/remote_user_plugin_test.rb
@@ -6,6 +6,10 @@ class AccountControllerTest < ActionController::TestCase
@environment.enabled_plugins = ['RemoteUserPlugin']
@environment.save
+ @another_environment = Environment.new(name: "AnotherEnvironment")
+ @another_environment.enabled_plugins = ['RemoteUserPlugin']
+ @another_environment.save
+
@controller = AccountController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
@@ -136,4 +140,26 @@ class AccountControllerTest < ActionController::TestCase
assert session[:user].blank?
assert_response 404
end
+
+ should "create an user in the correct environment" do
+ @controller.stubs(:environment).returns(@another_environment)
+ @request.env["HTTP_REMOTE_USER"] = "testuser"
+
+ get :index
+ user = User.last
+ assert_equal user.environment, @another_environment
+ end
+
+ should "create an user in both environments" do
+ user = create_user('testuser', :email => 'testuser at example.com', :password => 'test', :password_confirmation => 'test')
+ @controller.stubs(:environment).returns(@another_environment)
+ @request.env["HTTP_REMOTE_USER"] = "testuser"
+
+ users = User.where(:login => 'testuser')
+ assert_equal users.count, 1
+
+ get :index
+ users = User.where(:login => 'testuser')
+ assert_equal users.count, 2
+ end
end
View it on GitLab: https://gitlab.com/noosfero/noosfero/commit/e9c353c4c26f973935d2bb3177023d7e27149c2c
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20151218/d5d957d9/attachment-0001.html>
More information about the Noosfero-dev
mailing list