##// END OF EJS Templates
Adds some helpers tests....
Jean-Philippe Lang -
r13353:d4ebbe5ba8c8
parent child
Show More
@@ -0,0 +1,42
1 # Redmine - project management software
2 # Copyright (C) 2006-2014 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
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
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 require File.expand_path('../../../test_helper', __FILE__)
19
20 class GroupsHelperTest < ActionView::TestCase
21 include Redmine::I18n
22 include ERB::Util
23 include GroupsHelper
24
25 fixtures :users
26
27 def test_render_principals_for_new_group_users
28 group = Group.generate!
29
30 result = render_principals_for_new_group_users(group)
31 assert_select_in result, 'input[name=?][value=2]', 'user_ids[]'
32 end
33
34 def test_render_principals_for_new_group_users_with_limited_results_should_paginate
35 group = Group.generate!
36
37 result = render_principals_for_new_group_users(group, 3)
38 assert_select_in result, 'p.pagination'
39 assert_select_in result, 'span.current.page', :text => '1'
40 assert_select_in result, 'a[href=?]', "/groups/#{group.id}/autocomplete_for_user.js?page=2", :text => '2'
41 end
42 end
@@ -0,0 +1,42
1 # Redmine - project management software
2 # Copyright (C) 2006-2014 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
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
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 require File.expand_path('../../../test_helper', __FILE__)
19
20 class MembersHelperTest < ActionView::TestCase
21 include Redmine::I18n
22 include ERB::Util
23 include MembersHelper
24
25 fixtures :projects, :users, :members, :member_roles
26
27 def test_render_principals_for_new_members
28 project = Project.generate!
29
30 result = render_principals_for_new_members(project)
31 assert_select_in result, 'input[name=?][value=2]', 'membership[user_ids][]'
32 end
33
34 def test_render_principals_for_new_members_with_limited_results_should_paginate
35 project = Project.generate!
36
37 result = render_principals_for_new_members(project, 3)
38 assert_select_in result, 'p.pagination'
39 assert_select_in result, 'span.current.page', :text => '1'
40 assert_select_in result, 'a[href=?]', "/projects/#{project.identifier}/memberships/autocomplete.js?page=2", :text => '2'
41 end
42 end
@@ -1,46 +1,46
1 1 # encoding: utf-8
2 2 #
3 3 # Redmine - project management software
4 4 # Copyright (C) 2006-2014 Jean-Philippe Lang
5 5 #
6 6 # This program is free software; you can redistribute it and/or
7 7 # modify it under the terms of the GNU General Public License
8 8 # as published by the Free Software Foundation; either version 2
9 9 # of the License, or (at your option) any later version.
10 10 #
11 11 # This program is distributed in the hope that it will be useful,
12 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 14 # GNU General Public License for more details.
15 15 #
16 16 # You should have received a copy of the GNU General Public License
17 17 # along with this program; if not, write to the Free Software
18 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 19
20 20 module GroupsHelper
21 21 def group_settings_tabs(group)
22 22 tabs = []
23 23 tabs << {:name => 'general', :partial => 'groups/general', :label => :label_general}
24 24 tabs << {:name => 'users', :partial => 'groups/users', :label => :label_user_plural} if group.givable?
25 25 tabs << {:name => 'memberships', :partial => 'groups/memberships', :label => :label_project_plural}
26 26 tabs
27 27 end
28 28
29 def render_principals_for_new_group_users(group)
29 def render_principals_for_new_group_users(group, limit=100)
30 30 scope = User.active.sorted.not_in_group(group).like(params[:q])
31 31 principal_count = scope.count
32 principal_pages = Redmine::Pagination::Paginator.new principal_count, 100, params['page']
32 principal_pages = Redmine::Pagination::Paginator.new principal_count, limit, params['page']
33 33 principals = scope.offset(principal_pages.offset).limit(principal_pages.per_page).to_a
34 34
35 35 s = content_tag('div',
36 36 content_tag('div', principals_check_box_tags('user_ids[]', principals), :id => 'principals'),
37 37 :class => 'objects-selection'
38 38 )
39 39
40 40 links = pagination_links_full(principal_pages, principal_count, :per_page_links => false) {|text, parameters, options|
41 41 link_to text, autocomplete_for_user_group_path(group, parameters.merge(:q => params[:q], :format => 'js')), :remote => true
42 42 }
43 43
44 44 s + content_tag('p', links, :class => 'pagination')
45 45 end
46 46 end
@@ -1,38 +1,38
1 1 # encoding: utf-8
2 2 #
3 3 # Redmine - project management software
4 4 # Copyright (C) 2006-2014 Jean-Philippe Lang
5 5 #
6 6 # This program is free software; you can redistribute it and/or
7 7 # modify it under the terms of the GNU General Public License
8 8 # as published by the Free Software Foundation; either version 2
9 9 # of the License, or (at your option) any later version.
10 10 #
11 11 # This program is distributed in the hope that it will be useful,
12 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 14 # GNU General Public License for more details.
15 15 #
16 16 # You should have received a copy of the GNU General Public License
17 17 # along with this program; if not, write to the Free Software
18 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 19
20 20 module MembersHelper
21 def render_principals_for_new_members(project)
21 def render_principals_for_new_members(project, limit=100)
22 22 scope = Principal.active.visible.sorted.not_member_of(project).like(params[:q])
23 23 principal_count = scope.count
24 principal_pages = Redmine::Pagination::Paginator.new principal_count, 100, params['page']
24 principal_pages = Redmine::Pagination::Paginator.new principal_count, limit, params['page']
25 25 principals = scope.offset(principal_pages.offset).limit(principal_pages.per_page).to_a
26 26
27 27 s = content_tag('div',
28 28 content_tag('div', principals_check_box_tags('membership[user_ids][]', principals), :id => 'principals'),
29 29 :class => 'objects-selection'
30 30 )
31 31
32 32 links = pagination_links_full(principal_pages, principal_count, :per_page_links => false) {|text, parameters, options|
33 33 link_to text, autocomplete_project_memberships_path(project, parameters.merge(:q => params[:q], :format => 'js')), :remote => true
34 34 }
35 35
36 36 s + content_tag('p', links, :class => 'pagination')
37 37 end
38 38 end
General Comments 0
You need to be logged in to leave comments. Login now