From ce62b8289940f4f7744aa759437356dba5ba0904 Mon Sep 17 00:00:00 2001 From: sentientwaffle Date: Thu, 16 Feb 2012 19:26:24 -0700 Subject: [PATCH] add Actor#hash --- src/actor.coffee | 4 ++++ test/actor.test.coffee | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/src/actor.coffee b/src/actor.coffee index 1d0f782..3bbde49 100644 --- a/src/actor.coffee +++ b/src/actor.coffee @@ -1,5 +1,9 @@ +crypto = require 'crypto' + module.exports = class Actor constructor: (@name, @email) -> + if email + @hash = crypto.createHash("md5").update(@email, "ascii").digest("hex") # Public: Get a string representation of the Actor. toString: -> diff --git a/test/actor.test.coffee b/test/actor.test.coffee index 26a6a91..dbaab48 100644 --- a/test/actor.test.coffee +++ b/test/actor.test.coffee @@ -18,6 +18,13 @@ describe "Actor", -> actor.toString().should.eql "bob " + describe "#hash", -> + actor = new Actor "bob", "bob@example.com" + + it "is the md5 hash of the email", -> + actor.hash.should.eql "4b9bb80620f03eb3719e0a061c14283d" + + describe ".from_string", -> describe "with a name and email", -> actor = Actor.from_string "bob "