# HG changeset patch # User hamidouk # Date 1319469954 -7200 # Node ID f3fec80dd31ca8545da0fa74971a9f89fdce600f # Parent 3ce493c93d6c95b6355354eea80374f0c50f5105 renames and inheritance bug fixes. diff -r 3ce493c93d6c -r f3fec80dd31c src/js/data.js --- a/src/js/data.js Mon Oct 24 16:51:22 2011 +0200 +++ b/src/js/data.js Mon Oct 24 17:25:54 2011 +0200 @@ -34,7 +34,7 @@ IriSP.Serializer.prototype.currentMedia = function() { }; -IriSP.Serializer.prototype.sync = function(callback) { +IriSP.Serializer.prototype.sync = function(callback) { callback.apply(this, []); }; @@ -42,13 +42,19 @@ this._dataloader = DataLoader; }; -IriSP.SerializerFactory.prototype.getSerializer = function(config) { +IriSP.SerializerFactory.prototype.getSerializer = function(metadataOptions) { /* This function returns serializer set-up with the correct - configuration + configuration - takes a metadata struct describing the metadata source */ - switch(config.metadata.load) { + switch(metadataOptions.type) { case "json": - return new IriSP.JSONSerializer(this._dataloader, config.metadata.src); + return new IriSP.JSONSerializer(this._dataloader, metadataOptions.src); + break; + + case "dummy": /* only used for unit testing - not defined in production */ + return new IriSP.MockSerializer(this._dataloader, metadataOptions.src); + break; + default: return undefined; } diff -r 3ce493c93d6c -r f3fec80dd31c src/js/serializers/JSONSerializer.js --- a/src/js/serializers/JSONSerializer.js Mon Oct 24 16:51:22 2011 +0200 +++ b/src/js/serializers/JSONSerializer.js Mon Oct 24 17:25:54 2011 +0200 @@ -3,7 +3,7 @@ IriSP.Serializer.call(this, DataLoader, url); }; -IriSP.JSONSerializer.prototype = IriSP.Serializer; +IriSP.JSONSerializer.prototype = new IriSP.Serializer(); IriSP.JSONSerializer.prototype.serialize = function(data) { return JSON.stringify(data); @@ -15,7 +15,7 @@ IriSP.JSONSerializer.prototype.sync = function(callback) { /* we don't have to do much because jQuery handles json for us */ - + /* a wrapper to get a closure because we lose this in callbacks */ var wrapper = function(obj) { return function(data) { diff -r 3ce493c93d6c -r f3fec80dd31c unittests/mockSerializer.js --- a/unittests/mockSerializer.js Mon Oct 24 16:51:22 2011 +0200 +++ b/unittests/mockSerializer.js Mon Oct 24 17:25:54 2011 +0200 @@ -1,7 +1,7 @@ /* mock serializer, for unit testing. This file is separated from data.js because the stub data is huge an we don't want to ship it with the rest of the app */ - + IriSP.MockSerializer = function(DataLoader, url) { IriSP.Serializer.call(this, DataLoader, url); @@ -1462,6 +1462,8 @@ }; }; +IriSP.MockSerializer.prototype = new IriSP.Serializer(); + IriSP.MockSerializer.prototype.currentMedia = function() { return this._data.medias[0]; }; diff -r 3ce493c93d6c -r f3fec80dd31c unittests/tests/serializerFactory.js --- a/unittests/tests/serializerFactory.js Mon Oct 24 16:51:22 2011 +0200 +++ b/unittests/tests/serializerFactory.js Mon Oct 24 17:25:54 2011 +0200 @@ -7,15 +7,23 @@ test("test instantiation of a json serializer", function() { var factory = new IriSP.SerializerFactory(this.dt); - var config = {metadata : { load: "json", src : "/url" } }; + var config = { type: "json", src : "/url" }; var ser = factory.getSerializer(config); ok(ser instanceof IriSP.JSONSerializer, "returned object is instance of json serializer"); }); + + test("test instantiation of a dummy serializer", function() { + var factory = new IriSP.SerializerFactory(this.dt); + var config = { type: "dummy", src : "/url" }; + var ser = factory.getSerializer(config); + + ok(ser instanceof IriSP.MockSerializer, "returned object is instance of json serializer"); + }); test("test instantiation of a garbage serializer", function() { var factory = new IriSP.SerializerFactory(this.dt); - var config = {metadata : { load: "garbage", src : "/url" } }; + var config = {type: "garbage", src : "/url" }; var ser = factory.getSerializer(config); equal(ser, undefined, "returned object is undefined");