Mercurial > hg > soundsoftware-site
comparison .svn/pristine/98/98c30219e38bafbc07625c852133d782b2016988.svn-base @ 1296:038ba2d95de8 redmine-2.2
Fix redmine-2.2 branch update (add missing svn files)
author | Chris Cannam |
---|---|
date | Fri, 14 Jun 2013 09:05:06 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1294:3e4c3460b6ca | 1296:038ba2d95de8 |
---|---|
1 # Redmine - project management software | |
2 # Copyright (C) 2006-2012 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, :auth_sources | |
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 | |
41 source = assigns(:auth_source) | |
42 assert_equal AuthSourceLdap, source.class | |
43 assert source.new_record? | |
44 | |
45 assert_tag 'input', :attributes => {:name => 'type', :value => 'AuthSourceLdap'} | |
46 assert_tag 'input', :attributes => {:name => 'auth_source[host]'} | |
47 end | |
48 | |
49 def test_create | |
50 assert_difference 'AuthSourceLdap.count' do | |
51 post :create, :type => 'AuthSourceLdap', :auth_source => {:name => 'Test', :host => '127.0.0.1', :port => '389', :attr_login => 'cn'} | |
52 assert_redirected_to '/auth_sources' | |
53 end | |
54 | |
55 source = AuthSourceLdap.first(:order => 'id DESC') | |
56 assert_equal 'Test', source.name | |
57 assert_equal '127.0.0.1', source.host | |
58 assert_equal 389, source.port | |
59 assert_equal 'cn', source.attr_login | |
60 end | |
61 | |
62 def test_create_with_failure | |
63 assert_no_difference 'AuthSourceLdap.count' do | |
64 post :create, :type => 'AuthSourceLdap', :auth_source => {:name => 'Test', :host => '', :port => '389', :attr_login => 'cn'} | |
65 assert_response :success | |
66 assert_template 'new' | |
67 end | |
68 assert_error_tag :content => /host can't be blank/i | |
69 end | |
70 | |
71 def test_edit | |
72 get :edit, :id => 1 | |
73 | |
74 assert_response :success | |
75 assert_template 'edit' | |
76 | |
77 assert_tag 'input', :attributes => {:name => 'auth_source[host]'} | |
78 end | |
79 | |
80 def test_update | |
81 put :update, :id => 1, :auth_source => {:name => 'Renamed', :host => '192.168.0.10', :port => '389', :attr_login => 'uid'} | |
82 assert_redirected_to '/auth_sources' | |
83 | |
84 source = AuthSourceLdap.find(1) | |
85 assert_equal 'Renamed', source.name | |
86 assert_equal '192.168.0.10', source.host | |
87 end | |
88 | |
89 def test_update_with_failure | |
90 put :update, :id => 1, :auth_source => {:name => 'Renamed', :host => '', :port => '389', :attr_login => 'uid'} | |
91 assert_response :success | |
92 assert_template 'edit' | |
93 assert_error_tag :content => /host can't be blank/i | |
94 end | |
95 | |
96 def test_destroy | |
97 assert_difference 'AuthSourceLdap.count', -1 do | |
98 delete :destroy, :id => 1 | |
99 end | |
100 end | |
101 | |
102 def test_destroy_auth_source_in_use | |
103 User.find(2).update_attribute :auth_source_id, 1 | |
104 | |
105 assert_no_difference 'AuthSourceLdap.count' do | |
106 delete :destroy, :id => 1 | |
107 end | |
108 end | |
109 | |
110 def test_test_connection | |
111 AuthSourceLdap.any_instance.stubs(:test_connection).returns(true) | |
112 | |
113 get :test_connection, :id => 1 | |
114 assert_redirected_to '/auth_sources' | |
115 assert_not_nil flash[:notice] | |
116 assert_match /successful/i, flash[:notice] | |
117 end | |
118 | |
119 def test_test_connection_with_failure | |
120 AuthSourceLdap.any_instance.stubs(:initialize_ldap_con).raises(Net::LDAP::LdapError.new("Something went wrong")) | |
121 | |
122 get :test_connection, :id => 1 | |
123 assert_redirected_to '/auth_sources' | |
124 assert_not_nil flash[:error] | |
125 assert_include 'Something went wrong', flash[:error] | |
126 end | |
127 end |