Fix onebox loading on every keystroke after a request fails.

This commit is contained in:
Robin Ward
2013-03-05 14:03:50 -05:00
parent 016634d1d9
commit e4277757c4
5 changed files with 158 additions and 89 deletions

View File

@ -2,19 +2,22 @@
describe("Discourse.Onebox", function() {
var anchor;
beforeEach(function() {
spyOn(jQuery, 'ajax').andCallThrough();
anchor = $("<a href='http://bla.com'></a>")[0];
});
it("Stops rapid calls with cache true", function() {
Discourse.Onebox.lookup('http://bla.com', true, function(c) { return c; });
Discourse.Onebox.lookup('http://bla.com', true, function(c) { return c; });
Discourse.Onebox.load(anchor, true);
Discourse.Onebox.load(anchor, true);
expect(jQuery.ajax.calls.length).toBe(1);
});
it("Stops rapid calls with cache false", function() {
Discourse.Onebox.lookup('http://bla.com/a', false, function(c) { return c; });
Discourse.Onebox.lookup('http://bla.com/a', false, function(c) { return c; });
Discourse.Onebox.load(anchor, false);
Discourse.Onebox.load(anchor, false);
expect(jQuery.ajax.calls.length).toBe(1);
});