From a3606e00b472a8cd5775fa13a9c0a14da9290c91 Mon Sep 17 00:00:00 2001 From: Andy Allan Date: Mon, 10 Sep 2018 10:03:34 +0800 Subject: [PATCH] Rename user#list to user#index --- app/controllers/user_controller.rb | 4 +- app/views/user/_user.html.erb | 4 +- .../user/{list.html.erb => index.html.erb} | 0 config/locales/en.yml | 2 +- config/routes.rb | 4 +- test/controllers/user_controller_test.rb | 66 +++++++++---------- 6 files changed, 40 insertions(+), 40 deletions(-) rename app/views/user/{list.html.erb => index.html.erb} (100%) diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 644c62b6f..5aaa9d72b 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -14,7 +14,7 @@ class UserController < ApplicationController before_action :require_allow_read_prefs, :only => [:api_details] before_action :require_allow_read_gpx, :only => [:api_gpx_files] before_action :require_cookies, :only => [:new, :login, :confirm] - before_action :require_administrator, :only => [:set_status, :delete, :list] + before_action :require_administrator, :only => [:set_status, :delete, :index] around_action :api_call_handle_error, :only => [:api_read, :api_users, :api_details, :api_gpx_files] before_action :lookup_user_by_id, :only => [:api_read] before_action :lookup_user_by_name, :only => [:set_status, :delete] @@ -488,7 +488,7 @@ class UserController < ApplicationController ## # display a list of users matching specified criteria - def list + def index if request.post? ids = params[:user].keys.collect(&:to_i) diff --git a/app/views/user/_user.html.erb b/app/views/user/_user.html.erb index ad219655e..da9ae75c9 100644 --- a/app/views/user/_user.html.erb +++ b/app/views/user/_user.html.erb @@ -7,13 +7,13 @@

