Mercurial > hg > soundsoftware-site
comparison .svn/pristine/db/dbc74bfb5d695fe0fd5ec63c1a42442c480292e2.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 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_select 'form#auth_source_form' do | |
46 assert_select 'input[name=type][value=AuthSourceLdap]' | |
47 assert_select 'input[name=?]', 'auth_source[host]' | |
48 end | |
49 end | |
50 | |
51 def test_new_with_invalid_type_should_respond_with_404 | |
52 get :new, :type => 'foo' | |
53 assert_response 404 | |
54 end | |
55 | |
56 def test_create | |
57 assert_difference 'AuthSourceLdap.count' do | |
58 post :create, :type => 'AuthSourceLdap', :auth_source => {:name => 'Test', :host => '127.0.0.1', :port => '389', :attr_login => 'cn'} | |
59 assert_redirected_to '/auth_sources' | |
60 end | |
61 | |
62 source = AuthSourceLdap.order('id DESC').first | |
63 assert_equal 'Test', source.name | |
64 assert_equal '127.0.0.1', source.host | |
65 assert_equal 389, source.port | |
66 assert_equal 'cn', source.attr_login | |
67 end | |
68 | |
69 def test_create_with_failure | |
70 assert_no_difference 'AuthSourceLdap.count' do | |
71 post :create, :type => 'AuthSourceLdap', :auth_source => {:name => 'Test', :host => '', :port => '389', :attr_login => 'cn'} | |
72 assert_response :success | |
73 assert_template 'new' | |
74 end | |
75 assert_error_tag :content => /host can't be blank/i | |
76 end | |
77 | |
78 def test_edit | |
79 get :edit, :id => 1 | |
80 | |
81 assert_response :success | |
82 assert_template 'edit' | |
83 | |
84 assert_select 'form#auth_source_form' do | |
85 assert_select 'input[name=?]', 'auth_source[host]' | |
86 end | |
87 end | |
88 | |
89 def test_edit_should_not_contain_password | |
90 AuthSource.find(1).update_column :account_password, 'secret' | |
91 | |
92 get :edit, :id => 1 | |
93 assert_response :success | |
94 assert_select 'input[value=secret]', 0 | |
95 assert_select 'input[name=dummy_password][value=?]', /x+/ | |
96 end | |
97 | |
98 def test_edit_invalid_should_respond_with_404 | |
99 get :edit, :id => 99 | |
100 assert_response 404 | |
101 end | |
102 | |
103 def test_update | |
104 put :update, :id => 1, :auth_source => {:name => 'Renamed', :host => '192.168.0.10', :port => '389', :attr_login => 'uid'} | |
105 assert_redirected_to '/auth_sources' | |
106 | |
107 source = AuthSourceLdap.find(1) | |
108 assert_equal 'Renamed', source.name | |
109 assert_equal '192.168.0.10', source.host | |
110 end | |
111 | |
112 def test_update_with_failure | |
113 put :update, :id => 1, :auth_source => {:name => 'Renamed', :host => '', :port => '389', :attr_login => 'uid'} | |
114 assert_response :success | |
115 assert_template 'edit' | |
116 assert_error_tag :content => /host can't be blank/i | |
117 end | |
118 | |
119 def test_destroy | |
120 assert_difference 'AuthSourceLdap.count', -1 do | |
121 delete :destroy, :id => 1 | |
122 assert_redirected_to '/auth_sources' | |
123 end | |
124 end | |
125 | |
126 def test_destroy_auth_source_in_use | |
127 User.find(2).update_attribute :auth_source_id, 1 | |
128 | |
129 assert_no_difference 'AuthSourceLdap.count' do | |
130 delete :destroy, :id => 1 | |
131 assert_redirected_to '/auth_sources' | |
132 end | |
133 end | |
134 | |
135 def test_test_connection | |
136 AuthSourceLdap.any_instance.stubs(:test_connection).returns(true) | |
137 | |
138 get :test_connection, :id => 1 | |
139 assert_redirected_to '/auth_sources' | |
140 assert_not_nil flash[:notice] | |
141 assert_match /successful/i, flash[:notice] | |
142 end | |
143 | |
144 def test_test_connection_with_failure | |
145 AuthSourceLdap.any_instance.stubs(:initialize_ldap_con).raises(Net::LDAP::LdapError.new("Something went wrong")) | |
146 | |
147 get :test_connection, :id => 1 | |
148 assert_redirected_to '/auth_sources' | |
149 assert_not_nil flash[:error] | |
150 assert_include 'Something went wrong', flash[:error] | |
151 end | |
152 | |
153 def test_autocomplete_for_new_user | |
154 AuthSource.expects(:search).with('foo').returns([ | |
155 {:login => 'foo1', :firstname => 'John', :lastname => 'Smith', :mail => 'foo1@example.net', :auth_source_id => 1}, | |
156 {:login => 'Smith', :firstname => 'John', :lastname => 'Doe', :mail => 'foo2@example.net', :auth_source_id => 1} | |
157 ]) | |
158 | |
159 get :autocomplete_for_new_user, :term => 'foo' | |
160 assert_response :success | |
161 assert_equal 'application/json', response.content_type | |
162 json = ActiveSupport::JSON.decode(response.body) | |
163 assert_kind_of Array, json | |
164 assert_equal 2, json.size | |
165 assert_equal 'foo1', json.first['value'] | |
166 assert_equal 'foo1 (John Smith)', json.first['label'] | |
167 end | |
168 end |