Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added a DataSource reset function for fixtures - Fixes #408

  • Loading branch information...
commit 2f1cc85bf47b6be9d66a4ed95ccce57247a5e557 1 parent 68ac191
@wagenet wagenet authored
View
12 frameworks/datastore/data_sources/fixtures.js
@@ -344,7 +344,17 @@ SC.FixturesDataSource = SC.DataSource.extend(
var ret = [], fixtures = this._fixtures[SC.guidFor(recordType)];
return fixtures ? YES: NO;
},
-
+
+ /**
+ Resets the fixtures to their original values.
+
+ @returns {SC.FixturesDataSource} receiver
+ */
+ reset: function(){
+ this._fixtures = null;
+ return this;
+ },
+
/**
Returns YES or SC.MIXED_STATE if one or more of the storeKeys can be
handled by the fixture data source.
View
3  frameworks/datastore/system/store.js
@@ -662,6 +662,9 @@ SC.Store = SC.Object.extend( /** @scope SC.Store.prototype */ {
this.recordErrors = null;
this.queryErrors = null;
+ var dataSource = this.get('dataSource');
+ if (dataSource && dataSource.reset) { dataSource.reset(); }
+
var records = this.records, storeKey;
if (records) {
for(storeKey in records) {
View
15 frameworks/datastore/tests/data_sources/data_source.js
@@ -5,7 +5,7 @@
// ==========================================================================
/*globals JN module test ok equals same stop start */
-var MyApp, wasCalled;
+var MyApp, wasCalled, resetWasCalled;
module("SC.DataSource", {
setup: function () {
MyApp = window.MyApp = {};
@@ -41,6 +41,11 @@ module("SC.DataSource", {
wasCalled = true;
equals(arguments.length, 3);
return YES;
+ },
+
+ reset: function() {
+ resetWasCalled = true;
+ return this;
}
});
SC.RunLoop.begin();
@@ -188,3 +193,11 @@ test("The dataSource will return NO when all records committed return NO", funct
equals(MyApp.store.commitRecords(), NO,
"commiting records for an 'update', 'create', and 'destroy' should return NO");
});
+
+test("The store calls reset on the dataSource when reset", function(){
+ MyApp.store.set('dataSource', MyApp.DataSource.create());
+ resetWasCalled = NO; // Just to be sure
+
+ MyApp.store.reset();
+ ok(resetWasCalled, "should have called reset");
+});
Please sign in to comment.
Something went wrong with that request. Please try again.