diff --git a/package.json b/package.json index c6d9f1e..ab36de3 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "can-reflect": "^1.15.1" }, "devDependencies": { + "can-define": "^2.7.18", "can-set-legacy": "<2.0.0", "can-test-helpers": "^1.1.2", "detect-cyclic-packages": "^1.1.0", diff --git a/store.js b/store.js index fb521f7..7ef9b52 100644 --- a/store.js +++ b/store.js @@ -94,7 +94,7 @@ function typeConvert(data){ var copy = {}; canReflect.eachKey(data, function(value, key){ if(keys[key]) { - copy[key] = canReflect.convert(value, keys[key]); + copy[key] = canReflect.serialize(canReflect.convert(value, keys[key])); } else { copy[key] = value; } diff --git a/test/fixture_test.js b/test/fixture_test.js index e0c74a6..5361506 100644 --- a/test/fixture_test.js +++ b/test/fixture_test.js @@ -11,6 +11,7 @@ var canReflect = require("can-reflect"); var matches = require("../matches"); var QueryLogic = require("can-query-logic"); var testHelpers = require("can-test-helpers"); +var DefineMap = require("can-define/map/map"); var errorCallback = function(xhr, status, error){ @@ -1876,6 +1877,46 @@ QUnit.test('fixture returns the old fixture callback when fixtures are removed ( assert.deepEqual(oldFixtures, [{fixture: funcA, url: '/services/thing'}]); }); +QUnit.test("Using with nested types", function(assert){ + var done = assert.async(); + + var Pet = DefineMap.extend("Pet", { + name: "string" + }); + var Person = DefineMap.extend("Person", { + id: { type: "number", identity: true }, + name: "string", + pet: Pet + }); + + var store = fixture.store([{ + id: 1, + name: "Dorothy", + pet: { + name: "Max" + } + }], new QueryLogic(Person)); + + fixture('/api/persons/{id}', store); + + var xhr = new XMLHttpRequest(); + xhr.addEventListener('load', function() { + var data = JSON.parse(this.responseText); + var xhr2 = new XMLHttpRequest(); + + xhr2.addEventListener('load', function() { + var data = JSON.parse(this.responseText); + assert.equal(data.pet.name, "Max", "Still have the Pet type"); + done(); + }); + xhr2.open('PUT', '/api/persons/1', true); + xhr2.send(data); + + }); + xhr.open('GET', '/api/persons/1', true); + xhr.send(); +}); + if ("onabort" in XMLHttpRequest._XHR.prototype) { QUnit.test('fixture with timeout aborts if xhr timeout less than delay', function(assert) { var done = assert.async(); @@ -2009,7 +2050,7 @@ if ("onabort" in XMLHttpRequest._XHR.prototype) { return {}; }); - teardown(); + teardown(); }); testHelpers.dev.devOnlyTest("Works with steal-clone", function (assert) { @@ -2034,6 +2075,3 @@ if ("onabort" in XMLHttpRequest._XHR.prototype) { var done = assert.async(); }); } // END onabort check - - -