Permalink
Browse files

If no name is given for the user, default to ID

This is useful for XMPP where groupchat users only have an ID and not a
name.
  • Loading branch information...
1 parent efb21f4 commit dd49b49e9a08037c48891174146fd8d0d0c72072 @ejfinneran ejfinneran committed Nov 23, 2011
Showing with 15 additions and 0 deletions.
  1. +1 −0 src/user.coffee
  2. +14 −0 test/user_test.coffee
View
@@ -8,6 +8,7 @@ class User
constructor: (@id, options = { }) ->
for k of (options or { })
@[k] = options[k]
+ @['name'] ||= @id
module.exports = User
View
@@ -0,0 +1,14 @@
+User = require '../src/user'
+assert = require 'assert'
+
+
+user = new User "Fake User", {name: 'fake', type: "groupchat"}
+assert.equal "Fake User", user.id
+assert.equal "groupchat", user.type
+assert.equal "fake", user.name
+
+user = new User "Fake User", {room: "chat@room.jabber", type: "groupchat"}
+assert.equal "Fake User", user.id
+assert.equal "chat@room.jabber", user.room
+assert.equal "groupchat", user.type
+assert.equal "Fake User", user.name # Make sure that if no name is given, we fallback to the ID

0 comments on commit dd49b49

Please sign in to comment.