Commit 6005ec894a726cfa54685b703a4ea74a961f3956
Exists in
master
and in
4 other branches
Merge pull request #3392 from hiroponz/fix-non-ascii-char-username
Fix RoutingError when changing username to non ascii char.
Showing
3 changed files
with
33 additions
and
0 deletions
Show diff stats
app/controllers/admin/users_controller.rb
| ... | ... | @@ -84,6 +84,8 @@ class Admin::UsersController < Admin::ApplicationController |
| 84 | 84 | format.html { redirect_to [:admin, admin_user], notice: 'User was successfully updated.' } |
| 85 | 85 | format.json { head :ok } |
| 86 | 86 | else |
| 87 | + # restore username to keep form action url. | |
| 88 | + admin_user.username = params[:id] | |
| 87 | 89 | format.html { render action: "edit" } |
| 88 | 90 | format.json { render json: admin_user.errors, status: :unprocessable_entity } |
| 89 | 91 | end | ... | ... |
features/admin/users.feature
| ... | ... | @@ -6,3 +6,11 @@ Feature: Admin Users |
| 6 | 6 | Scenario: On Admin Users |
| 7 | 7 | Given I visit admin users page |
| 8 | 8 | Then I should see all users |
| 9 | + | |
| 10 | + Scenario: Edit user and change username to non ascii char | |
| 11 | + When I visit admin users page | |
| 12 | + And Click edit | |
| 13 | + And Input non ascii char in username | |
| 14 | + And Click save | |
| 15 | + Then See username error message | |
| 16 | + And Not chenged form action url | ... | ... |
features/steps/admin/admin_users.rb
| ... | ... | @@ -8,4 +8,27 @@ class AdminUsers < Spinach::FeatureSteps |
| 8 | 8 | page.should have_content user.name |
| 9 | 9 | end |
| 10 | 10 | end |
| 11 | + | |
| 12 | + And 'Click edit' do | |
| 13 | + @user = User.first | |
| 14 | + find("#edit_user_#{@user.id}").click | |
| 15 | + end | |
| 16 | + | |
| 17 | + And 'Input non ascii char in username' do | |
| 18 | + fill_in 'user_username', with: "\u3042\u3044" | |
| 19 | + end | |
| 20 | + | |
| 21 | + And 'Click save' do | |
| 22 | + click_button("Save") | |
| 23 | + end | |
| 24 | + | |
| 25 | + Then 'See username error message' do | |
| 26 | + within "#error_explanation" do | |
| 27 | + page.should have_content "Username" | |
| 28 | + end | |
| 29 | + end | |
| 30 | + | |
| 31 | + And 'Not chenged form action url' do | |
| 32 | + page.should have_selector %(form[action="/admin/users/#{@user.username}"]) | |
| 33 | + end | |
| 11 | 34 | end | ... | ... |