Skip to content

Instantly share code, notes, and snippets.

@ksin
Created November 23, 2014 02:55
Show Gist options
  • Save ksin/302a6cfafe10295a759b to your computer and use it in GitHub Desktop.
Save ksin/302a6cfafe10295a759b to your computer and use it in GitHub Desktop.
api helper
import Ember from 'ember';
var FakeClientApi = Ember.Object.extend({
recentMediaForTagStub: null,
stubRecentMediaForTag: function(callback){
this.recentMediaForTagStub = callback;
},
recentMediaForTag: function(tag, options) {
if (this.recentMediaForTagStub) {
var results = this.recentMediaForTagStub.call(this, tag, options);
return Ember.RSVP.resolve(results);
}
return Ember.RSVP.reject('No stubs registered for recentMediaForTag. Did you forget to call `stubRecentMediaForTag`?');
}
});
export function apiStub(registryEntryName, app, dsl) {
var apiClient = FakeClientApi.create();
app.register(registryEntryName, apiClient, { instantiate: false });
dsl.call(apiClient);
return apiClient;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment