Created
May 27, 2013 09:42
-
-
Save anoras/5656157 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it('should trigger an event when things are retrieved', function() { | |
var server = Sinon.fakeServer.create(); | |
server.respondWith(/\/thing\/(\d+)/, function (xhr, id) { | |
xhr.respond(200, { "Content-Type": "application/json" }, JSON.stringify(new Thing({ id: id, text: 'Hello' }))); | |
}); | |
var ventInvoked = false; | |
vent.on('thingReceived', function(thing) { | |
expect(thing.get('id')).toEqual(123); | |
ventInvoked = true; | |
}); | |
vent.trigger('thingRequested', 123); | |
server.respond(); | |
expect(ventInvoked).toBeTruthy(); | |
server.restore(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this.vent.on('thingRequested', function(id) { | |
var thing = new Thing({ id: id }); | |
thing.fetch({ | |
success: function(thing, response, options) { | |
self.vent.trigger('thingReceived', thing); | |
}, | |
error: function(thing, response, options) { | |
console.error('Unable to get thing'); | |
} | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define([ | |
'lodash', | |
'backbone' | |
], | |
function (_, Backbone) { | |
return Backbone.Model.extend({ | |
url: function() { | |
return '/thing/' + this.get('id'); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment