fix for issue RavenDB-2387 + unit test (port from 2.5)