Skip to content

Commit

Permalink
Merge pull request #36 from cre-ne-jp/fix-redirection-on-user-edit
Browse files Browse the repository at this point in the history
利用者追加・編集で保存した後のリダイレクト先を修正する
  • Loading branch information
ochaochaocha3 committed Apr 8, 2017
2 parents 2cacbae + bb0a6da commit fe05de9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
4 changes: 2 additions & 2 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def create

if @user.save
flash[:success] = t('views.flash.added_user')
redirect_to(users_path)
redirect_to(@user)
else
render(:new)
end
Expand All @@ -36,7 +36,7 @@ def update

if @user.update_attributes(user_params)
flash[:success] = t('views.flash.updated_user')
redirect_to(users_path)
redirect_to(@user)
else
@user.username = old_username
render(:edit)
Expand Down
10 changes: 4 additions & 6 deletions test/controllers/users_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,24 @@ class UsersControllerTest < ActionController::TestCase
test 'create: 追加に成功する' do
login_user(@user)

patch(
post(
:create,
id: 'new_user',
user: {
username: 'new_user',
password: '12345678',
password_confirmation: '12345678'
}
)

assert_redirected_to(:users, '利用者一覧ページにリダイレクトされる')
assert_redirected_to(user_path(id: 'new_user'), '利用者ページにリダイレクトされる')
refute_nil(flash[:success], 'successのflashが表示される')
end

test 'create: 無効な値の場合は追加に失敗する' do
login_user(@user)

patch(
post(
:create,
id: @user.friendly_id,
user: {
username: '',
password: '12345678',
Expand All @@ -113,7 +111,7 @@ class UsersControllerTest < ActionController::TestCase
}
)

assert_redirected_to(:users, '利用者一覧ページにリダイレクトされる')
assert_redirected_to(user_path(id: 'new_user'), '利用者ページにリダイレクトされる')
refute_nil(flash[:success], 'successのflashが表示される')
end

Expand Down

0 comments on commit fe05de9

Please sign in to comment.