Auto-populate fields while creating a new user with LDAP (#10286).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11080 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -149,4 +149,20 @@ class AuthSourcesControllerTest < ActionController::TestCase
|
||||
assert_not_nil flash[:error]
|
||||
assert_include 'Something went wrong', flash[:error]
|
||||
end
|
||||
|
||||
def test_autocomplete_for_new_user
|
||||
AuthSource.expects(:search).with('foo').returns([
|
||||
{:login => 'foo1', :firstname => 'John', :lastname => 'Smith', :mail => 'foo1@example.net', :auth_source_id => 1},
|
||||
{:login => 'Smith', :firstname => 'John', :lastname => 'Doe', :mail => 'foo2@example.net', :auth_source_id => 1}
|
||||
])
|
||||
|
||||
get :autocomplete_for_new_user, :term => 'foo'
|
||||
assert_response :success
|
||||
assert_equal 'application/json', response.content_type
|
||||
json = ActiveSupport::JSON.decode(response.body)
|
||||
assert_kind_of Array, json
|
||||
assert_equal 2, json.size
|
||||
assert_equal 'foo1', json.first['value']
|
||||
assert_equal 'foo1 (John Smith)', json.first['label']
|
||||
end
|
||||
end
|
||||
|
||||
@@ -51,5 +51,9 @@ class RoutingAuthSourcesTest < ActionController::IntegrationTest
|
||||
{ :controller => 'auth_sources', :action => 'test_connection',
|
||||
:id => '1234' }
|
||||
)
|
||||
assert_routing(
|
||||
{ :method => 'get', :path => "/auth_sources/autocomplete_for_new_user" },
|
||||
{ :controller => 'auth_sources', :action => 'autocomplete_for_new_user' }
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -124,6 +124,30 @@ class AuthSourceLdapTest < ActiveSupport::TestCase
|
||||
auth_source.authenticate 'example1', '123456'
|
||||
end
|
||||
end
|
||||
|
||||
def test_search_should_return_matching_entries
|
||||
results = AuthSource.search("exa")
|
||||
assert_equal 1, results.size
|
||||
result = results.first
|
||||
assert_kind_of Hash, result
|
||||
assert_equal "example1", result[:login]
|
||||
assert_equal "Example", result[:firstname]
|
||||
assert_equal "One", result[:lastname]
|
||||
assert_equal "example1@redmine.org", result[:mail]
|
||||
assert_equal 1, result[:auth_source_id]
|
||||
end
|
||||
|
||||
def test_search_with_no_match_should_return_an_empty_array
|
||||
results = AuthSource.search("wro")
|
||||
assert_equal [], results
|
||||
end
|
||||
|
||||
def test_search_with_exception_should_return_an_empty_array
|
||||
Net::LDAP.stubs(:new).raises(Net::LDAP::LdapError, 'Cannot connect')
|
||||
|
||||
results = AuthSource.search("exa")
|
||||
assert_equal [], results
|
||||
end
|
||||
else
|
||||
puts '(Test LDAP server not configured)'
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user