Commit 6982dcf63caa15198e1430febd743f16fa5b2887
1 parent
b05a71bd
Exists in
stable-spb-1.4
and in
5 other branches
Allow multi environment on remote user plugin
Adding tests for multi env remote user Signed-off-by: Gabriel Silva <gabriel93.silva@gmail.com> Signed-off-by: Tallys Martins <tallysmartins@gmail.com> Signed-off-by: Macartur Sousa <macartur.sc@gmail.com Closes !753 (cherry picked from commit e9c353c4c26f973935d2bb3177023d7e27149c2c)
Showing
2 changed files
with
30 additions
and
4 deletions
Show diff stats
plugins/remote_user/lib/remote_user_plugin.rb
... | ... | @@ -28,9 +28,9 @@ class RemoteUserPlugin < Noosfero::Plugin |
28 | 28 | end |
29 | 29 | |
30 | 30 | if !logged_in? |
31 | - self.current_user = User.find_by_login(remote_user) | |
31 | + self.current_user = User.where(environment_id: environment, login: remote_user).first | |
32 | 32 | unless self.current_user |
33 | - 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)) | |
33 | + 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)) | |
34 | 34 | self.current_user.activate |
35 | 35 | end |
36 | 36 | self.current_user.save! |
... | ... | @@ -39,9 +39,9 @@ class RemoteUserPlugin < Noosfero::Plugin |
39 | 39 | self.current_user.forget_me |
40 | 40 | reset_session |
41 | 41 | |
42 | - self.current_user = User.find_by_login(remote_user) | |
42 | + self.current_user = User.where(environment_id: environment, login: remote_user).first | |
43 | 43 | unless self.current_user |
44 | - 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)) | |
44 | + 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)) | |
45 | 45 | self.current_user.activate |
46 | 46 | end |
47 | 47 | self.current_user.save! | ... | ... |
plugins/remote_user/test/functional/remote_user_plugin_test.rb
... | ... | @@ -9,6 +9,10 @@ class AccountControllerTest < ActionController::TestCase |
9 | 9 | @environment.enabled_plugins = ['RemoteUserPlugin'] |
10 | 10 | @environment.save |
11 | 11 | |
12 | + @another_environment = Environment.new(name: "AnotherEnvironment") | |
13 | + @another_environment.enabled_plugins = ['RemoteUserPlugin'] | |
14 | + @another_environment.save | |
15 | + | |
12 | 16 | @controller = AccountController.new |
13 | 17 | @request = ActionController::TestRequest.new |
14 | 18 | @response = ActionController::TestResponse.new |
... | ... | @@ -139,4 +143,26 @@ class AccountControllerTest < ActionController::TestCase |
139 | 143 | assert session[:user].blank? |
140 | 144 | assert_response 404 |
141 | 145 | end |
146 | + | |
147 | + should "create an user in the correct environment" do | |
148 | + @controller.stubs(:environment).returns(@another_environment) | |
149 | + @request.env["HTTP_REMOTE_USER"] = "testuser" | |
150 | + | |
151 | + get :index | |
152 | + user = User.last | |
153 | + assert_equal user.environment, @another_environment | |
154 | + end | |
155 | + | |
156 | + should "create an user in both environments" do | |
157 | + user = create_user('testuser', :email => 'testuser@example.com', :password => 'test', :password_confirmation => 'test') | |
158 | + @controller.stubs(:environment).returns(@another_environment) | |
159 | + @request.env["HTTP_REMOTE_USER"] = "testuser" | |
160 | + | |
161 | + users = User.where(:login => 'testuser') | |
162 | + assert_equal users.count, 1 | |
163 | + | |
164 | + get :index | |
165 | + users = User.where(:login => 'testuser') | |
166 | + assert_equal users.count, 2 | |
167 | + end | |
142 | 168 | end | ... | ... |