@@ -1,90 +1,90 | |||
|
1 | # Redmine - project management software | |
|
2 | # Copyright (C) 2006-2011 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 AuthSourcesControllerTest < ActionController::TestCase | |
|
21 | fixtures :users | |
|
22 | ||
|
23 | def setup | |
|
24 | @request.session[:user_id] = 1 | |
|
25 | end | |
|
26 | ||
|
27 | def test_index | |
|
28 | get :index | |
|
29 | ||
|
30 | assert_response :success | |
|
31 | assert_template 'index' | |
|
32 | assert_not_nil assigns(:auth_sources) | |
|
33 | end | |
|
34 | ||
|
35 | def test_new | |
|
36 | get :new | |
|
37 | ||
|
38 | assert_response :success | |
|
39 | assert_template 'new' | |
|
40 | assert_kind_of AuthSource, assigns(:auth_source) | |
|
41 | assert assigns(:auth_source).new_record? | |
|
42 | end | |
|
43 | ||
|
44 | def test_create | |
|
45 | assert_difference 'AuthSource.count' do | |
|
46 | post :create, :auth_source => {:name => 'Test'} | |
|
47 | end | |
|
48 | ||
|
49 | assert_redirected_to '/auth_sources' | |
|
50 | auth_source = AuthSource.first(:order => 'id DESC') | |
|
51 | assert_equal 'Test', auth_source.name | |
|
52 | end | |
|
53 | ||
|
54 | def test_edit | |
|
55 | auth_source = AuthSource.generate!(:name => 'TestEdit') | |
|
56 | get :edit, :id => auth_source.id | |
|
57 | ||
|
58 | assert_response :success | |
|
59 | assert_template 'edit' | |
|
60 | assert_equal auth_source, assigns(:auth_source) | |
|
61 | end | |
|
62 | ||
|
63 | def test_update | |
|
64 | auth_source = AuthSource.generate!(:name => 'TestEdit') | |
|
65 | post :update, :id => auth_source.id, :auth_source => {:name => 'TestUpdate'} | |
|
66 | ||
|
67 | assert_redirected_to '/auth_sources' | |
|
68 | assert_equal 'TestUpdate', auth_source.reload.name | |
|
69 | end | |
|
70 | ||
|
71 | def test_destroy_without_users | |
|
72 | auth_source = AuthSource.generate!(:name => 'TestEdit') | |
|
73 | assert_difference 'AuthSource.count', -1 do | |
|
74 | post :destroy, :id => auth_source.id | |
|
75 | end | |
|
76 | ||
|
77 | assert_redirected_to '/auth_sources' | |
|
78 | end | |
|
79 | ||
|
80 | def test_destroy_with_users | |
|
81 | auth_source = AuthSource.generate!(:name => 'TestEdit') | |
|
82 | User.generate!(:auth_source => auth_source) | |
|
83 | assert_no_difference 'AuthSource.count' do | |
|
84 | post :destroy, :id => auth_source.id | |
|
85 | end | |
|
86 | ||
|
87 | assert_redirected_to '/auth_sources' | |
|
88 | assert AuthSource.find(auth_source.id) | |
|
89 | end | |
|
90 | end | |
|
1 | # Redmine - project management software | |
|
2 | # Copyright (C) 2006-2011 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 AuthSourcesControllerTest < ActionController::TestCase | |
|
21 | fixtures :users | |
|
22 | ||
|
23 | def setup | |
|
24 | @request.session[:user_id] = 1 | |
|
25 | end | |
|
26 | ||
|
27 | def test_index | |
|
28 | get :index | |
|
29 | ||
|
30 | assert_response :success | |
|
31 | assert_template 'index' | |
|
32 | assert_not_nil assigns(:auth_sources) | |
|
33 | end | |
|
34 | ||
|
35 | def test_new | |
|
36 | get :new | |
|
37 | ||
|
38 | assert_response :success | |
|
39 | assert_template 'new' | |
|
40 | assert_kind_of AuthSource, assigns(:auth_source) | |
|
41 | assert assigns(:auth_source).new_record? | |
|
42 | end | |
|
43 | ||
|
44 | def test_create | |
|
45 | assert_difference 'AuthSource.count' do | |
|
46 | post :create, :auth_source => {:name => 'Test'} | |
|
47 | end | |
|
48 | ||
|
49 | assert_redirected_to '/auth_sources' | |
|
50 | auth_source = AuthSource.first(:order => 'id DESC') | |
|
51 | assert_equal 'Test', auth_source.name | |
|
52 | end | |
|
53 | ||
|
54 | def test_edit | |
|
55 | auth_source = AuthSource.generate!(:name => 'TestEdit') | |
|
56 | get :edit, :id => auth_source.id | |
|
57 | ||
|
58 | assert_response :success | |
|
59 | assert_template 'edit' | |
|
60 | assert_equal auth_source, assigns(:auth_source) | |
|
61 | end | |
|
62 | ||
|
63 | def test_update | |
|
64 | auth_source = AuthSource.generate!(:name => 'TestEdit') | |
|
65 | post :update, :id => auth_source.id, :auth_source => {:name => 'TestUpdate'} | |
|
66 | ||
|
67 | assert_redirected_to '/auth_sources' | |
|
68 | assert_equal 'TestUpdate', auth_source.reload.name | |
|
69 | end | |
|
70 | ||
|
71 | def test_destroy_without_users | |
|
72 | auth_source = AuthSource.generate!(:name => 'TestEdit') | |
|
73 | assert_difference 'AuthSource.count', -1 do | |
|
74 | post :destroy, :id => auth_source.id | |
|
75 | end | |
|
76 | ||
|
77 | assert_redirected_to '/auth_sources' | |
|
78 | end | |
|
79 | ||
|
80 | def test_destroy_with_users | |
|
81 | auth_source = AuthSource.generate!(:name => 'TestEdit') | |
|
82 | User.generate!(:auth_source => auth_source) | |
|
83 | assert_no_difference 'AuthSource.count' do | |
|
84 | post :destroy, :id => auth_source.id | |
|
85 | end | |
|
86 | ||
|
87 | assert_redirected_to '/auth_sources' | |
|
88 | assert AuthSource.find(auth_source.id) | |
|
89 | end | |
|
90 | end |
General Comments 0
You need to be logged in to leave comments.
Login now