Permalink
Browse files

Leave the campfire room on IRC PART.

This makes join/part more explicit and should prevent issues with "ghost" users.
Fixes #46.
  • Loading branch information...
zerowidth committed Oct 26, 2013
1 parent f7043ee commit d5624e3c68f7d8963ee8ed666d124503f2292122
Showing with 37 additions and 12 deletions.
  1. +3 −9 lib/camper_van/channel.rb
  2. +34 −3 spec/camper_van/channel_spec.rb
View
@@ -78,19 +78,13 @@ def join
# Public: "leaves" a campfire room, per the PART irc command.
# Confirms with the connected client to PART the channel.
- #
- # Does not actually leave the campfire room, just closes out the campfire
- # connections, so the server can idle the connection out. This behavior
- # was chosen so periodic joins/parts wouldn't spam the campfire rooms
- # unnecessarily, and also to reflect how Propane et. al. treat open
- # connections: allowing them to time out rather than leaving explicitly.
def part
client.user_reply :part, channel
if stream
- stream.close if stream.respond_to?('close') # EM/em-http-request gem is installed and uses .close
- stream.close_connection if stream.respond_to?('close_connection')
+ stream.close if stream.respond_to?(:close) # EM/em-http-request gem is installed and uses .close
+ stream.close_connection if stream.respond_to?(:close_connection)
end
- # room.leave # let the timeout do it rather than being explicit!
+ room.leave
end
# Public: replies to a WHO command with a list of users for a campfire room,
@@ -22,6 +22,7 @@ class TestRoom
attr_reader :locked, :full, :topic, :membership_limit
attr_reader :sent
attr_reader :stream_count
+ attr_reader :left
attr_writer :users, :topic, :locked, :full, :open_to_guests
attr_writer :stream
@@ -52,6 +53,10 @@ def join
yield
end
+ def leave
+ @left = true
+ end
+
def users
yield @users if block_given?
@users
@@ -144,12 +149,38 @@ def stream
end
it "closes the connection on the stream" do
- @room.stream = MiniTest::Mock.new
- @room.stream.expect(:close_connection, nil)
+ stream = Class.new do
+ attr_reader :closed
+ def close_connection
+ @closed = true
+ end
+ end
+
+ @room.stream = stream.new
+ @channel.stream_campfire_to_channel # sets up stream
+ @channel.part
+
+ assert @room.stream.closed
+ end
+
+ it "closes the em-http connection if present" do
+ stream = Class.new do
+ attr_reader :closed
+ def close # em-http defines this
+ @closed = true
+ end
+ end
+
+ @room.stream = stream.new
@channel.stream_campfire_to_channel # sets up stream
@channel.part
- @room.stream.verify
+ assert @room.stream.closed
+ end
+
+ it "leaves the channel" do
+ @channel.part
+ assert @room.left
end
end

1 comment on commit d5624e3

@elia

This comment has been minimized.

Show comment Hide comment
@elia

elia Dec 5, 2013

❤️

elia commented on d5624e3 Dec 5, 2013

❤️

Please sign in to comment.