Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
caching simultaneous request ready
  • Loading branch information
vitalets committed Aug 25, 2012
1 parent d4fed2c commit a30efad
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/js/bootstrap-editable.js
Expand Up @@ -431,7 +431,7 @@

if(!$(document).data(cacheID)) $(document).data(cacheID, {});
cache = $(document).data(cacheID);

//check for cached data
if (cache.loading === false && cache.source && typeof cache.source === 'object') { //take source from cache
this.settings.source = cache.source;
Expand All @@ -447,7 +447,7 @@
cache.loading = true;
cache.callbacks = [];
}

//options loading from server
$.ajax({
url: this.settings.source,
Expand Down
35 changes: 34 additions & 1 deletion test/select.js
Expand Up @@ -229,7 +229,7 @@ $(function () {
}, timeout);
});

asyncTest("cache options request for same selects", function () {
asyncTest("cache request for same selects", function () {
var e = $('<a href="#" data-type="select" data-pk="1" data-value="2" data-url="post.php" data-source="groups-cache.php">customer</a>').appendTo(fx).editable(),
e1 = $('<a href="#" data-type="select" data-pk="1" data-value="2" data-url="post.php" data-source="groups-cache.php">customer</a>').appendTo(fx).editable(),
req = 0;
Expand Down Expand Up @@ -273,6 +273,39 @@ $(function () {

});

asyncTest("cache simultaneous requests", function () {
expect(4);
var req = 0;
$.mockjax({
url: 'groups-cache-sim.php',
responseTime: 200,
response: function() {
req++;
this.responseText = groups;
}
});

var e = $('<a href="#" data-type="select" data-pk="1" data-value="1" data-autotext="always" data-url="post.php" data-source="groups-cache-sim.php">35</a>').appendTo(fx).editable(),
e1 = $('<a href="#" data-type="select" data-pk="1" data-value="2" data-autotext="always" data-url="post.php" data-source="groups-cache-sim.php">35</a>').appendTo(fx).editable(),
e2 = $('<a href="#" data-type="select" data-pk="1" data-value="3" data-autotext="always" data-url="post.php" data-source="groups-cache-sim.php">6456</a>').appendTo(fx).editable();

setTimeout(function() {

equal(req, 1, 'one request');
equal(e.text(), groups[1], 'text1 correct');
equal(e1.text(), groups[2], 'text2 correct');
equal(e2.text(), groups[3], 'text3 correct');

e.remove();
e1.remove();
e2.remove();
start();
}, 300);

});



test("autotext: auto", function () {
expect(3);
//auto, text->empty, source->array
Expand Down

0 comments on commit a30efad

Please sign in to comment.