renames and inheritance bug fixes. popcorn-port
authorhamidouk
Mon, 24 Oct 2011 17:25:54 +0200
branchpopcorn-port
changeset 128 f3fec80dd31c
parent 127 3ce493c93d6c
child 129 296d9ddf9cc1
renames and inheritance bug fixes.
src/js/data.js
src/js/serializers/JSONSerializer.js
unittests/mockSerializer.js
unittests/tests/serializerFactory.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;
   }
--- 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) {    
--- 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];
 };
--- 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");