From ab98f8b5b1fb323ded965cdb352a504525dd0703 Mon Sep 17 00:00:00 2001 From: Michael Kozono Date: Thu, 11 May 2017 13:57:03 -0700 Subject: Fix redirect message for groups and users --- app/controllers/concerns/routable_actions.rb | 8 ++++---- spec/controllers/groups_controller_spec.rb | 8 ++++++-- spec/controllers/projects_controller_spec.rb | 8 ++++++-- spec/controllers/users_controller_spec.rb | 12 ++++++++---- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/app/controllers/concerns/routable_actions.rb b/app/controllers/concerns/routable_actions.rb index d4ab6782444..afd110adcad 100644 --- a/app/controllers/concerns/routable_actions.rb +++ b/app/controllers/concerns/routable_actions.rb @@ -4,7 +4,7 @@ module RoutableActions def find_routable!(routable_klass, requested_full_path, extra_authorization_proc: nil) routable = routable_klass.find_by_full_path(requested_full_path, follow_redirects: request.get?) - if routable_authorized?(routable_klass, routable, extra_authorization_proc) + if routable_authorized?(routable, extra_authorization_proc) ensure_canonical_path(routable, requested_full_path) routable else @@ -13,8 +13,8 @@ module RoutableActions end end - def routable_authorized?(routable_klass, routable, extra_authorization_proc) - action = :"read_#{routable_klass.to_s.underscore}" + def routable_authorized?(routable, extra_authorization_proc) + action = :"read_#{routable.class.to_s.underscore}" return false unless can?(current_user, action, routable) if extra_authorization_proc @@ -30,7 +30,7 @@ module RoutableActions canonical_path = routable.full_path if canonical_path != requested_path if canonical_path.casecmp(requested_path) != 0 - flash[:notice] = "Project '#{requested_path}' was moved to '#{canonical_path}'. Please update any links and bookmarks that may still have the old path." + flash[:notice] = "#{routable.class.to_s.titleize} '#{requested_path}' was moved to '#{canonical_path}'. Please update any links and bookmarks that may still have the old path." end redirect_to request.original_url.sub(requested_path, canonical_path) end diff --git a/spec/controllers/groups_controller_spec.rb b/spec/controllers/groups_controller_spec.rb index df8ea225814..15dae3231ca 100644 --- a/spec/controllers/groups_controller_spec.rb +++ b/spec/controllers/groups_controller_spec.rb @@ -101,7 +101,7 @@ describe GroupsController do get :issues, id: redirect_route.path expect(response).to redirect_to(issues_group_path(group.to_param)) - expect(controller).to set_flash[:notice].to(/moved/) + expect(controller).to set_flash[:notice].to(group_moved_message(redirect_route, group)) end end end @@ -146,7 +146,7 @@ describe GroupsController do get :merge_requests, id: redirect_route.path expect(response).to redirect_to(merge_requests_group_path(group.to_param)) - expect(controller).to set_flash[:notice].to(/moved/) + expect(controller).to set_flash[:notice].to(group_moved_message(redirect_route, group)) end end end @@ -249,4 +249,8 @@ describe GroupsController do end end end + + def group_moved_message(redirect_route, group) + "Group '#{redirect_route.path}' was moved to '#{group.full_path}'. Please update any links and bookmarks that may still have the old path." + end end diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb index e46ef447df2..e230944d52e 100644 --- a/spec/controllers/projects_controller_spec.rb +++ b/spec/controllers/projects_controller_spec.rb @@ -227,7 +227,7 @@ describe ProjectsController do get :show, namespace_id: 'foo', id: 'bar' expect(response).to redirect_to(public_project) - expect(controller).to set_flash[:notice].to(/moved/) + expect(controller).to set_flash[:notice].to(project_moved_message(redirect_route, public_project)) end end end @@ -473,7 +473,7 @@ describe ProjectsController do get :refs, namespace_id: 'foo', id: 'bar' expect(response).to redirect_to(refs_namespace_project_path(namespace_id: public_project.namespace, id: public_project)) - expect(controller).to set_flash[:notice].to(/moved/) + expect(controller).to set_flash[:notice].to(project_moved_message(redirect_route, public_project)) end end end @@ -487,4 +487,8 @@ describe ProjectsController do expect(JSON.parse(response.body).keys).to match_array(%w(body references)) end end + + def project_moved_message(redirect_route, project) + "Project '#{redirect_route.path}' was moved to '#{project.full_path}'. Please update any links and bookmarks that may still have the old path." + end end diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index 74c5aa44ba9..1d61719f1d0 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -83,7 +83,7 @@ describe UsersController do get :show, username: redirect_route.path expect(response).to redirect_to(user) - expect(controller).to set_flash[:notice].to(/moved/) + expect(controller).to set_flash[:notice].to(user_moved_message(redirect_route, user)) end end @@ -162,7 +162,7 @@ describe UsersController do get :calendar, username: redirect_route.path expect(response).to redirect_to(user_calendar_path(user)) - expect(controller).to set_flash[:notice].to(/moved/) + expect(controller).to set_flash[:notice].to(user_moved_message(redirect_route, user)) end end end @@ -216,7 +216,7 @@ describe UsersController do get :calendar_activities, username: redirect_route.path expect(response).to redirect_to(user_calendar_activities_path(user)) - expect(controller).to set_flash[:notice].to(/moved/) + expect(controller).to set_flash[:notice].to(user_moved_message(redirect_route, user)) end end end @@ -270,7 +270,7 @@ describe UsersController do get :snippets, username: redirect_route.path expect(response).to redirect_to(user_snippets_path(user)) - expect(controller).to set_flash[:notice].to(/moved/) + expect(controller).to set_flash[:notice].to(user_moved_message(redirect_route, user)) end end end @@ -320,4 +320,8 @@ describe UsersController do end end end + + def user_moved_message(redirect_route, user) + "User '#{redirect_route.path}' was moved to '#{user.full_path}'. Please update any links and bookmarks that may still have the old path." + end end -- cgit v1.2.1