<% if user.creation_ip %> - <%= raw t 'user.list.summary', + <%= raw t 'user.index.summary', :name => link_to(h(user.display_name), user_path(user)), :ip_address => link_to(user.creation_ip, :ip => user.creation_ip), :date => l(user.creation_time, :format => :friendly) %> <% else %> - <%= raw t 'user.list.summary_no_ip', + <%= raw t 'user.index.summary_no_ip', :name => link_to(h(user.display_name), user_path(user)), :date => l(user.creation_time, :format => :friendly) %> diff --git a/app/views/user/list.html.erb b/app/views/user/index.html.erb similarity index 100% rename from app/views/user/list.html.erb rename to app/views/user/index.html.erb diff --git a/config/locales/en.yml b/config/locales/en.yml index 7682204d5..bebfedfde 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2168,7 +2168,7 @@ en: not_a_friend: "%{name} is not one of your friends." filter: not_an_administrator: "You need to be an administrator to perform that action." - list: + index: title: Users heading: Users showing: diff --git a/config/routes.rb b/config/routes.rb index da7e0de71..35c46d8c1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -242,8 +242,8 @@ OpenStreetMap::Application.routes.draw do get "/user/:display_name/delete" => "user#delete", :as => :delete_user # user lists - match "/users" => "user#list", :via => [:get, :post] - match "/users/:status" => "user#list", :via => [:get, :post] + match "/users" => "user#index", :via => [:get, :post] + match "/users/:status" => "user#index", :via => [:get, :post] # geocoder get "/search" => "geocoder#search" diff --git a/test/controllers/user_controller_test.rb b/test/controllers/user_controller_test.rb index ba4b2ff3a..ba4709407 100644 --- a/test/controllers/user_controller_test.rb +++ b/test/controllers/user_controller_test.rb @@ -170,19 +170,19 @@ class UserControllerTest < ActionController::TestCase assert_routing( { :path => "/users", :method => :get }, - { :controller => "user", :action => "list" } + { :controller => "user", :action => "index" } ) assert_routing( { :path => "/users", :method => :post }, - { :controller => "user", :action => "list" } + { :controller => "user", :action => "index" } ) assert_routing( { :path => "/users/status", :method => :get }, - { :controller => "user", :action => "list", :status => "status" } + { :controller => "user", :action => "index", :status => "status" } ) assert_routing( { :path => "/users/status", :method => :post }, - { :controller => "user", :action => "list", :status => "status" } + { :controller => "user", :action => "index", :status => "status" } ) end @@ -1431,7 +1431,7 @@ class UserControllerTest < ActionController::TestCase assert_equal "deleted", user.status end - def test_list_get + def test_index_get user = create(:user) moderator_user = create(:moderator_user) administrator_user = create(:administrator_user) @@ -1443,21 +1443,21 @@ class UserControllerTest < ActionController::TestCase assert_equal 7, User.count # Shouldn't work when not logged in - get :list + get :index assert_response :redirect assert_redirected_to :action => :login, :referer => users_path session[:user] = user.id # Shouldn't work when logged in as a normal user - get :list + get :index assert_response :redirect assert_redirected_to :action => :login, :referer => users_path session[:user] = moderator_user.id # Shouldn't work when logged in as a moderator - get :list + get :index assert_response :redirect assert_redirected_to :action => :login, :referer => users_path @@ -1465,25 +1465,25 @@ class UserControllerTest < ActionController::TestCase # Note there is a header row, so all row counts are users + 1 # Should work when logged in as an administrator - get :list + get :index assert_response :success - assert_template :list + assert_template :index assert_select "table#user_list tr", :count => 7 + 1 # Should be able to limit by status - get :list, :params => { :status => "suspended" } + get :index, :params => { :status => "suspended" } assert_response :success - assert_template :list + assert_template :index assert_select "table#user_list tr", :count => 1 + 1 # Should be able to limit by IP address - get :list, :params => { :ip => "1.2.3.4" } + get :index, :params => { :ip => "1.2.3.4" } assert_response :success - assert_template :list + assert_template :index assert_select "table#user_list tr", :count => 1 + 1 end - def test_list_get_paginated + def test_index_get_paginated 1.upto(100).each do |n| User.create(:display_name => "extra_#{n}", :email => "extra#{n}@example.com", @@ -1495,29 +1495,29 @@ class UserControllerTest < ActionController::TestCase # 100 examples, an administrator, and a granter for the admin. assert_equal 102, User.count - get :list + get :index assert_response :success - assert_template :list + assert_template :index assert_select "table#user_list tr", :count => 51 - get :list, :params => { :page => 2 } + get :index, :params => { :page => 2 } assert_response :success - assert_template :list + assert_template :index assert_select "table#user_list tr", :count => 51 - get :list, :params => { :page => 3 } + get :index, :params => { :page => 3 } assert_response :success - assert_template :list + assert_template :index assert_select "table#user_list tr", :count => 3 end - def test_list_post_confirm + def test_index_post_confirm inactive_user = create(:user, :pending) suspended_user = create(:user, :suspended) # Shouldn't work when not logged in assert_no_difference "User.active.count" do - post :list, :params => { :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 } } + post :index, :params => { :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 } } end assert_response :redirect assert_redirected_to :action => :login, :referer => users_path @@ -1528,7 +1528,7 @@ class UserControllerTest < ActionController::TestCase # Shouldn't work when logged in as a normal user assert_no_difference "User.active.count" do - post :list, :params => { :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 } } + post :index, :params => { :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 } } end assert_response :redirect assert_redirected_to :action => :login, :referer => users_path @@ -1539,7 +1539,7 @@ class UserControllerTest < ActionController::TestCase # Shouldn't work when logged in as a moderator assert_no_difference "User.active.count" do - post :list, :params => { :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 } } + post :index, :params => { :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 } } end assert_response :redirect assert_redirected_to :action => :login, :referer => users_path @@ -1550,21 +1550,21 @@ class UserControllerTest < ActionController::TestCase # Should work when logged in as an administrator assert_difference "User.active.count", 2 do - post :list, :params => { :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 } } + post :index, :params => { :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 } } end assert_response :redirect - assert_redirected_to :action => :list + assert_redirected_to :action => :index assert_equal "confirmed", inactive_user.reload.status assert_equal "confirmed", suspended_user.reload.status end - def test_list_post_hide + def test_index_post_hide normal_user = create(:user) confirmed_user = create(:user, :confirmed) # Shouldn't work when not logged in assert_no_difference "User.active.count" do - post :list, :params => { :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 } } + post :index, :params => { :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 } } end assert_response :redirect assert_redirected_to :action => :login, :referer => users_path @@ -1575,7 +1575,7 @@ class UserControllerTest < ActionController::TestCase # Shouldn't work when logged in as a normal user assert_no_difference "User.active.count" do - post :list, :params => { :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 } } + post :index, :params => { :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 } } end assert_response :redirect assert_redirected_to :action => :login, :referer => users_path @@ -1586,7 +1586,7 @@ class UserControllerTest < ActionController::TestCase # Shouldn't work when logged in as a moderator assert_no_difference "User.active.count" do - post :list, :params => { :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 } } + post :index, :params => { :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 } } end assert_response :redirect assert_redirected_to :action => :login, :referer => users_path @@ -1597,10 +1597,10 @@ class UserControllerTest < ActionController::TestCase # Should work when logged in as an administrator assert_difference "User.active.count", -2 do - post :list, :params => { :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 } } + post :index, :params => { :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 } } end assert_response :redirect - assert_redirected_to :action => :list + assert_redirected_to :action => :index assert_equal "deleted", normal_user.reload.status assert_equal "deleted", confirmed_user.reload.status end -- 2.39.5