Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use turbo for the settings page to stop the URL changing #5453

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/controllers/accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ def update
(params[:user][:auth_provider] == current_user.auth_provider &&
params[:user][:auth_uid] == current_user.auth_uid)
update_user(current_user, user_params)
if current_user.errors.count.zero?
if current_user.errors.empty?
redirect_to edit_account_path
else
render :edit
render :edit, :status => :unprocessable_entity
end
else
session[:new_user_settings] = user_params.to_h
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/concerns/user_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ def update_user(user, params)
# Ignore errors sending email
end
else
current_user.errors.add(:new_email, current_user.errors[:email])
current_user.errors.add(:email, [])
current_user.errors.delete(:email).each do |error|
current_user.errors.add(:new_email, error)
end
end

user.restore_email!
Expand Down
2 changes: 1 addition & 1 deletion app/views/accounts/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<%= render :partial => "settings_menu" %>

<%= bootstrap_form_for current_user, :url => { :action => :update }, :html => { :multipart => true, :id => "accountForm", :autocomplete => :off } do |f| %>
<%= bootstrap_form_for current_user, :url => { :action => :update }, :data => { :turbo => true }, :html => { :multipart => true, :id => "accountForm", :autocomplete => :off } do |f| %>

<%= f.text_field :display_name %>
<%= f.email_field :email, :disabled => true, :label => t(".current email address") %>
Expand Down
8 changes: 4 additions & 4 deletions test/controllers/accounts_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ def test_account
# Changing name to one that exists should fail
new_attributes = user.attributes.dup.merge(:display_name => create(:user).display_name)
patch account_path, :params => { :user => new_attributes }
assert_response :success
assert_response :unprocessable_entity
assert_template :edit
assert_select ".alert-success", false
assert_select "form#accountForm > div > input.is-invalid#user_display_name"

# Changing name to one that exists should fail, regardless of case
new_attributes = user.attributes.dup.merge(:display_name => create(:user).display_name.upcase)
patch account_path, :params => { :user => new_attributes }
assert_response :success
assert_response :unprocessable_entity
assert_template :edit
assert_select ".alert-success", false
assert_select "form#accountForm > div > input.is-invalid#user_display_name"
Expand All @@ -88,7 +88,7 @@ def test_account
patch account_path, :params => { :user => user.attributes }
end
end
assert_response :success
assert_response :unprocessable_entity
assert_template :edit
assert_select ".alert-success", false
assert_select "form#accountForm > div > input.is-invalid#user_new_email"
Expand All @@ -100,7 +100,7 @@ def test_account
patch account_path, :params => { :user => user.attributes }
end
end
assert_response :success
assert_response :unprocessable_entity
assert_template :edit
assert_select ".alert-success", false
assert_select "form#accountForm > div > input.is-invalid#user_new_email"
Expand Down
Loading