1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-22 17:02:17 -05:00

deleted local storage dao code and tests

This commit is contained in:
Tankred Hase 2013-05-31 13:05:12 +02:00
parent 09d4c1c56f
commit 9a7e87d33e
4 changed files with 0 additions and 94 deletions

View File

@ -1,55 +0,0 @@
/**
* Handles generic caching of JSON objects in LocalStorage
*/
app.dao.LocalStorageDAO = function(window) {
'use strict';
/**
* Stringifies an object literal to JSON and perists it
*/
this.persist = function(key, object) {
var json = JSON.stringify(object);
window.localStorage.setItem(key, json);
};
/**
* Fetches a json string from local storage by its key and parses it to an object literal
*/
this.read = function(key) {
var json = window.localStorage.getItem(key);
return JSON.parse(json);
};
/**
* List all the items of a certain type in local storage
* @param type [String] The type of item e.g. 'email'
*/
this.list = function(type) {
var i, key, json, list = [];
for (i = 0; i < window.localStorage.length; i++) {
key = window.localStorage.key(i);
if (key.indexOf(type) === 0) {
json = window.localStorage.getItem(key);
list.push(JSON.parse(json));
}
}
return list;
};
/**
* Removes an object liter from local storage by its key (delete)
*/
this.remove = function(key) {
window.localStorage.removeItem(key);
};
/**
* Clears the whole local storage cache
*/
this.clear = function() {
window.localStorage.clear();
};
};

View File

@ -45,7 +45,6 @@
<script src="../../src/js/crypto/crypto-batch.js"></script> <script src="../../src/js/crypto/crypto-batch.js"></script>
<script src="../../src/js/crypto/crypto.js"></script> <script src="../../src/js/crypto/crypto.js"></script>
<script src="../../src/js/dao/localstorage-dao.js"></script>
<script src="../../src/js/dao/lawnchair-dao.js"></script> <script src="../../src/js/dao/lawnchair-dao.js"></script>
<script src="../../src/js/dao/devicestorage.js"></script> <script src="../../src/js/dao/devicestorage.js"></script>
<script src="../../src/js/dao/cloudstorage-dao.js"></script> <script src="../../src/js/dao/cloudstorage-dao.js"></script>

View File

@ -45,7 +45,6 @@
<script src="../../src/js/crypto/crypto-batch.js"></script> <script src="../../src/js/crypto/crypto-batch.js"></script>
<script src="../../src/js/crypto/crypto.js"></script> <script src="../../src/js/crypto/crypto.js"></script>
<script src="../../src/js/dao/localstorage-dao.js"></script>
<script src="../../src/js/dao/lawnchair-dao.js"></script> <script src="../../src/js/dao/lawnchair-dao.js"></script>
<script src="../../src/js/dao/devicestorage.js"></script> <script src="../../src/js/dao/devicestorage.js"></script>
<script src="../../src/js/dao/cloudstorage-dao.js"></script> <script src="../../src/js/dao/cloudstorage-dao.js"></script>
@ -57,7 +56,6 @@
<script src="forge-test.js"></script> <script src="forge-test.js"></script>
<script src="aes-test.js"></script> <script src="aes-test.js"></script>
<script src="rsa-test.js"></script> <script src="rsa-test.js"></script>
<script src="localstorage-dao-test.js"></script>
<script src="lawnchair-dao-test.js"></script> <script src="lawnchair-dao-test.js"></script>
<script src="keychain-dao-test.js"></script> <script src="keychain-dao-test.js"></script>
<script src="crypto-test.js"></script> <script src="crypto-test.js"></script>

View File

@ -1,36 +0,0 @@
module("LocalStorage DAO");
test("CRUD object literal", 4, function() {
var dao = new app.dao.LocalStorageDAO(window);
// clear before test
dao.clear();
var key = 'type_asdf';
var data = {
name : 'testName',
type : 'testType'
};
// create
dao.persist(key, data);
// read
var read = dao.read(key);
equal(data.name, read.name, 'Create, Read');
// list all
var list = dao.list('type');
ok(list.length === 1, 'List');
// update
var newName = 'updatedName';
read.name = newName;
dao.persist(key, read);
var updated = dao.read(key);
equal(updated.name, newName, 'Update');
// delete
dao.remove(key);
equal(dao.read(key), null, 'Delete');
});