Merge remote branch 'cloudant:3000-inject_auth_ddoc'

This closes #115

Signed-off-by: ILYA Khlopotov <iilyak@ca.ibm.com>
diff --git a/src/chttpd_auth_cache.erl b/src/chttpd_auth_cache.erl
index 6e14263..b676bf7 100644
--- a/src/chttpd_auth_cache.erl
+++ b/src/chttpd_auth_cache.erl
@@ -92,7 +92,8 @@
 %% gen_server callbacks
 
 init([]) ->
-    {ok, #state{changes_pid = spawn_changes(0)}}.
+    self() ! {start_listener, 0},
+    {ok, #state{}}.
 
 handle_call(_Call, _From, State) ->
     {noreply, State}.
@@ -116,8 +117,10 @@
 handle_info(_Msg, State) ->
     {noreply, State}.
 
-terminate(_Reason, #state{changes_pid = Pid}) ->
-    exit(Pid, kill).
+terminate(_Reason, #state{changes_pid = Pid}) when is_pid(Pid) ->
+    exit(Pid, kill);
+terminate(_Reason, _State) ->
+    ok.
 
 code_change(_OldVsn, #state{}=State, _Extra) ->
     {ok, State}.