Commit e9c353c4c26f973935d2bb3177023d7e27149c2c
1 parent
5607f066
Exists in
master
and in
17 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
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
... | ... | @@ -6,6 +6,10 @@ class AccountControllerTest < ActionController::TestCase |
6 | 6 | @environment.enabled_plugins = ['RemoteUserPlugin'] |
7 | 7 | @environment.save |
8 | 8 | |
9 | + @another_environment = Environment.new(name: "AnotherEnvironment") | |
10 | + @another_environment.enabled_plugins = ['RemoteUserPlugin'] | |
11 | + @another_environment.save | |
12 | + | |
9 | 13 | @controller = AccountController.new |
10 | 14 | @request = ActionController::TestRequest.new |
11 | 15 | @response = ActionController::TestResponse.new |
... | ... | @@ -136,4 +140,26 @@ class AccountControllerTest < ActionController::TestCase |
136 | 140 | assert session[:user].blank? |
137 | 141 | assert_response 404 |
138 | 142 | end |
143 | + | |
144 | + should "create an user in the correct environment" do | |
145 | + @controller.stubs(:environment).returns(@another_environment) | |
146 | + @request.env["HTTP_REMOTE_USER"] = "testuser" | |
147 | + | |
148 | + get :index | |
149 | + user = User.last | |
150 | + assert_equal user.environment, @another_environment | |
151 | + end | |
152 | + | |
153 | + should "create an user in both environments" do | |
154 | + user = create_user('testuser', :email => 'testuser@example.com', :password => 'test', :password_confirmation => 'test') | |
155 | + @controller.stubs(:environment).returns(@another_environment) | |
156 | + @request.env["HTTP_REMOTE_USER"] = "testuser" | |
157 | + | |
158 | + users = User.where(:login => 'testuser') | |
159 | + assert_equal users.count, 1 | |
160 | + | |
161 | + get :index | |
162 | + users = User.where(:login => 'testuser') | |
163 | + assert_equal users.count, 2 | |
164 | + end | |
139 | 165 | end | ... | ... |
-
mentioned in commit 6982dcf63caa15198e1430febd743f16fa5b2887