Skip to content
Browse files

Fix for bug with Hubot sending messages to the wrong room

This fixes an issue where if Hubot joined mulitple rooms, userForId
would return the user object with the room attribute from the first
message as persisted by Redis.

Since the adapter only cares about the room the user belongs to, we can
just construct an object that provides that information rather than
polluting robot.brain with a fake user object via userForId
  • Loading branch information...
1 parent 6aaa803 commit 68f6271406fe26df80b997b7ebbde01a0bf29590 @ejfinneran ejfinneran committed Jun 26, 2012
Showing with 10 additions and 5 deletions.
  1. +1 −1 src/robot.coffee
  2. +9 −4 test/robot_test.coffee
View
2 src/robot.coffee
@@ -265,7 +265,7 @@ class Robot
#
# Returns nothing.
messageRoom: (room, strings...) ->
- user = @userForId @id, { room: room }
+ user = { room: room }
@adapter.send user, strings...
# Public: A helper reply function which delegates to the adapter's reply
View
13 test/robot_test.coffee
@@ -28,17 +28,22 @@ server.listen 9001, ->
helper.messageRoom "chat@example.com", "Hello room"
assert.equal 4, helper.sent.length
assert.equal "chat@example.com", helper.recipients[3].room
- assert.equal helper.id, helper.recipients[3].id
assert.equal "Hello room", helper.sent[3]
- helper.adapter.receive 'foobar'
+ helper.messageRoom "chat2@example.com", "Hello to another room"
assert.equal 5, helper.sent.length
- assert.equal 'catch-all', helper.sent[4]
+ assert.equal "chat2@example.com", helper.recipients[4].room
+ assert.equal "Hello to another room", helper.sent[4]
+
+
+ helper.adapter.receive 'foobar'
+ assert.equal 6, helper.sent.length
+ assert.equal 'catch-all', helper.sent[5]
# set a callback for when the next message is replied to
helper.cb = (msg) ->
- assert.equal 6, helper.sent.length
+ assert.equal 7, helper.sent.length
assert.equal 'fetched', msg
helper.close()
server.close()

0 comments on commit 68f6271

Please sign in to comment.
Something went wrong with that request. Please try again.