From: Tom Hughes Date: Tue, 19 Jan 2021 18:24:41 +0000 (+0000) Subject: Redirect after saving settings in case the username has changed X-Git-Tag: live~2309 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/812f5b44e8a84607853973f83d1de3a2b6fa1633?hp=-c Redirect after saving settings in case the username has changed Fixes #3059 --- 812f5b44e8a84607853973f83d1de3a2b6fa1633 diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 9aea439cb..872a03d8b 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -52,7 +52,7 @@ Lint/DuplicateBranch: # Offense count: 487 # Configuration parameters: IgnoredMethods, CountRepeatedAttributes. Metrics/AbcSize: - Max: 194 + Max: 234 # Offense count: 62 # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods. @@ -92,7 +92,7 @@ Metrics/PerceivedComplexity: # Offense count: 365 Minitest/MultipleAssertions: - Max: 81 + Max: 97 # Offense count: 4 Naming/AccessorMethodName: diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 7f12720a6..b274b1808 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -128,6 +128,7 @@ class UsersController < ApplicationController (params[:user][:auth_provider] == current_user.auth_provider && params[:user][:auth_uid] == current_user.auth_uid) update_user(current_user, params) + redirect_to user_account_url(current_user) if current_user.errors.count.zero? else session[:new_user_settings] = params redirect_to auth_url(params[:user][:auth_provider], params[:user][:auth_uid]) @@ -461,6 +462,8 @@ class UsersController < ApplicationController update_user(current_user, settings) + flash.discard + session[:user_errors] = current_user.errors.as_json redirect_to :action => "account", :display_name => current_user.display_name @@ -655,12 +658,12 @@ class UsersController < ApplicationController set_locale(:reset => true) if user.new_email.blank? || user.new_email == user.email - flash.now[:notice] = t "users.account.flash update success" + flash[:notice] = t "users.account.flash update success" else user.email = user.new_email if user.valid? - flash.now[:notice] = t "users.account.flash update success confirm needed" + flash[:notice] = t "users.account.flash update success confirm needed" begin UserMailer.email_confirm(user, user.tokens.create).deliver_later diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb index 89c2d2c9c..12a804bc5 100644 --- a/test/controllers/users_controller_test.rb +++ b/test/controllers/users_controller_test.rb @@ -953,6 +953,9 @@ class UsersControllerTest < ActionDispatch::IntegrationTest user.description = "new description" user.preferred_editor = "default" post user_account_path(user), :params => { :user => user.attributes } + assert_response :redirect + assert_redirected_to user_account_url(user) + get user_account_path(user) assert_response :success assert_template :account assert_select "div#errorExplanation", false @@ -971,6 +974,9 @@ class UsersControllerTest < ActionDispatch::IntegrationTest # Changing to a valid editor should work user.preferred_editor = "id" post user_account_path(user), :params => { :user => user.attributes } + assert_response :redirect + assert_redirected_to user_account_url(user) + get user_account_path(user) assert_response :success assert_template :account assert_select "div#errorExplanation", false @@ -980,6 +986,9 @@ class UsersControllerTest < ActionDispatch::IntegrationTest # Changing to the default editor should work user.preferred_editor = "default" post user_account_path(user), :params => { :user => user.attributes } + assert_response :redirect + assert_redirected_to user_account_url(user) + get user_account_path(user) assert_response :success assert_template :account assert_select "div#errorExplanation", false @@ -989,6 +998,9 @@ class UsersControllerTest < ActionDispatch::IntegrationTest # Changing to an uploaded image should work image = Rack::Test::UploadedFile.new("test/gpx/fixtures/a.gif", "image/gif") post user_account_path(user), :params => { :avatar_action => "new", :user => user.attributes.merge(:avatar => image) } + assert_response :redirect + assert_redirected_to user_account_url(user) + get user_account_path(user) assert_response :success assert_template :account assert_select "div#errorExplanation", false @@ -997,6 +1009,9 @@ class UsersControllerTest < ActionDispatch::IntegrationTest # Changing to a gravatar image should work post user_account_path(user), :params => { :avatar_action => "gravatar", :user => user.attributes } + assert_response :redirect + assert_redirected_to user_account_url(user) + get user_account_path(user) assert_response :success assert_template :account assert_select "div#errorExplanation", false @@ -1005,6 +1020,9 @@ class UsersControllerTest < ActionDispatch::IntegrationTest # Removing the image should work post user_account_path(user), :params => { :avatar_action => "delete", :user => user.attributes } + assert_response :redirect + assert_redirected_to user_account_url(user) + get user_account_path(user) assert_response :success assert_template :account assert_select "div#errorExplanation", false @@ -1037,6 +1055,9 @@ class UsersControllerTest < ActionDispatch::IntegrationTest # Changing name to one that doesn't exist should work new_attributes = user.attributes.dup.merge(:display_name => "new tester") post user_account_path(user), :params => { :user => new_attributes } + assert_response :redirect + assert_redirected_to user_account_url(:display_name => "new tester") + get user_account_path(:display_name => "new tester") assert_response :success assert_template :account assert_select "div#errorExplanation", false @@ -1079,6 +1100,9 @@ class UsersControllerTest < ActionDispatch::IntegrationTest post user_account_path(user), :params => { :user => user.attributes } end end + assert_response :redirect + assert_redirected_to user_account_url(user) + get user_account_path(user) assert_response :success assert_template :account assert_select "div#errorExplanation", false