Chris@0
|
1 # Redmine - project management software
|
Chris@909
|
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
|
Chris@0
|
3 #
|
Chris@0
|
4 # This program is free software; you can redistribute it and/or
|
Chris@0
|
5 # modify it under the terms of the GNU General Public License
|
Chris@0
|
6 # as published by the Free Software Foundation; either version 2
|
Chris@0
|
7 # of the License, or (at your option) any later version.
|
Chris@909
|
8 #
|
Chris@0
|
9 # This program is distributed in the hope that it will be useful,
|
Chris@0
|
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@0
|
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@0
|
12 # GNU General Public License for more details.
|
Chris@909
|
13 #
|
Chris@0
|
14 # You should have received a copy of the GNU General Public License
|
Chris@0
|
15 # along with this program; if not, write to the Free Software
|
Chris@0
|
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Chris@0
|
17
|
Chris@119
|
18 require File.expand_path('../../test_helper', __FILE__)
|
Chris@0
|
19 require 'members_controller'
|
Chris@0
|
20
|
Chris@0
|
21 # Re-raise errors caught by the controller.
|
Chris@0
|
22 class MembersController; def rescue_action(e) raise e end; end
|
Chris@0
|
23
|
Chris@0
|
24
|
Chris@0
|
25 class MembersControllerTest < ActionController::TestCase
|
Chris@0
|
26 fixtures :projects, :members, :member_roles, :roles, :users
|
Chris@909
|
27
|
Chris@0
|
28 def setup
|
Chris@0
|
29 @controller = MembersController.new
|
Chris@0
|
30 @request = ActionController::TestRequest.new
|
Chris@0
|
31 @response = ActionController::TestResponse.new
|
Chris@0
|
32 User.current = nil
|
Chris@0
|
33 @request.session[:user_id] = 2
|
Chris@0
|
34 end
|
Chris@909
|
35
|
Chris@0
|
36 def test_create
|
Chris@0
|
37 assert_difference 'Member.count' do
|
Chris@0
|
38 post :new, :id => 1, :member => {:role_ids => [1], :user_id => 7}
|
Chris@0
|
39 end
|
Chris@0
|
40 assert_redirected_to '/projects/ecookbook/settings/members'
|
Chris@0
|
41 assert User.find(7).member_of?(Project.find(1))
|
Chris@0
|
42 end
|
Chris@909
|
43
|
Chris@0
|
44 def test_create_multiple
|
Chris@0
|
45 assert_difference 'Member.count', 3 do
|
Chris@0
|
46 post :new, :id => 1, :member => {:role_ids => [1], :user_ids => [7, 8, 9]}
|
Chris@0
|
47 end
|
Chris@0
|
48 assert_redirected_to '/projects/ecookbook/settings/members'
|
Chris@0
|
49 assert User.find(7).member_of?(Project.find(1))
|
Chris@0
|
50 end
|
Chris@0
|
51
|
Chris@909
|
52 def test_xhr_create
|
Chris@909
|
53 assert_difference 'Member.count', 3 do
|
Chris@909
|
54 post :new, :format => "js", :id => 1, :member => {:role_ids => [1], :user_ids => [7, 8, 9]}
|
Chris@909
|
55 end
|
Chris@909
|
56 assert_select_rjs :replace_html, 'tab-content-members'
|
Chris@909
|
57 assert User.find(7).member_of?(Project.find(1))
|
Chris@909
|
58 assert User.find(8).member_of?(Project.find(1))
|
Chris@909
|
59 assert User.find(9).member_of?(Project.find(1))
|
Chris@909
|
60 end
|
Chris@0
|
61
|
Chris@909
|
62 def test_xhr_create_with_failure
|
Chris@909
|
63 assert_no_difference 'Member.count' do
|
Chris@909
|
64 post :new, :format => "js", :id => 1, :member => {:role_ids => [], :user_ids => [7, 8, 9]}
|
Chris@909
|
65 end
|
Chris@909
|
66 assert_select '#tab-content-members', 0
|
Chris@909
|
67 assert @response.body.match(/alert/i), "Alert message not sent"
|
Chris@909
|
68 end
|
Chris@0
|
69
|
Chris@0
|
70 def test_edit
|
Chris@0
|
71 assert_no_difference 'Member.count' do
|
Chris@0
|
72 post :edit, :id => 2, :member => {:role_ids => [1], :user_id => 3}
|
Chris@0
|
73 end
|
Chris@0
|
74 assert_redirected_to '/projects/ecookbook/settings/members'
|
Chris@0
|
75 end
|
Chris@909
|
76
|
Chris@909
|
77 def test_xhr_edit
|
Chris@909
|
78 assert_no_difference 'Member.count' do
|
Chris@909
|
79 xhr :post, :edit, :id => 2, :member => {:role_ids => [1], :user_id => 3}
|
Chris@909
|
80 end
|
Chris@909
|
81 assert_select_rjs :replace_html, 'tab-content-members'
|
Chris@909
|
82 member = Member.find(2)
|
Chris@909
|
83 assert_equal [1], member.role_ids
|
Chris@909
|
84 assert_equal 3, member.user_id
|
Chris@909
|
85 end
|
Chris@909
|
86
|
Chris@0
|
87 def test_destroy
|
Chris@0
|
88 assert_difference 'Member.count', -1 do
|
Chris@0
|
89 post :destroy, :id => 2
|
Chris@0
|
90 end
|
Chris@0
|
91 assert_redirected_to '/projects/ecookbook/settings/members'
|
Chris@0
|
92 assert !User.find(3).member_of?(Project.find(1))
|
Chris@0
|
93 end
|
Chris@909
|
94
|
Chris@909
|
95 def test_xhr_destroy
|
Chris@909
|
96 assert_difference 'Member.count', -1 do
|
Chris@909
|
97 xhr :post, :destroy, :id => 2
|
Chris@909
|
98 end
|
Chris@909
|
99 assert_select_rjs :replace_html, 'tab-content-members'
|
Chris@909
|
100 end
|
Chris@909
|
101
|
Chris@0
|
102 def test_autocomplete_for_member
|
Chris@0
|
103 get :autocomplete_for_member, :id => 1, :q => 'mis'
|
Chris@0
|
104 assert_response :success
|
Chris@0
|
105 assert_template 'autocomplete_for_member'
|
Chris@909
|
106
|
Chris@0
|
107 assert_tag :label, :content => /User Misc/,
|
Chris@0
|
108 :child => { :tag => 'input', :attributes => { :name => 'member[user_ids][]', :value => '8' } }
|
Chris@0
|
109 end
|
Chris@0
|
110 end
|