]> source.dussan.org Git - redmine.git/commitdiff
Adds functional test for #test_connection.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 2 Mar 2012 11:31:44 +0000 (11:31 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 2 Mar 2012 11:31:44 +0000 (11:31 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9053 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/auth_sources_controller.rb
test/functional/ldap_auth_sources_controller_test.rb

index cf139a187cd064a9a7d44a011e44d28649a61770..2a854ad48a8d6c0328346c09f68883e13e27a7a5 100644 (file)
@@ -64,8 +64,8 @@ class AuthSourcesController < ApplicationController
     begin
       @auth_method.test_connection
       flash[:notice] = l(:notice_successful_connection)
-    rescue => text
-      flash[:error] = l(:error_unable_to_connect, text.message)
+    rescue Exception => e
+      flash[:error] = l(:error_unable_to_connect, e.message)
     end
     redirect_to :action => 'index'
   end
index b24cbc2812514b52acba3395ffe20873793eb1d2..bfb2c569e9f5869619187efeef29853a454c3f35 100644 (file)
@@ -93,4 +93,22 @@ class LdapAuthSourcesControllerTest < ActionController::TestCase
       post :destroy, :id => 1
     end
   end
+
+  def test_test_connection
+    AuthSourceLdap.any_instance.stubs(:test_connection).returns(true)
+
+    get :test_connection, :id => 1
+    assert_redirected_to '/ldap_auth_sources'
+    assert_not_nil flash[:notice]
+    assert_match /successful/i, flash[:notice]
+  end
+
+  def test_test_connection_with_failure
+    AuthSourceLdap.any_instance.stubs(:test_connection).raises(Exception.new("Something went wrong"))
+
+    get :test_connection, :id => 1
+    assert_redirected_to '/ldap_auth_sources'
+    assert_not_nil flash[:error]
+    assert_include '(Something went wrong)', flash[:error]
+  end
 end