Permalink
Browse files

Implement findQuery on GitHubDataSource

  • Loading branch information...
pangratz committed Jul 23, 2012
1 parent 0d190c3 commit bde47040ac2917c600fe9ba7c8edd6d48a631ab0
@@ -1,4 +1,5 @@
require('dashboard/core');
require('dashboard/model');
Dashboard.GitHubDataSource = DS.Adapter.extend({
PREFIX: 'https://api.github.com',
@@ -29,7 +30,13 @@ Dashboard.GitHubDataSource = DS.Adapter.extend({
this.set('limit', response.meta['X-RateLimit-Limit']);
}
},
findQuery: function(store, type, query, modelArray) {
if (Dashboard.Repository.detect(type) && 'watched' === query.type) {
this.watchedRepositories(query.username, modelArray, 'load');
}
},
watchedRepositories: function(username, target, callback) {
this.ajax('/users/%@/watched'.fmt(username), target, callback);
}
@@ -98,4 +98,4 @@ test("invokes ajax", function() {
deepEqual(ajaxUrl, '/users/buster/watched', "the passed url is correct");
deepEqual(ajaxTarget, target, "the target has been passed");
deepEqual(ajaxCallback, 'callback', "the callback has been passed");
});
});
@@ -0,0 +1,35 @@
require('dashboard/store');
require('dashboard/model');
require('dashboard/github_data_source');
var store, adapter;
module("Dashboard.Store and Dashboard.GitHubDataSource integration tests", {
setup: function() {
adapter = Dashboard.GitHubDataSource.create();
store = Dashboard.Store.create({ adapter: adapter });
},
teardown: function() {
adapter.destroy();
store.destroy();
}
});
test("findQuery works for watched repositories", function() {
// it is expected that a findQuery for Dashboard.Repository
// invokes `watchedRepositories` on adapter when type in the query is 'watched'
expect(2);
adapter.reopen({
watchedRepositories: function(username, target, callback) {
ok(true, "watched repositories has been called");
equal(username, 'pangratz', 'correct username has been passed');
}
});
store.findQuery(Dashboard.Repository, {
username: 'pangratz',
type: 'watched'
});
});

0 comments on commit bde4704

Please sign in to comment.