   end
 
   test "#leave raise InvalidReturn exception when return type invalid" do
-    socket = %Socket{pid: self, router: Router, channel: "chan4", topic: "topic"}
-    sockets = HashDict.put(HashDict.new, {"chan4", "topic"}, socket)
-    message = %Message{channel: "chan4", topic: "topic", event: "join", message: %{}}
-
-    PubSub.create("chan4:topic")
-    {:ok, sockets} = Transport.dispatch(message, sockets, self, Router)
-    sock = HashDict.get(sockets, {"chan4", "topic"})
-    assert Socket.authorized?(sock, "chan4", "topic")
+    socket = new_socket
+    sockets = HashDict.put(HashDict.new, {"chan1", "topic"}, socket)
+    message = join_message({:ok, socket})
+
+    PubSub.create("chan1:topic")
+    {:ok, sockets} = Transport.dispatch(message, sockets, self, Router)
+    sock = HashDict.get(sockets, {"chan1", "topic"})
+    assert Socket.authorized?(sock, "chan1", "topic")
+    Process.put(:leave, :badreturn)
     assert_raise InvalidReturn, fn ->
       Transport.dispatch_leave(sockets, :reason)
     end
   end
 
   test "#event raises InvalidReturn exception when return type is invalid" do
-    socket = %Socket{pid: self, router: Router, channel: "chan5", topic: "topic"}
-    sockets = HashDict.put(HashDict.new, {"chan5", "topic"}, socket)
-    message = %Message{channel: "chan5", topic: "topic", event: "join", message: %{}}
-
-    PubSub.create("chan5:topic")
-    {:ok, sockets} = Transport.dispatch(message, sockets, self, Router)
-    sock = HashDict.get(sockets, {"chan5", "topic"})
-    assert Socket.authorized?(sock, "chan5", "topic")
-    message = %Message{channel: "chan5", topic: "topic", event: "boom", message: %{}}
+    socket = new_socket
+    sockets = HashDict.put(HashDict.new, {"chan1", "topic"}, socket)
+    message = join_message({:ok, socket})
+
+    PubSub.create("chan1:topic")
+    {:ok, sockets} = Transport.dispatch(message, sockets, self, Router)
+    sock = HashDict.get(sockets, {"chan1", "topic"})
+    assert Socket.authorized?(sock, "chan1", "topic")
+    message = %Message{channel: "chan1",
+                       topic: "topic",
+                       event: "boom",
+                       message: :badreturn}
 
     assert_raise InvalidReturn, fn ->
       Transport.dispatch(message, sockets, self, Router)

  alias Phoenix.Channel.Transport
  alias Phoenix.Channel.Transport.InvalidReturn

  def new_socket do
    %Socket{pid: self,
            router: nil,
            channel: "somechan",
            assigns: []}
  end

  test "#subscribe/unsubscribe's socket to/from topic" do

    end
  end

  test "Default #leave is generated as a noop" do
    socket = new_socket
    Process.put(:leave, socket)
    assert MyChannel.leave(socket, []) == socket
  end

  test "#leave can be overridden" do
    Process.put(:leave, :overridden)
    assert MyChannel.leave(new_socket, []) == :overridden
  end

  test "successful join authorizes and subscribes socket to channel/topic" do
    message = join_message({:ok, new_socket})

    PubSub.create("chan1:topic")
    assert PubSub.subscribers("chan1:topic") == []
