Created
August 5, 2014 11:50
-
-
Save asci/ab3468d0d21d78c16403 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function moduleFor(fullName, description, callbacks, delegate) { | |
var container; | |
var context; | |
var _callbacks = { | |
setup: function(){ | |
callbacks = callbacks || { }; | |
var needs = [fullName].concat(callbacks.needs || []); | |
container = isolatedContainer(needs); | |
callbacks.subject = callbacks.subject || defaultSubject; | |
callbacks.setup = callbacks.setup || function() { }; | |
callbacks.teardown = callbacks.teardown || function() { }; | |
function factory() { | |
return container.lookupFactory(fullName); | |
} | |
testContext.set({ | |
container: container, | |
factory: factory, | |
dispatcher: null, | |
__setup_properties__: callbacks | |
}); | |
context = testContext.get(); | |
if (delegate) { | |
delegate(container, context, defaultSubject); | |
} | |
if (Ember.$('#ember-testing').length === 0) { | |
Ember.$(' | |
').appendTo(document.body); | |
} | |
buildContextVariables(context); | |
callbacks.setup.call(context, container); | |
}, | |
teardown: function(){ | |
Ember.run(function(){ | |
container.destroy(); | |
if (context.dispatcher) { | |
context.dispatcher.destroy(); | |
} | |
}); | |
callbacks.teardown(container); | |
Ember.$('#ember-testing').empty(); | |
} | |
}; | |
QUnit.module(description || fullName, _callbacks); | |
} | |
function moduleForModel(name, description, callbacks) { | |
if (!DS) throw new Error('You must have Ember Data installed to use `moduleForModel`.'); | |
moduleFor('model:' + name, description, callbacks, function(container, context, defaultSubject) { | |
if (DS._setupContainer) { | |
DS._setupContainer(container); | |
} else { | |
container.register('store:main', DS.Store); | |
} | |
var adapterFactory = container.lookupFactory('adapter:application'); | |
if (!adapterFactory) { | |
container.register('adapter:application', DS.FixtureAdapter); | |
} | |
context.__setup_properties__.store = function(){ | |
return container.lookup('store:main'); | |
}; | |
if (context.__setup_properties__.subject === defaultSubject) { | |
context.__setup_properties__.subject = function(options) { | |
return Ember.run(function() { | |
return container.lookup('store:main').createRecord(name, options); | |
}); | |
}; | |
} | |
}); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment