[Users] Fix exception on users?name=non_existant_name

Just redirect to the show page unconditionally, it handles it already
This commit is contained in:
Earlopain 2022-10-13 15:36:56 +02:00
parent e3575a6efe
commit 7816c8562e
No known key found for this signature in database
GPG Key ID: 6CFB948E15246897
2 changed files with 4 additions and 14 deletions

View File

@ -19,12 +19,7 @@ class UsersController < ApplicationController
def index
if params[:name].present?
@user = User.find_by_name(params[:name])
if @user.nil?
raise "No user found with name: #{params[:name]}"
else
redirect_to user_path(@user)
end
redirect_to user_path(id: params[:name])
else
@users = User.search(search_params).includes(:user_status).paginate(params[:page], limit: params[:limit], search_count: params[:search])
respond_with(@users) do |format|

View File

@ -12,14 +12,9 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
assert_response :success
end
should "list all users for /users?name=<name>" do
get users_path, params: { name: @user.name }
assert_redirected_to(@user)
end
should "raise error for /users?name=<nonexistent>" do
get users_path, params: { name: "nobody" }
assert_response :error
should "redirect for /users?name=<name>" do
get users_path, params: { name: "some_username" }
assert_redirected_to(user_path(id: "some_username"))
end
should "list all users (with search)" do