@@ -1,28 +1,39 | |||||
1 | <div class="contextual"> |
|
1 | <div class="contextual"> | |
2 | <%= link_to l(:label_group_new), new_group_path, :class => 'icon icon-add' %> |
|
2 | <%= link_to l(:label_group_new), new_group_path, :class => 'icon icon-add' %> | |
3 | </div> |
|
3 | </div> | |
4 |
|
4 | |||
5 | <%= title l(:label_group_plural) %> |
|
5 | <%= title l(:label_group_plural) %> | |
|
6 | ||||
|
7 | <%= form_tag(groups_path, :method => :get) do %> | |||
|
8 | <fieldset><legend><%= l(:label_filter_plural) %></legend> | |||
|
9 | <label for='name'><%= l(:label_group) %>:</label> | |||
|
10 | <%= text_field_tag 'name', params[:name], :size => 30 %> | |||
|
11 | <%= submit_tag l(:button_apply), :class => "small", :name => nil %> | |||
|
12 | <%= link_to l(:button_clear), groups_path, :class => 'icon icon-reload' %> | |||
|
13 | </fieldset> | |||
|
14 | <% end %> | |||
|
15 | | |||
|
16 | ||||
6 | <% if @groups.any? %> |
|
17 | <% if @groups.any? %> | |
7 | <div class="autoscroll"> |
|
18 | <div class="autoscroll"> | |
8 | <table class="list groups"> |
|
19 | <table class="list groups"> | |
9 | <thead><tr> |
|
20 | <thead><tr> | |
10 | <th><%=l(:label_group)%></th> |
|
21 | <th><%=l(:label_group)%></th> | |
11 | <th><%=l(:label_user_plural)%></th> |
|
22 | <th><%=l(:label_user_plural)%></th> | |
12 | <th></th> |
|
23 | <th></th> | |
13 | </tr></thead> |
|
24 | </tr></thead> | |
14 | <tbody> |
|
25 | <tbody> | |
15 | <% @groups.each do |group| %> |
|
26 | <% @groups.each do |group| %> | |
16 | <tr id="group-<%= group.id %>" class="<%= cycle 'odd', 'even' %> <%= "builtin" if group.builtin? %>"> |
|
27 | <tr id="group-<%= group.id %>" class="<%= cycle 'odd', 'even' %> <%= "builtin" if group.builtin? %>"> | |
17 | <td class="name"><%= link_to group, edit_group_path(group) %></td> |
|
28 | <td class="name"><%= link_to group, edit_group_path(group) %></td> | |
18 | <td class="user_count"><%= (@user_count_by_group_id[group.id] || 0) unless group.builtin? %></td> |
|
29 | <td class="user_count"><%= (@user_count_by_group_id[group.id] || 0) unless group.builtin? %></td> | |
19 | <td class="buttons"><%= delete_link group unless group.builtin? %></td> |
|
30 | <td class="buttons"><%= delete_link group unless group.builtin? %></td> | |
20 | </tr> |
|
31 | </tr> | |
21 | <% end %> |
|
32 | <% end %> | |
22 | </tbody> |
|
33 | </tbody> | |
23 | </table> |
|
34 | </table> | |
24 | </div> |
|
35 | </div> | |
25 | <span class="pagination"><%= pagination_links_full @group_pages, @group_count %></span> |
|
36 | <span class="pagination"><%= pagination_links_full @group_pages, @group_count %></span> | |
26 | <% else %> |
|
37 | <% else %> | |
27 | <p class="nodata"><%= l(:label_no_data) %></p> |
|
38 | <p class="nodata"><%= l(:label_no_data) %></p> | |
28 | <% end %> |
|
39 | <% end %> |
@@ -1,159 +1,168 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2016 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2016 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | require File.expand_path('../../test_helper', __FILE__) |
|
18 | require File.expand_path('../../test_helper', __FILE__) | |
19 |
|
19 | |||
20 | class GroupsControllerTest < Redmine::ControllerTest |
|
20 | class GroupsControllerTest < Redmine::ControllerTest | |
21 | fixtures :projects, :users, :members, :member_roles, :roles, :groups_users |
|
21 | fixtures :projects, :users, :members, :member_roles, :roles, :groups_users | |
22 |
|
22 | |||
23 | def setup |
|
23 | def setup | |
24 | @request.session[:user_id] = 1 |
|
24 | @request.session[:user_id] = 1 | |
25 | end |
|
25 | end | |
26 |
|
26 | |||
27 | def test_index |
|
27 | def test_index | |
28 | get :index |
|
28 | get :index | |
29 | assert_response :success |
|
29 | assert_response :success | |
30 | assert_select 'table.groups' |
|
30 | assert_select 'table.groups' | |
31 | end |
|
31 | end | |
32 |
|
32 | |||
33 | def test_index_should_show_user_count |
|
33 | def test_index_should_show_user_count | |
34 | get :index |
|
34 | get :index | |
35 | assert_response :success |
|
35 | assert_response :success | |
36 | assert_select 'tr#group-11 td.user_count', :text => '1' |
|
36 | assert_select 'tr#group-11 td.user_count', :text => '1' | |
37 | end |
|
37 | end | |
38 |
|
38 | |||
|
39 | def test_index_with_name_filter | |||
|
40 | Group.generate!(:name => "Clients") | |||
|
41 | ||||
|
42 | get :index, :name => "cli" | |||
|
43 | assert_response :success | |||
|
44 | assert_select 'table.groups tbody tr', 1 | |||
|
45 | assert_select 'table.groups tbody td.name', :text => 'Clients' | |||
|
46 | end | |||
|
47 | ||||
39 | def test_show |
|
48 | def test_show | |
40 | get :show, :id => 10 |
|
49 | get :show, :id => 10 | |
41 | assert_response :success |
|
50 | assert_response :success | |
42 | end |
|
51 | end | |
43 |
|
52 | |||
44 | def test_show_invalid_should_return_404 |
|
53 | def test_show_invalid_should_return_404 | |
45 | get :show, :id => 99 |
|
54 | get :show, :id => 99 | |
46 | assert_response 404 |
|
55 | assert_response 404 | |
47 | end |
|
56 | end | |
48 |
|
57 | |||
49 | def test_new |
|
58 | def test_new | |
50 | get :new |
|
59 | get :new | |
51 | assert_response :success |
|
60 | assert_response :success | |
52 | assert_select 'input[name=?]', 'group[name]' |
|
61 | assert_select 'input[name=?]', 'group[name]' | |
53 | end |
|
62 | end | |
54 |
|
63 | |||
55 | def test_create |
|
64 | def test_create | |
56 | assert_difference 'Group.count' do |
|
65 | assert_difference 'Group.count' do | |
57 | post :create, :group => {:name => 'New group'} |
|
66 | post :create, :group => {:name => 'New group'} | |
58 | end |
|
67 | end | |
59 | assert_redirected_to '/groups' |
|
68 | assert_redirected_to '/groups' | |
60 | group = Group.order('id DESC').first |
|
69 | group = Group.order('id DESC').first | |
61 | assert_equal 'New group', group.name |
|
70 | assert_equal 'New group', group.name | |
62 | assert_equal [], group.users |
|
71 | assert_equal [], group.users | |
63 | end |
|
72 | end | |
64 |
|
73 | |||
65 | def test_create_and_continue |
|
74 | def test_create_and_continue | |
66 | assert_difference 'Group.count' do |
|
75 | assert_difference 'Group.count' do | |
67 | post :create, :group => {:name => 'New group'}, :continue => 'Create and continue' |
|
76 | post :create, :group => {:name => 'New group'}, :continue => 'Create and continue' | |
68 | end |
|
77 | end | |
69 | assert_redirected_to '/groups/new' |
|
78 | assert_redirected_to '/groups/new' | |
70 | group = Group.order('id DESC').first |
|
79 | group = Group.order('id DESC').first | |
71 | assert_equal 'New group', group.name |
|
80 | assert_equal 'New group', group.name | |
72 | end |
|
81 | end | |
73 |
|
82 | |||
74 | def test_create_with_failure |
|
83 | def test_create_with_failure | |
75 | assert_no_difference 'Group.count' do |
|
84 | assert_no_difference 'Group.count' do | |
76 | post :create, :group => {:name => ''} |
|
85 | post :create, :group => {:name => ''} | |
77 | end |
|
86 | end | |
78 | assert_response :success |
|
87 | assert_response :success | |
79 | assert_select_error /Name cannot be blank/i |
|
88 | assert_select_error /Name cannot be blank/i | |
80 | end |
|
89 | end | |
81 |
|
90 | |||
82 | def test_edit |
|
91 | def test_edit | |
83 | get :edit, :id => 10 |
|
92 | get :edit, :id => 10 | |
84 | assert_response :success |
|
93 | assert_response :success | |
85 |
|
94 | |||
86 | assert_select 'div#tab-content-users' |
|
95 | assert_select 'div#tab-content-users' | |
87 | assert_select 'div#tab-content-memberships' do |
|
96 | assert_select 'div#tab-content-memberships' do | |
88 | assert_select 'a', :text => 'Private child of eCookbook' |
|
97 | assert_select 'a', :text => 'Private child of eCookbook' | |
89 | end |
|
98 | end | |
90 | end |
|
99 | end | |
91 |
|
100 | |||
92 | def test_update |
|
101 | def test_update | |
93 | new_name = 'New name' |
|
102 | new_name = 'New name' | |
94 | put :update, :id => 10, :group => {:name => new_name} |
|
103 | put :update, :id => 10, :group => {:name => new_name} | |
95 | assert_redirected_to '/groups' |
|
104 | assert_redirected_to '/groups' | |
96 | group = Group.find(10) |
|
105 | group = Group.find(10) | |
97 | assert_equal new_name, group.name |
|
106 | assert_equal new_name, group.name | |
98 | end |
|
107 | end | |
99 |
|
108 | |||
100 | def test_update_with_failure |
|
109 | def test_update_with_failure | |
101 | put :update, :id => 10, :group => {:name => ''} |
|
110 | put :update, :id => 10, :group => {:name => ''} | |
102 | assert_response :success |
|
111 | assert_response :success | |
103 | assert_select_error /Name cannot be blank/i |
|
112 | assert_select_error /Name cannot be blank/i | |
104 | end |
|
113 | end | |
105 |
|
114 | |||
106 | def test_destroy |
|
115 | def test_destroy | |
107 | assert_difference 'Group.count', -1 do |
|
116 | assert_difference 'Group.count', -1 do | |
108 | post :destroy, :id => 10 |
|
117 | post :destroy, :id => 10 | |
109 | end |
|
118 | end | |
110 | assert_redirected_to '/groups' |
|
119 | assert_redirected_to '/groups' | |
111 | end |
|
120 | end | |
112 |
|
121 | |||
113 | def test_new_users |
|
122 | def test_new_users | |
114 | get :new_users, :id => 10 |
|
123 | get :new_users, :id => 10 | |
115 | assert_response :success |
|
124 | assert_response :success | |
116 | assert_select 'input[name=?]', 'user_search' |
|
125 | assert_select 'input[name=?]', 'user_search' | |
117 | end |
|
126 | end | |
118 |
|
127 | |||
119 | def test_xhr_new_users |
|
128 | def test_xhr_new_users | |
120 | xhr :get, :new_users, :id => 10 |
|
129 | xhr :get, :new_users, :id => 10 | |
121 | assert_response :success |
|
130 | assert_response :success | |
122 | assert_equal 'text/javascript', response.content_type |
|
131 | assert_equal 'text/javascript', response.content_type | |
123 | end |
|
132 | end | |
124 |
|
133 | |||
125 | def test_add_users |
|
134 | def test_add_users | |
126 | assert_difference 'Group.find(10).users.count', 2 do |
|
135 | assert_difference 'Group.find(10).users.count', 2 do | |
127 | post :add_users, :id => 10, :user_ids => ['2', '3'] |
|
136 | post :add_users, :id => 10, :user_ids => ['2', '3'] | |
128 | end |
|
137 | end | |
129 | end |
|
138 | end | |
130 |
|
139 | |||
131 | def test_xhr_add_users |
|
140 | def test_xhr_add_users | |
132 | assert_difference 'Group.find(10).users.count', 2 do |
|
141 | assert_difference 'Group.find(10).users.count', 2 do | |
133 | xhr :post, :add_users, :id => 10, :user_ids => ['2', '3'] |
|
142 | xhr :post, :add_users, :id => 10, :user_ids => ['2', '3'] | |
134 | assert_response :success |
|
143 | assert_response :success | |
135 | assert_equal 'text/javascript', response.content_type |
|
144 | assert_equal 'text/javascript', response.content_type | |
136 | end |
|
145 | end | |
137 | assert_match /John Smith/, response.body |
|
146 | assert_match /John Smith/, response.body | |
138 | end |
|
147 | end | |
139 |
|
148 | |||
140 | def test_remove_user |
|
149 | def test_remove_user | |
141 | assert_difference 'Group.find(10).users.count', -1 do |
|
150 | assert_difference 'Group.find(10).users.count', -1 do | |
142 | delete :remove_user, :id => 10, :user_id => '8' |
|
151 | delete :remove_user, :id => 10, :user_id => '8' | |
143 | end |
|
152 | end | |
144 | end |
|
153 | end | |
145 |
|
154 | |||
146 | def test_xhr_remove_user |
|
155 | def test_xhr_remove_user | |
147 | assert_difference 'Group.find(10).users.count', -1 do |
|
156 | assert_difference 'Group.find(10).users.count', -1 do | |
148 | xhr :delete, :remove_user, :id => 10, :user_id => '8' |
|
157 | xhr :delete, :remove_user, :id => 10, :user_id => '8' | |
149 | assert_response :success |
|
158 | assert_response :success | |
150 | assert_equal 'text/javascript', response.content_type |
|
159 | assert_equal 'text/javascript', response.content_type | |
151 | end |
|
160 | end | |
152 | end |
|
161 | end | |
153 |
|
162 | |||
154 | def test_autocomplete_for_user |
|
163 | def test_autocomplete_for_user | |
155 | xhr :get, :autocomplete_for_user, :id => 10, :q => 'smi', :format => 'js' |
|
164 | xhr :get, :autocomplete_for_user, :id => 10, :q => 'smi', :format => 'js' | |
156 | assert_response :success |
|
165 | assert_response :success | |
157 | assert_include 'John Smith', response.body |
|
166 | assert_include 'John Smith', response.body | |
158 | end |
|
167 | end | |
159 | end |
|
168 | end |
General Comments 0
You need to be logged in to leave comments.
Login now