Author: awiner
Date: Tue Feb 17 18:53:44 2009
New Revision: 745192
URL: http://svn.apache.org/viewvc?rev=745192&view=rev
Log:
SHINDIG-911: bugs about features/setprefs/setprefs.js
- Fix prefs setArray() function to call RPC
- Fix prefs setArray() function to handle number entries in the array, per its
docs
Also added a test for the setprefs feature code
Added:
incubator/shindig/trunk/features/setprefs/setprefstest.js
Modified:
incubator/shindig/trunk/features/pom.xml
incubator/shindig/trunk/features/setprefs/setprefs.js
Modified: incubator/shindig/trunk/features/pom.xml
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/features/pom.xml?rev=745192&r1=745191&r2=745192&view=diff
==============================================================================
--- incubator/shindig/trunk/features/pom.xml (original)
+++ incubator/shindig/trunk/features/pom.xml Tue Feb 17 18:53:44 2009
@@ -78,6 +78,7 @@
<source>core/util.js</source>
<source>core/prefs.js</source>
<source>core.io/io.js</source>
+ <source>setprefs/setprefs.js</source>
<source>views/views.js</source>
<source>opensocial-reference/opensocial.js</source>
<source>opensocial-reference/activity.js</source>
Modified: incubator/shindig/trunk/features/setprefs/setprefs.js
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/features/setprefs/setprefs.js?rev=745192&r1=745191&r2=745192&view=diff
==============================================================================
--- incubator/shindig/trunk/features/setprefs/setprefs.js (original)
+++ incubator/shindig/trunk/features/setprefs/setprefs.js Tue Feb 17 18:53:44
2009
@@ -48,6 +48,7 @@
null, // no callback
gadgets.util.getUrlParameters().ifpctok || 0 // Legacy IFPC "security".
].concat(Array.prototype.slice.call(arguments));
+
gadgets.rpc.call.apply(gadgets.rpc, args);
};
@@ -61,8 +62,10 @@
// We must escape pipe (|) characters to ensure that decoding in
// getArray actually works properly.
for (var i = 0, j = val.length; i < j; ++i) {
- val[i] = val[i].replace(/\|/g, "%7C");
+ if (typeof val[i] !== "number") {
+ val[i] = val[i].replace(/\|/g, "%7C");
+ }
}
- gadgets.Prefs.setInternal_(key, val.join('|'));
+ this.set(key, val.join('|'));
};
Added: incubator/shindig/trunk/features/setprefs/setprefstest.js
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/features/setprefs/setprefstest.js?rev=745192&view=auto
==============================================================================
--- incubator/shindig/trunk/features/setprefs/setprefstest.js (added)
+++ incubator/shindig/trunk/features/setprefs/setprefstest.js Tue Feb 17
18:53:44 2009
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * @fileoverview
+ *
+ * Unittests for the setprefs feature.
+ */
+
+function SetPrefsTest(name) {
+ TestCase.call(this, name);
+}
+
+SetPrefsTest.inherits(TestCase);
+
+SetPrefsTest.prototype.setUp = function() {
+ var that = this;
+ this.savedRpc = gadgets.rpc;
+ gadgets.rpc = {};
+ gadgets.rpc.call = function() {
+ that.rpcArguments = Array.prototype.slice.call(arguments);
+ }
+};
+
+SetPrefsTest.prototype.tearDown = function() {
+ this.rpcArguments = undefined;
+ gadgets.rpc = this.savedRpc;
+};
+
+SetPrefsTest.prototype.testSet = function() {
+ var pref = new gadgets.Prefs();
+ gadgets.Prefs.setInternal_('key', 100);
+ pref.set('key', 200);
+ this.assertEquals(200, pref.getInt('key'));
+
+ this.assertRpcCalled(null, 'set_pref', null, 0, 'key', 200);
+};
+
+SetPrefsTest.prototype.testSetArray = function() {
+ var pref = new gadgets.Prefs();
+ pref.setArray('array', ['foo', 'bar']);
+ var array = pref.getArray('array');
+ this.assertEquals(2, array.length);
+ this.assertEquals('foo', array[0]);
+ this.assertEquals('bar', array[1]);
+
+ this.assertRpcCalled(null, 'set_pref', null, 0, 'array', 'foo|bar');
+};
+
+SetPrefsTest.prototype.testSetArrayWithPipe = function() {
+ var pref = new gadgets.Prefs();
+ pref.setArray('array', ['foo', 'b|ar']);
+ var array = pref.getArray('array');
+ this.assertEquals(2, array.length);
+ this.assertEquals('foo', array[0]);
+ this.assertEquals('b|ar', array[1]);
+
+ this.assertRpcCalled(null, 'set_pref', null, 0, 'array', 'foo|b%7Car');
+};
+
+SetPrefsTest.prototype.testSetArrayWithNumbers = function() {
+ var pref = new gadgets.Prefs();
+ pref.setArray('array', [1, 2]);
+ var array = pref.getArray('array');
+ this.assertEquals(2, array.length);
+ this.assertEquals('1', array[0]);
+ this.assertEquals('2', array[1]);
+
+ this.assertRpcCalled(null, 'set_pref', null, 0, 'array', '1|2');
+};
+
+SetPrefsTest.prototype.assertRpcCalled = function() {
+ this.assertNotUndefined("RPC was not called.", this.rpcArguments);
+ this.assertEquals("RPC argument list not valid length.",
+ arguments.length, this.rpcArguments.length);
+
+ for (var i = 0; i < arguments.length; i++) {
+ this.assertEquals(arguments[i], this.rpcArguments[i]);
+ }
+};
+