comparison .svn/pristine/8d/8d49dae3dcbe3c33e8ba68468bf87f82d0d0b226.svn-base @ 1298:4f746d8966dd redmine_2.3_integration

Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author Chris Cannam
date Fri, 14 Jun 2013 09:28:30 +0100
parents 622f24f53b42
children
comparison
equal deleted inserted replaced
1297:0a574315af3e 1298:4f746d8966dd
1 # Redmine - project management software
2 # Copyright (C) 2006-2013 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 MembersControllerTest < ActionController::TestCase
21 fixtures :projects, :members, :member_roles, :roles, :users
22
23 def setup
24 User.current = nil
25 @request.session[:user_id] = 2
26 end
27
28 def test_create
29 assert_difference 'Member.count' do
30 post :create, :project_id => 1, :membership => {:role_ids => [1], :user_id => 7}
31 end
32 assert_redirected_to '/projects/ecookbook/settings/members'
33 assert User.find(7).member_of?(Project.find(1))
34 end
35
36 def test_create_multiple
37 assert_difference 'Member.count', 3 do
38 post :create, :project_id => 1, :membership => {:role_ids => [1], :user_ids => [7, 8, 9]}
39 end
40 assert_redirected_to '/projects/ecookbook/settings/members'
41 assert User.find(7).member_of?(Project.find(1))
42 end
43
44 def test_xhr_create
45 assert_difference 'Member.count', 3 do
46 xhr :post, :create, :project_id => 1, :membership => {:role_ids => [1], :user_ids => [7, 8, 9]}
47 assert_response :success
48 assert_template 'create'
49 assert_equal 'text/javascript', response.content_type
50 end
51 assert User.find(7).member_of?(Project.find(1))
52 assert User.find(8).member_of?(Project.find(1))
53 assert User.find(9).member_of?(Project.find(1))
54 assert_include 'tab-content-members', response.body
55 end
56
57 def test_xhr_create_with_failure
58 assert_no_difference 'Member.count' do
59 xhr :post, :create, :project_id => 1, :membership => {:role_ids => [], :user_ids => [7, 8, 9]}
60 assert_response :success
61 assert_template 'create'
62 assert_equal 'text/javascript', response.content_type
63 end
64 assert_match /alert/, response.body, "Alert message not sent"
65 end
66
67 def test_edit
68 assert_no_difference 'Member.count' do
69 put :update, :id => 2, :membership => {:role_ids => [1], :user_id => 3}
70 end
71 assert_redirected_to '/projects/ecookbook/settings/members'
72 end
73
74 def test_xhr_edit
75 assert_no_difference 'Member.count' do
76 xhr :put, :update, :id => 2, :membership => {:role_ids => [1], :user_id => 3}
77 assert_response :success
78 assert_template 'update'
79 assert_equal 'text/javascript', response.content_type
80 end
81 member = Member.find(2)
82 assert_equal [1], member.role_ids
83 assert_equal 3, member.user_id
84 assert_include 'tab-content-members', response.body
85 end
86
87 def test_destroy
88 assert_difference 'Member.count', -1 do
89 delete :destroy, :id => 2
90 end
91 assert_redirected_to '/projects/ecookbook/settings/members'
92 assert !User.find(3).member_of?(Project.find(1))
93 end
94
95 def test_xhr_destroy
96 assert_difference 'Member.count', -1 do
97 xhr :delete, :destroy, :id => 2
98 assert_response :success
99 assert_template 'destroy'
100 assert_equal 'text/javascript', response.content_type
101 end
102 assert_nil Member.find_by_id(2)
103 assert_include 'tab-content-members', response.body
104 end
105
106 def test_autocomplete
107 get :autocomplete, :project_id => 1, :q => 'mis', :format => 'js'
108 assert_response :success
109 assert_include 'User Misc', response.body
110 end
111 end