@@ -18,6 +18,7 | |||||
18 | require File.expand_path('../../test_helper', __FILE__) |
|
18 | require File.expand_path('../../test_helper', __FILE__) | |
19 |
|
19 | |||
20 | class LdapAuthSourcesControllerTest < ActionController::TestCase |
|
20 | class LdapAuthSourcesControllerTest < ActionController::TestCase | |
|
21 | fixtures :auth_sources, :users | |||
21 |
|
22 | |||
22 | def setup |
|
23 | def setup | |
23 | @request.session[:user_id] = 1 |
|
24 | @request.session[:user_id] = 1 | |
@@ -33,4 +34,63 class LdapAuthSourcesControllerTest < ActionController::TestCase | |||||
33 | assert_equal AuthSourceLdap, source.class |
|
34 | assert_equal AuthSourceLdap, source.class | |
34 | assert source.new_record? |
|
35 | assert source.new_record? | |
35 | end |
|
36 | end | |
|
37 | ||||
|
38 | def test_create | |||
|
39 | assert_difference 'AuthSourceLdap.count' do | |||
|
40 | post :create, :auth_source => {:name => 'Test', :host => '127.0.0.1', :port => '389', :attr_login => 'cn'} | |||
|
41 | assert_redirected_to '/ldap_auth_sources' | |||
|
42 | end | |||
|
43 | ||||
|
44 | source = AuthSourceLdap.first(:order => 'id DESC') | |||
|
45 | assert_equal 'Test', source.name | |||
|
46 | assert_equal '127.0.0.1', source.host | |||
|
47 | assert_equal 389, source.port | |||
|
48 | assert_equal 'cn', source.attr_login | |||
|
49 | end | |||
|
50 | ||||
|
51 | def test_create_with_failure | |||
|
52 | assert_no_difference 'AuthSourceLdap.count' do | |||
|
53 | post :create, :auth_source => {:name => 'Test', :host => '', :port => '389', :attr_login => 'cn'} | |||
|
54 | assert_response :success | |||
|
55 | assert_template 'new' | |||
|
56 | end | |||
|
57 | assert_error_tag :content => /host can't be blank/i | |||
|
58 | end | |||
|
59 | ||||
|
60 | def test_edit | |||
|
61 | get :edit, :id => 1 | |||
|
62 | ||||
|
63 | assert_response :success | |||
|
64 | assert_template 'edit' | |||
|
65 | end | |||
|
66 | ||||
|
67 | def test_update | |||
|
68 | post :update, :id => 1, :auth_source => {:name => 'Renamed', :host => '192.168.0.10', :port => '389', :attr_login => 'uid'} | |||
|
69 | assert_redirected_to '/ldap_auth_sources' | |||
|
70 | ||||
|
71 | source = AuthSourceLdap.find(1) | |||
|
72 | assert_equal 'Renamed', source.name | |||
|
73 | assert_equal '192.168.0.10', source.host | |||
|
74 | end | |||
|
75 | ||||
|
76 | def test_update_with_failure | |||
|
77 | post :update, :id => 1, :auth_source => {:name => 'Renamed', :host => '', :port => '389', :attr_login => 'uid'} | |||
|
78 | assert_response :success | |||
|
79 | assert_template 'edit' | |||
|
80 | assert_error_tag :content => /host can't be blank/i | |||
|
81 | end | |||
|
82 | ||||
|
83 | def test_destroy | |||
|
84 | assert_difference 'AuthSourceLdap.count', -1 do | |||
|
85 | post :destroy, :id => 1 | |||
|
86 | end | |||
|
87 | end | |||
|
88 | ||||
|
89 | def test_destroy_auth_source_in_use | |||
|
90 | User.find(2).update_attribute :auth_source_id, 1 | |||
|
91 | ||||
|
92 | assert_no_difference 'AuthSourceLdap.count' do | |||
|
93 | post :destroy, :id => 1 | |||
|
94 | end | |||
|
95 | end | |||
36 | end |
|
96 | end |
General Comments 0
You need to be logged in to leave comments.
Login now