Skip to content

Commit

Permalink
Move functions onto instance of Encryptor, not class
Browse files Browse the repository at this point in the history
  • Loading branch information
kerryb committed Mar 24, 2013
1 parent abadf11 commit c6a1226
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
11 changes: 7 additions & 4 deletions app/assets/javascripts/encryptor.coffee
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
window.Encryptor = class Encryptor
@encrypt: =>
class Encryptor
constructor: ->
$("#plain-text").keyup @encrypt

encrypt: =>
plainText = $("#plain-text").val()
$.get "/encrypt", {text: plainText}, @update

@update: (data) =>
update: (data) =>
$("#encrypted-text").val data.text

$ ->
$("#plain-text").keyup window.Encryptor.encrypt
window.encryptor = new Encryptor
6 changes: 3 additions & 3 deletions spec/javascripts/encryptor_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ describe "Encryptor", ->

describe ".update", ->
it "sets the #encrypted-text element's value to the supplied data's text attribute", ->
window.Encryptor.update {text: "foo"}
window.encryptor.update {text: "foo"}
expect($("#encrypted-text").val()).toEqual "foo"

describe ".encrypt", ->
it "requests encryption of the #plain-text field, calling .update on success", ->
$("#plain-text").val "foo"
spyOn $, "get"
window.Encryptor.encrypt()
expect($.get).toHaveBeenCalledWith "/encrypt", {text: "foo"}, window.Encryptor.update
window.encryptor.encrypt()
expect($.get).toHaveBeenCalledWith "/encrypt", {text: "foo"}, window.encryptor.update

0 comments on commit c6a1226

Please sign in to comment.