Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Tests for Events

  • Loading branch information...
commit 30095ceb828508392a2eb9d9f73a42b8df43af9e 1 parent f820b37
Jan Varwig authored
3  lib/assets/javascripts/rest_in_place/rest_in_place.coffee.erb
View
@@ -57,6 +57,7 @@ class RestInPlaceEditor
loadViaGET : ->
showRequest = @ajax()
showRequest.done (data) => @loadSuccessCallback(data)
+ showRequest.fail => @$element.trigger('failure.rest-in-place')
# ## Implementation Methods
#
@@ -223,4 +224,4 @@ $.fn.restInPlace = ->
# Run automatically
-$ -> $('.rest-in-place').restInPlace()
+$ -> $('.rest-in-place').restInPlace()
47 testapp/app/assets/javascripts/spec.coffee
View
@@ -173,4 +173,49 @@ describe "jQuery Interface", ->
.find('span')
.restInPlace()
.data('restInPlaceEditor')
- expect(typeof rip.activate).toEqual("function")
+ expect(typeof rip.activate).toEqual("function")
+
+describe "Events", ->
+ handlers = {}
+
+ beforeEach ->
+ rip = makeRip '<p><span data-object="person" data-attribute="age">Blubb</span></p>'
+ handlers =
+ activate : ->
+ success : ->
+ failure : ->
+ update : ->
+ abort : ->
+
+ it "should dispatch activate.rest-in-place", ->
+ spyOn(handlers, 'activate')
+ rip.$element.bind("activate.rest-in-place", handlers.activate)
+ rip.activate()
+ expect(handlers.activate).toHaveBeenCalled()
+
+ it "should dispatch success.rest-in-place", ->
+ spyOn(handlers, 'success')
+ rip.$element.bind("success.rest-in-place", handlers.success)
+ rip.loadSuccessCallback({person: {age: 666}})
+ expect(handlers.success).toHaveBeenCalled()
+
+ it "should dispatch failure.rest-in-place", ->
+ spyOn(handlers, 'failure')
+ rip.$element.bind("failure.rest-in-place", handlers.failure)
+ deferred = rip.loadViaGET()
+ waitsFor((-> deferred.state() != "pending"), "deferred timeout", 500)
+ runs -> expect(handlers.failure).toHaveBeenCalled()
+ # Test POST failure
+
+ it "should dispatch update.rest-in-place", ->
+ spyOn(handlers, 'update')
+ rip.$element.bind("update.rest-in-place", handlers.update)
+ rip.update()
+ expect(handlers.update).toHaveBeenCalled()
+
+ it "should dispatch abort.rest-in-place", ->
+ spyOn(handlers, 'abort')
+ rip.$element.bind("abort.rest-in-place", handlers.abort)
+ rip.activate()
+ rip.abort()
+ expect(handlers.abort).toHaveBeenCalled()
Please sign in to comment.
Something went wrong with that request. Please try again.