diff options
-rw-r--r-- | app/controllers/groups_controller.rb | 13 | ||||
-rw-r--r-- | app/views/groups/index.html.erb | 5 | ||||
-rw-r--r-- | test/functional/groups_controller_test.rb | 6 |
3 files changed, 19 insertions, 5 deletions
diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index 2dbcd8a1f..0cd4055e5 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -26,9 +26,10 @@ class GroupsController < ApplicationController def index @groups = Group.sorted.all - respond_to do |format| - format.html + format.html { + @user_count_by_group_id = user_count_by_group_id + } format.api end end @@ -138,4 +139,12 @@ class GroupsController < ApplicationController rescue ActiveRecord::RecordNotFound render_404 end + + def user_count_by_group_id + h = User.joins(:groups).group('group_id').count + h.keys.each do |key| + h[key.to_i] = h.delete(key) + end + h + end end diff --git a/app/views/groups/index.html.erb b/app/views/groups/index.html.erb index d48afe9f0..22c89eff4 100644 --- a/app/views/groups/index.html.erb +++ b/app/views/groups/index.html.erb @@ -3,7 +3,6 @@ </div> <%= title l(:label_group_plural) %> - <% if @groups.any? %> <table class="list groups"> <thead><tr> @@ -13,9 +12,9 @@ </tr></thead> <tbody> <% @groups.each do |group| %> - <tr class="<%= cycle 'odd', 'even' %>"> + <tr id="group-<%= group.id %>" class="<%= cycle 'odd', 'even' %>"> <td class="name"><%= link_to h(group), edit_group_path(group) %></td> - <td><%= group.users.size %></td> + <td class="user_count"><%= @user_count_by_group_id[group.id] || 0 %></td> <td class="buttons"><%= delete_link group %></td> </tr> <% end %> diff --git a/test/functional/groups_controller_test.rb b/test/functional/groups_controller_test.rb index 35f0a4312..252472ab6 100644 --- a/test/functional/groups_controller_test.rb +++ b/test/functional/groups_controller_test.rb @@ -30,6 +30,12 @@ class GroupsControllerTest < ActionController::TestCase assert_template 'index' end + def test_index_should_show_user_count + get :index + assert_response :success + assert_select 'tr#group-11 td.user_count', :text => '1' + end + def test_show get :show, :id => 10 assert_response :success |