diff --git a/app/queries/admin/moderators_query.rb b/app/queries/admin/moderators_query.rb index b8b95d9ab..2de7bb2a9 100644 --- a/app/queries/admin/moderators_query.rb +++ b/app/queries/admin/moderators_query.rb @@ -24,7 +24,7 @@ module Admin end def self.role_id_for(role) - Role.find_by!(name: role).id + Role.find_by(name: role)&.id end def self.search_relation(relation, search) diff --git a/app/views/admin/mods/index.html.erb b/app/views/admin/mods/index.html.erb index 8790623a2..5163d61d9 100644 --- a/app/views/admin/mods/index.html.erb +++ b/app/views/admin/mods/index.html.erb @@ -19,40 +19,43 @@ <%= f.submit "Search", class: "btn btn-light" %> <% end %> +<% if @mods.empty? %> +
There are no mods matching your search criteria.
+<% else %> + <%= paginate @mods, theme: "internal" %> -<%= paginate @mods, theme: "internal" %> - - - - - - - - - - <% if params[:state] == "potential" %> - - <% end %> - - - - <% @mods.each do |mod| %> +
IDProfileCommentsBadgesLast CommentAction
+ - - - - - + + + + + <% if params[:state] == "potential" %> - + <% end %> - <% end %> - -
<%= mod.id %><%= link_to mod.username, admin_user_path(mod.id) %><%= mod.comments_count %><%= mod.badge_achievements_count %><%= time_ago_in_words mod.last_comment_at %> agoIDProfileCommentsBadgesLast Comment - <%= form_with model: [:admin, mod], url: admin_mod_path(mod.id), method: :patch, local: true do |f| %> - <%= f.submit "Make Trusted Mod", class: "btn btn-light js-add-to-mod-channel" %> - <% end %> - Action
+ + + <% @mods.each do |mod| %> + + <%= mod.id %> + <%= link_to mod.username, admin_user_path(mod.id) %> + <%= mod.comments_count %> + <%= mod.badge_achievements_count %> + <%= time_ago_in_words mod.last_comment_at %> ago + <% if params[:state] == "potential" %> + + <%= form_with model: [:admin, mod], url: admin_mod_path(mod.id), method: :patch, local: true do |f| %> + <%= f.submit "Make Trusted Mod", class: "btn btn-light js-add-to-mod-channel" %> + <% end %> + + <% end %> + + <% end %> + + -<%= paginate @mods, theme: "internal" %> + <%= paginate @mods, theme: "internal" %> +<% end %> diff --git a/spec/queries/admin/moderators_query_spec.rb b/spec/queries/admin/moderators_query_spec.rb index 0a4afbed4..89269c38a 100644 --- a/spec/queries/admin/moderators_query_spec.rb +++ b/spec/queries/admin/moderators_query_spec.rb @@ -38,7 +38,7 @@ RSpec.describe Admin::ModeratorsQuery, type: :query do context "when state does not exist" do let(:options) { { state: "non_existent_role" } } - it { within_block_is_expected.to raise_error(ActiveRecord::RecordNotFound) } + it { is_expected.to match_array([]) } end end end diff --git a/spec/requests/admin/mods_spec.rb b/spec/requests/admin/mods_spec.rb index 6d24703c6..28d626016 100644 --- a/spec/requests/admin/mods_spec.rb +++ b/spec/requests/admin/mods_spec.rb @@ -35,6 +35,13 @@ RSpec.describe "/admin/mods", type: :request do end end + context "when the are no matching mods" do + it "displays an warning" do + get "/admin/mods?search=no-results&state=tag_moderator" + expect(response.body).to include("There are no mods matching your search criteria") + end + end + it "displays mod user" do get "/admin/mods" expect(response.body).to include(moderator.username)