Mercurial > hg > soundsoftware-site
comparison test/functional/auth_sources_controller_test.rb @ 1295:622f24f53b42 redmine-2.3
Update to Redmine SVN revision 11972 on 2.3-stable branch
author | Chris Cannam |
---|---|
date | Fri, 14 Jun 2013 09:02:21 +0100 |
parents | 433d4f72a19b |
children | e248c7af89ec |
comparison
equal
deleted
inserted
replaced
1294:3e4c3460b6ca | 1295:622f24f53b42 |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2012 Jean-Philippe Lang | 2 # Copyright (C) 2006-2013 Jean-Philippe Lang |
3 # | 3 # |
4 # This program is free software; you can redistribute it and/or | 4 # This program is free software; you can redistribute it and/or |
5 # modify it under the terms of the GNU General Public License | 5 # modify it under the terms of the GNU General Public License |
6 # as published by the Free Software Foundation; either version 2 | 6 # as published by the Free Software Foundation; either version 2 |
7 # of the License, or (at your option) any later version. | 7 # of the License, or (at your option) any later version. |
40 | 40 |
41 source = assigns(:auth_source) | 41 source = assigns(:auth_source) |
42 assert_equal AuthSourceLdap, source.class | 42 assert_equal AuthSourceLdap, source.class |
43 assert source.new_record? | 43 assert source.new_record? |
44 | 44 |
45 assert_tag 'input', :attributes => {:name => 'type', :value => 'AuthSourceLdap'} | 45 assert_select 'form#auth_source_form' do |
46 assert_tag 'input', :attributes => {:name => 'auth_source[host]'} | 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 | |
47 end | 54 end |
48 | 55 |
49 def test_create | 56 def test_create |
50 assert_difference 'AuthSourceLdap.count' do | 57 assert_difference 'AuthSourceLdap.count' do |
51 post :create, :type => 'AuthSourceLdap', :auth_source => {:name => 'Test', :host => '127.0.0.1', :port => '389', :attr_login => 'cn'} | 58 post :create, :type => 'AuthSourceLdap', :auth_source => {:name => 'Test', :host => '127.0.0.1', :port => '389', :attr_login => 'cn'} |
52 assert_redirected_to '/auth_sources' | 59 assert_redirected_to '/auth_sources' |
53 end | 60 end |
54 | 61 |
55 source = AuthSourceLdap.first(:order => 'id DESC') | 62 source = AuthSourceLdap.order('id DESC').first |
56 assert_equal 'Test', source.name | 63 assert_equal 'Test', source.name |
57 assert_equal '127.0.0.1', source.host | 64 assert_equal '127.0.0.1', source.host |
58 assert_equal 389, source.port | 65 assert_equal 389, source.port |
59 assert_equal 'cn', source.attr_login | 66 assert_equal 'cn', source.attr_login |
60 end | 67 end |
72 get :edit, :id => 1 | 79 get :edit, :id => 1 |
73 | 80 |
74 assert_response :success | 81 assert_response :success |
75 assert_template 'edit' | 82 assert_template 'edit' |
76 | 83 |
77 assert_tag 'input', :attributes => {:name => 'auth_source[host]'} | 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 | |
78 end | 101 end |
79 | 102 |
80 def test_update | 103 def test_update |
81 put :update, :id => 1, :auth_source => {:name => 'Renamed', :host => '192.168.0.10', :port => '389', :attr_login => 'uid'} | 104 put :update, :id => 1, :auth_source => {:name => 'Renamed', :host => '192.168.0.10', :port => '389', :attr_login => 'uid'} |
82 assert_redirected_to '/auth_sources' | 105 assert_redirected_to '/auth_sources' |
94 end | 117 end |
95 | 118 |
96 def test_destroy | 119 def test_destroy |
97 assert_difference 'AuthSourceLdap.count', -1 do | 120 assert_difference 'AuthSourceLdap.count', -1 do |
98 delete :destroy, :id => 1 | 121 delete :destroy, :id => 1 |
122 assert_redirected_to '/auth_sources' | |
99 end | 123 end |
100 end | 124 end |
101 | 125 |
102 def test_destroy_auth_source_in_use | 126 def test_destroy_auth_source_in_use |
103 User.find(2).update_attribute :auth_source_id, 1 | 127 User.find(2).update_attribute :auth_source_id, 1 |
104 | 128 |
105 assert_no_difference 'AuthSourceLdap.count' do | 129 assert_no_difference 'AuthSourceLdap.count' do |
106 delete :destroy, :id => 1 | 130 delete :destroy, :id => 1 |
131 assert_redirected_to '/auth_sources' | |
107 end | 132 end |
108 end | 133 end |
109 | 134 |
110 def test_test_connection | 135 def test_test_connection |
111 AuthSourceLdap.any_instance.stubs(:test_connection).returns(true) | 136 AuthSourceLdap.any_instance.stubs(:test_connection).returns(true) |
122 get :test_connection, :id => 1 | 147 get :test_connection, :id => 1 |
123 assert_redirected_to '/auth_sources' | 148 assert_redirected_to '/auth_sources' |
124 assert_not_nil flash[:error] | 149 assert_not_nil flash[:error] |
125 assert_include 'Something went wrong', flash[:error] | 150 assert_include 'Something went wrong', flash[:error] |
126 end | 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 | |
127 end | 168 end |