Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
lucas.parsy
jio
Commits
cf923fa7
Commit
cf923fa7
authored
Dec 02, 2015
by
lucas.parsy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
corrected bugs in websqlstorage breaking rsvp queues.
added sinon spy tests in websqlstorage test file.
parent
b864cc1c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
698 additions
and
43 deletions
+698
-43
src/jio.storage/websqlstorage.js
src/jio.storage/websqlstorage.js
+48
-13
test/jio.storage/websqlstorage.tests.js
test/jio.storage/websqlstorage.tests.js
+650
-30
No files found.
src/jio.storage/websqlstorage.js
View file @
cf923fa7
...
...
@@ -37,7 +37,10 @@
});
}
function
createDatabase
(
db
)
{
function
initDatabase
(
that
)
{
var
db
=
that
.
_database
;
if
(
that
.
_base_created
===
true
)
{
return
;
}
that
.
_base_created
=
true
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
sqlExec
(
db
,
"
CREATE TABLE IF NOT EXISTS documents
"
+
...
...
@@ -89,7 +92,7 @@
throw
new
TypeError
(
"
blob_len parameter must be a number >= 20
"
);
}
this
.
_blob_length
=
spec
.
blob_length
||
2000000
;
createDatabase
(
this
.
_database
)
;
this
.
_base_created
=
false
;
}
function
addProperty
(
db
,
id
,
prop
,
value
)
{
...
...
@@ -109,11 +112,15 @@
websqlStorage
.
prototype
.
put
=
function
(
id
,
param
)
{
var
db
=
this
.
_database
,
that
=
this
,
dataString
=
JSON
.
stringify
(
param
),
i
,
arrayLen
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
initDatabase
(
that
);
})
.
push
(
function
()
{
return
sqlExec
(
db
,
"
INSERT OR REPLACE INTO
"
+
"
documents(id, data) VALUES(?,?)
"
,
...
...
@@ -139,9 +146,13 @@
};
websqlStorage
.
prototype
.
remove
=
function
(
id
)
{
var
db
=
this
.
_database
;
var
db
=
this
.
_database
,
that
=
this
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
initDatabase
(
that
);
})
.
push
(
function
()
{
return
sqlExec
(
db
,
"
DELETE FROM documents WHERE id = ?
"
,
[
id
]);
})
...
...
@@ -155,9 +166,13 @@
};
websqlStorage
.
prototype
.
get
=
function
(
id
)
{
var
db
=
this
.
_database
;
var
db
=
this
.
_database
,
that
=
this
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
initDatabase
(
that
);
})
.
push
(
function
()
{
return
sqlExec
(
db
,
"
SELECT data FROM documents WHERE id = ?
"
,
[
id
]);
})
...
...
@@ -170,9 +185,13 @@
};
websqlStorage
.
prototype
.
allAttachments
=
function
(
id
)
{
var
db
=
this
.
_database
;
var
db
=
this
.
_database
,
that
=
this
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
initDatabase
(
that
);
})
.
push
(
function
()
{
return
sqlExec
(
db
,
"
SELECT COUNT(*) FROM documents WHERE id = ?
"
,
[
id
]);
})
...
...
@@ -195,11 +214,10 @@
});
};
function
sendBlobPart
(
db
,
id
,
name
,
blob
,
nbSlice
)
{
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
jIO
.
util
.
readBlobAsDataURL
(
blob
);
})
function
sendBlobPart
(
db
,
id
,
name
,
blob
,
nbSlice
,
queue
)
{
queue
.
push
(
function
()
{
return
jIO
.
util
.
readBlobAsDataURL
(
blob
);
})
.
push
(
function
(
strBlob
)
{
strBlob
=
strBlob
.
currentTarget
.
result
;
return
sqlExec
(
db
,
"
INSERT INTO blob(id, attachment, part, blob)
"
+
...
...
@@ -209,9 +227,13 @@
websqlStorage
.
prototype
.
putAttachment
=
function
(
id
,
name
,
blob
)
{
var
db
=
this
.
_database
,
that
=
this
,
partSize
=
this
.
_blob_length
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
initDatabase
(
that
);
})
.
push
(
function
()
{
return
sqlExec
(
db
,
"
SELECT COUNT(*) FROM documents WHERE id = ?
"
,
[
id
]);
})
...
...
@@ -233,17 +255,20 @@
})
.
push
(
function
()
{
var
blobSize
=
blob
.
size
,
queue
=
new
RSVP
.
Queue
(),
i
,
index
;
for
(
i
=
0
,
index
=
0
;
i
<
blobSize
;
i
+=
partSize
,
index
+=
1
)
{
sendBlobPart
(
db
,
id
,
name
,
blob
.
slice
(
i
,
i
+
partSize
),
index
);
sendBlobPart
(
db
,
id
,
name
,
blob
.
slice
(
i
,
i
+
partSize
),
index
,
queue
);
}
return
queue
;
});
};
websqlStorage
.
prototype
.
getAttachment
=
function
(
id
,
name
,
options
)
{
var
db
=
this
.
_database
,
that
=
this
,
partSize
=
this
.
_blob_length
,
start
,
end
,
...
...
@@ -271,6 +296,9 @@
}
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
initDatabase
(
that
);
})
.
push
(
function
()
{
var
command
=
"
SELECT part, blob FROM blob WHERE id = ? AND
"
+
"
attachment = ? AND part >= ?
"
,
...
...
@@ -312,9 +340,12 @@
};
websqlStorage
.
prototype
.
removeAttachment
=
function
(
id
,
name
)
{
var
db
=
this
.
_database
;
var
db
=
this
.
_database
,
that
=
this
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
initDatabase
(
that
);
})
.
push
(
function
()
{
return
sqlExec
(
db
,
"
DELETE FROM attachment WHERE
"
+
"
id = ? AND attachment = ?
"
,
[
id
,
name
]);
...
...
@@ -333,6 +364,7 @@
websqlStorage
.
prototype
.
buildQuery
=
function
(
options
)
{
var
db
=
this
.
_database
,
that
=
this
,
query
=
"
SELECT id
"
;
if
(
options
===
undefined
)
{
options
=
{};
}
...
...
@@ -342,6 +374,9 @@
query
+=
"
FROM documents ORDER BY id
"
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
initDatabase
(
that
);
})
.
push
(
function
()
{
return
sqlExec
(
db
,
query
,
[]);
})
...
...
test/jio.storage/websqlstorage.tests.js
View file @
cf923fa7
/*jslint nomen: true */
/*global openDatabase, Blob*/
(
function
(
jIO
,
QUnit
,
openDatabase
,
Blob
)
{
/*global openDatabase, Blob
, sinon
*/
(
function
(
jIO
,
QUnit
,
openDatabase
,
Blob
,
sinon
)
{
"
use strict
"
;
var
test
=
QUnit
.
test
,
stop
=
QUnit
.
stop
,
...
...
@@ -14,6 +14,16 @@
db
=
openDatabase
(
'
jio:qunit
'
,
'
1.0
'
,
''
,
2
*
1024
*
1024
),
j
;
function
getSpy
()
{
return
new
RSVP
.
Promise
(
function
(
resolve
)
{
var
spy
;
db
.
transaction
(
function
(
tx
)
{
spy
=
sinon
.
spy
(
tx
.
constructor
.
prototype
,
"
executeSql
"
);
resolve
(
spy
);
});
});
}
function
exec
(
transac
,
args
)
{
return
new
RSVP
.
Promise
(
function
(
resolve
,
reject
)
{
db
.
transaction
(
function
(
tx
)
{
...
...
@@ -30,19 +40,67 @@
});
}
function
spyStorageCreation
(
context
)
{
var
eleven
=
false
;
if
(
context
.
spy
.
callCount
>=
12
)
{
eleven
=
true
;
}
equal
(
eleven
,
true
);
equal
(
context
.
spy
.
args
[
0
][
0
],
'
SELECT name FROM sqlite_master WHERE type ="table"
'
+
'
AND name != "__WebKitDatabaseInfoTable__"
'
);
equal
(
context
.
spy
.
args
[
1
][
0
],
'
DELETE FROM documents
'
);
equal
(
context
.
spy
.
args
[
2
][
0
],
'
DELETE FROM metadata
'
);
equal
(
context
.
spy
.
args
[
3
][
0
],
'
DELETE FROM attachment
'
);
equal
(
context
.
spy
.
args
[
4
][
0
],
'
DELETE FROM blob
'
);
equal
(
context
.
spy
.
args
[
5
][
0
],
'
CREATE TABLE IF NOT EXISTS documents(id VARCHAR PRIMARY
'
+
'
KEY NOT NULL, data TEXT)
'
);
equal
(
context
.
spy
.
args
[
6
][
0
],
'
CREATE TABLE IF NOT EXISTS metadata(doc VARCHAR, prop
'
+
'
VARCHAR, stringValue TEXT, nbrValue INT)
'
);
equal
(
context
.
spy
.
args
[
7
][
0
],
'
CREATE TABLE IF NOT EXISTS attachment(id VARCHAR, attachment
'
+
'
VARCHAR, CONSTRAINT un_id_attachment UNIQUE (id, attachment))
'
);
equal
(
context
.
spy
.
args
[
8
][
0
],
'
CREATE TABLE IF NOT EXISTS blob(id VARCHAR, attachment
'
+
'
VARCHAR, part INT, blob TEXT)
'
);
equal
(
context
.
spy
.
args
[
9
][
0
],
'
CREATE TRIGGER IF NOT EXISTS jIOremove BEFORE DELETE ON
'
+
'
documents FOR EACH ROW BEGIN DELETE FROM metadata WHERE
'
+
'
doc = OLD.id; DELETE FROM attachment WHERE id = OLD.id;END;
'
);
equal
(
context
.
spy
.
args
[
10
][
0
],
'
CREATE TRIGGER IF NOT EXISTS jIOupdate BEFORE INSERT ON
'
+
'
documents FOR EACH ROW BEGIN DELETE FROM metadata WHERE
'
+
'
doc = NEW.id;END;
'
);
equal
(
context
.
spy
.
args
[
11
][
0
],
'
CREATE TRIGGER IF NOT EXISTS jIOremoveAttachmentBEFORE DELETE ON
'
+
'
attachment FOR EACH ROW BEGIN DELETE from blob WHERE id = OLD.id
'
+
'
AND attachment = OLD.attachment;END;
'
);
}
function
deleteRow
(
it
,
queue
,
result
)
{
queue
.
push
(
function
()
{
return
exec
(
"
DELETE FROM
"
+
result
.
rows
[
it
].
name
);
});
}
function
deleteWebsql
()
{
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
exec
(
"
DELETE FROM documents
"
,
[]);
})
.
push
(
function
()
{
return
exec
(
"
DELETE FROM metadata
"
,
[]);
})
.
push
(
function
()
{
return
exec
(
"
DELETE FROM attachment
"
,
[]);
return
exec
(
'
SELECT name FROM sqlite_master WHERE
'
+
'
type ="table" AND name != "__WebKitDatabaseInfoTable__"
'
);
})
.
push
(
function
()
{
return
exec
(
"
DELETE FROM blob
"
,
[]);
.
push
(
function
(
result
)
{
var
i
,
len
=
result
.
rows
.
length
,
queue
=
new
RSVP
.
Queue
();
for
(
i
=
0
;
i
<
len
;
i
+=
1
)
{
deleteRow
(
i
,
queue
,
result
);
}
return
queue
;
});
}
...
...
@@ -85,15 +143,79 @@
type
:
"
websql
"
,
database
:
"
qunit
"
});
this
.
spy
=
getSpy
();
},
teardown
:
function
()
{
this
.
spy
.
restore
();
delete
this
.
spy
;
}
});
test
(
"
spy webSQL usage
"
,
function
()
{
var
context
=
this
;
stop
();
expect
(
15
);
context
.
spy
.
then
(
function
(
value
)
{
context
.
spy
=
value
;
return
;
})
.
then
(
function
()
{
return
deleteWebsql
();
})
.
then
(
function
()
{
return
context
.
jio
.
allDocs
();
})
.
then
(
function
()
{
spyStorageCreation
(
context
);
equal
(
context
.
spy
.
args
[
12
][
0
],
'
SELECT id FROM documents ORDER BY id
'
);
deepEqual
(
context
.
spy
.
args
[
12
][
1
],
[]);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
spy webSQL usage with include_docs
"
,
function
()
{
var
context
=
this
;
stop
();
expect
(
15
);
context
.
spy
.
then
(
function
(
value
)
{
context
.
spy
=
value
;
return
;
})
.
then
(
function
()
{
return
deleteWebsql
();
})
.
then
(
function
()
{
return
context
.
jio
.
allDocs
({
include_docs
:
true
});
})
.
then
(
function
()
{
spyStorageCreation
(
context
);
equal
(
context
.
spy
.
args
[
12
][
0
],
'
SELECT id, data AS doc FROM documents ORDER BY id
'
);
deepEqual
(
context
.
spy
.
args
[
12
][
1
],
[]);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
empty result
"
,
function
()
{
var
context
=
this
;
stop
();
expect
(
1
);
deleteWebsql
()
context
.
spy
.
then
(
function
(
value
)
{
context
.
spy
=
value
;
return
deleteWebsql
();
})
.
then
(
function
()
{
return
context
.
jio
.
allDocs
();
})
...
...
@@ -119,7 +241,10 @@
stop
();
expect
(
1
);
deleteWebsql
()
context
.
spy
.
then
(
function
(
value
)
{
context
.
spy
=
value
;
return
deleteWebsql
();
})
.
then
(
function
()
{
return
RSVP
.
all
([
context
.
jio
.
put
(
"
2
"
,
{
"
title
"
:
"
title2
"
}),
...
...
@@ -157,7 +282,10 @@
stop
();
expect
(
1
);
deleteWebsql
()
context
.
spy
.
then
(
function
(
value
)
{
context
.
spy
=
value
;
return
deleteWebsql
();
})
.
then
(
function
()
{
return
RSVP
.
all
([
context
.
jio
.
put
(
"
2
"
,
{
"
title
"
:
"
title2
"
}),
...
...
@@ -198,15 +326,61 @@
type
:
"
websql
"
,
database
:
"
qunit
"
});
this
.
spy
=
getSpy
();
},
teardown
:
function
()
{
this
.
spy
.
restore
();
delete
this
.
spy
;
}
});
test
(
"
spy webSQL usage
"
,
function
()
{
var
context
=
this
;
stop
();
expect
(
19
);
context
.
spy
.
then
(
function
(
value
)
{
context
.
spy
=
value
;
return
;
})
.
then
(
function
()
{
return
deleteWebsql
();
})
.
then
(
function
()
{
return
context
.
jio
.
put
(
"
foo
"
,
{
"
title
"
:
"
bar
"
});
})
.
then
(
function
()
{
return
context
.
jio
.
get
(
"
foo
"
);
})
.
then
(
function
()
{
equal
(
context
.
spy
.
args
[
12
][
0
],
'
INSERT OR REPLACE INTO documents(id, data) VALUES(?,?)
'
);
deepEqual
(
context
.
spy
.
args
[
12
][
1
],
[
'
foo
'
,
'
{"title":"bar"}
'
]);
equal
(
context
.
spy
.
args
[
13
][
0
],
'
INSERT INTO metadata(doc, prop, stringValue) VALUES(?, ?, ?)
'
);
deepEqual
(
context
.
spy
.
args
[
13
][
1
],
[
'
foo
'
,
'
title
'
,
'
bar
'
]);
equal
(
context
.
spy
.
args
[
14
][
0
],
'
SELECT data FROM documents WHERE id = ?
'
);
deepEqual
(
context
.
spy
.
args
[
14
][
1
],
[
'
foo
'
]);
spyStorageCreation
(
context
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
get inexistent document
"
,
function
()
{
var
context
=
this
;
stop
();
expect
(
3
);
deleteWebsql
()
context
.
spy
.
then
(
function
(
value
)
{
context
.
spy
=
value
;
return
deleteWebsql
();
})
.
then
(
function
()
{
return
context
.
jio
.
get
(
"
inexistent
"
);
})
...
...
@@ -230,7 +404,10 @@
stop
();
expect
(
1
);
deleteWebsql
()
context
.
spy
.
then
(
function
(
value
)
{
context
.
spy
=
value
;
return
deleteWebsql
();
})
.
then
(
function
()
{
return
context
.
jio
.
put
(
id
,
{
"
title
"
:
"
bar
"
});
})
...
...
@@ -258,7 +435,10 @@
stop
();
expect
(
1
);
deleteWebsql
()
context
.
spy
.
then
(
function
(
value
)
{
context
.
spy
=
value
;
return
deleteWebsql
();
})
.
then
(
function
()
{
return
context
.
jio
.
put
(
id
,
{
"
title
"
:
"
bar
"
});
})
...
...
@@ -290,15 +470,63 @@
type
:
"
websql
"
,
database
:
"
qunit
"
});
this
.
spy
=
getSpy
();
},
teardown
:
function
()
{
this
.
spy
.
restore
();
delete
this
.
spy
;
}
});
test
(
"
spy webSQL usage
"
,
function
()
{
var
context
=
this
;
stop
();
expect
(
21
);
context
.
spy
.
then
(
function
(
value
)
{
context
.
spy
=
value
;
return
;
})
.
then
(
function
()
{
return
deleteWebsql
();
})
.
then
(
function
()
{
return
context
.
jio
.
put
(
"
foo
"
,
{
"
title
"
:
"
bar
"
});
})
.
then
(
function
()
{
return
context
.
jio
.
allAttachments
(
"
foo
"
);
})
.
then
(
function
()
{
spyStorageCreation
(
context
);
equal
(
context
.
spy
.
args
[
12
][
0
],
'
INSERT OR REPLACE INTO documents(id, data) VALUES(?,?)
'
);
deepEqual
(
context
.
spy
.
args
[
12
][
1
],
[
'
foo
'
,
'
{"title":"bar"}
'
]);
equal
(
context
.
spy
.
args
[
13
][
0
],
'
INSERT INTO metadata(doc, prop, stringValue) VALUES(?, ?, ?)
'
);
deepEqual
(
context
.
spy
.
args
[
13
][
1
],
[
'
foo
'
,
'
title
'
,
'
bar
'
]);
equal
(
context
.
spy
.
args
[
14
][
0
],
'
SELECT COUNT(*) FROM documents WHERE id = ?
'
);
deepEqual
(
context
.
spy
.
args
[
14
][
1
],
[
'
foo
'
]);
equal
(
context
.
spy
.
args
[
15
][
0
],
'
SELECT attachment FROM attachment WHERE id = ?
'
);
deepEqual
(
context
.
spy
.
args
[
15
][
1
],
[
'
foo
'
]);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
get inexistent document
"
,
function
()
{
var
context
=
this
;
stop
();
expect
(
3
);
deleteWebsql
()
context
.
spy
.
then
(
function
(
value
)
{
context
.
spy
=
value
;
return
deleteWebsql
();
})
.
then
(
function
()
{
return
context
.
jio
.
allAttachments
(
"
inexistent
"
);
})
...
...
@@ -321,7 +549,10 @@
stop
();
expect
(
1
);
deleteWebsql
()
context
.
spy
.
then
(
function
(
value
)
{
context
.
spy
=
value
;
return
deleteWebsql
();
})
.
then
(
function
()
{
return
context
.
jio
.
put
(
id
,
{
"
title
"
:
"
bar
"
});
})
...
...
@@ -346,7 +577,10 @@
stop
();
expect
(
1
);
deleteWebsql
()
context
.
spy
.
then
(
function
(
value
)
{
context
.
spy
=
value
;
return
deleteWebsql
();
})
.
then
(
function
()
{
return
context
.
jio
.
put
(
id
,
{
"
title
"
:
"
bar
"
});
})
...
...
@@ -378,15 +612,58 @@
type
:
"
websql
"
,
database
:
"
qunit
"
});
this
.
spy
=
getSpy
();
},
teardown
:
function
()
{
this
.
spy
.
restore
();
delete
this
.
spy
;
}
});
test
(
"
spy webSQL usage
"
,
function
()
{
var
context
=
this
;
stop
();
expect
(
17
);
context
.
spy
.
then
(
function
(
value
)
{
context
.
spy
=
value
;
return
;
})
.
then
(
function
()
{
return
deleteWebsql
();
})
.
then
(
function
()
{
return
context
.
jio
.
put
(
"
foo
"
,
{
"
title
"
:
"
bar
"
});
})
.
then
(
function
()
{
return
context
.
jio
.
allAttachments
(
"
foo
"
);
})
.
then
(
function
()
{
spyStorageCreation
(
context
);
equal
(
context
.
spy
.
args
[
12
][
0
],
'
INSERT OR REPLACE INTO documents(id, data) VALUES(?,?)
'
);
deepEqual
(
context
.
spy
.
args
[
12
][
1
],
[
'
foo
'
,
'
{"title":"bar"}
'
]);
equal
(
context
.
spy
.
args
[
13
][
0
],
'
INSERT INTO metadata(doc, prop, stringValue) VALUES(?, ?, ?)
'
);
deepEqual
(
context
.
spy
.
args
[
13
][
1
],
[
'
foo
'
,
'
title
'
,
'
bar
'
]);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
put document
"
,
function
()
{
var
context
=
this
;
stop
();
expect
(
1
);
deleteWebsql
()
context
.
spy
.
then
(
function
(
value
)
{
context
.
spy
=
value
;
return
deleteWebsql
();
})
.
then
(
function
()
{
return
context
.
jio
.
put
(
"
inexistent
"
,
{});
})
...
...
@@ -410,16 +687,139 @@
type
:
"
websql
"
,
database
:
"
qunit
"
});
this
.
spy
=
getSpy
();
},
teardown
:
function
()
{
this
.
spy
.
restore
();
delete
this
.
spy
;
}
});
test
(
"
spy webSQL usage with one document
"
,
function
()
{
var
context
=
this
;
stop
();
expect
(
19
);
context
.
spy
.
then
(
function
(
value
)
{
context
.
spy
=
value
;
return
;
})
.
then
(
function
()
{
return
deleteWebsql
();
})
.
then
(
function
()
{
return
context
.
jio
.
put
(
"
foo
"
,
{
"
title
"
:
"
bar
"
});
})
.
then
(
function
()
{
return
context
.
jio
.
remove
(
"
foo
"
);
})
.
then
(
function
()
{
spyStorageCreation
(
context
);
equal
(
context
.
spy
.
args
[
12
][
0
],
'
INSERT OR REPLACE INTO documents(id, data) VALUES(?,?)
'
);
deepEqual
(
context
.
spy
.
args
[
12
][
1
],
[
'
foo
'
,
'
{"title":"bar"}
'
]);
equal
(
context
.
spy
.
args
[
13
][
0
],
'
INSERT INTO metadata(doc, prop, stringValue) VALUES(?, ?, ?)
'
);
deepEqual
(
context
.
spy
.
args
[
13
][
1
],
[
'
foo
'
,
'
title
'
,
'
bar
'
]);
equal
(
context
.
spy
.
args
[
14
][
0
],
'
DELETE FROM documents WHERE id = ?
'
);
deepEqual
(
context
.
spy
.
args
[
14
][
1
],
[
'
foo
'
]);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
spy webSQL usage with two attachments
"
,
function
()
{
var
context
=
this
;
stop
();
expect
(
39
);
context
.
spy
.
then
(
function
(
value
)
{
context
.
spy
=
value
;
return
;
})
.
then
(
function
()
{
return
deleteWebsql
();
})
.
then
(
function
()
{
return
context
.
jio
.
put
(
"
foo
"
,
{
"
title
"
:
"
bar
"
});
})
.
then
(
function
()
{
return
RSVP
.
all
([
context
.
jio
.
putAttachment
(
"
foo
"
,
"
attachment1
"
,
"
bar
"
),
context
.
jio
.
putAttachment
(
"
foo
"
,
"
attachment2
"
,
"
bar2
"
)
]);
})
.
then
(
function
()
{
return
context
.
jio
.
remove
(
"
foo
"
);
})
.
then
(
function
()
{
spyStorageCreation
(
context
);
equal
(
context
.
spy
.
args
[
12
][
0
],
'
INSERT OR REPLACE INTO documents(id, data) VALUES(?,?)
'
);
deepEqual
(
context
.
spy
.
args
[
12
][
1
],
[
'
foo
'
,
'
{"title":"bar"}
'
]);
equal
(
context
.
spy
.
args
[
13
][
0
],
'
INSERT INTO metadata(doc, prop, stringValue) VALUES(?, ?, ?)
'
);
deepEqual
(
context
.
spy
.
args
[
13
][
1
],
[
'
foo
'
,
'
title
'
,
'
bar
'
]);
equal
(
context
.
spy
.
args
[
14
][
0
],
'
SELECT COUNT(*) FROM documents WHERE id = ?
'
);
deepEqual
(
context
.
spy
.
args
[
14
][
1
],
[
'
foo
'
]);
equal
(
context
.
spy
.
args
[
15
][
0
],
'
SELECT COUNT(*) FROM documents WHERE id = ?
'
);
deepEqual
(
context
.
spy
.
args
[
15
][
1
],
[
'
foo
'
]);
equal
(
context
.
spy
.
args
[
16
][
0
],
'
INSERT OR REPLACE INTO attachment(id, attachment) VALUES(?, ?)
'
);
deepEqual
(
context
.
spy
.
args
[
16
][
1
],
[
'
foo
'
,
'
attachment1
'
]);
equal
(
context
.
spy
.
args
[
17
][
0
],
'
INSERT OR REPLACE INTO attachment(id, attachment) VALUES(?, ?)
'
);
deepEqual
(
context
.
spy
.
args
[
17
][
1
],
[
'
foo
'
,
'
attachment2
'
]);
equal
(
context
.
spy
.
args
[
18
][
0
],
'
DELETE FROM blob WHERE id = ? AND attachment = ?
'
);
deepEqual
(
context
.
spy
.
args
[
18
][
1
],
[
'
foo
'
,
'
attachment1
'
]);
equal
(
context
.
spy
.
args
[
19
][
0
],
'
DELETE FROM blob WHERE id = ? AND attachment = ?
'
);
deepEqual
(
context
.
spy
.
args
[
19
][
1
],
[
'
foo
'
,
'
attachment2
'
]);
equal
(
context
.
spy
.
args
[
20
][
0
],
'
INSERT INTO blob(id, attachment,
'
+
'
part, blob) VALUES(?, ?, ?, ?)
'
);
deepEqual
(
context
.
spy
.
args
[
20
][
1
],
[
'
foo
'
,
'
attachment1
'
,
-
1
,
'
text/plain;charset=utf-8
'
]);
equal
(
context
.
spy
.
args
[
21
][
0
],
'
INSERT INTO blob(id, attachment,
'
+
'
part, blob) VALUES(?, ?, ?, ?)
'
);
deepEqual
(
context
.
spy
.
args
[
21
][
1
],
[
'
foo
'
,
'
attachment2
'
,
-
1
,
'
text/plain;charset=utf-8
'
]);
equal
(
context
.
spy
.
args
[
22
][
0
],
'
INSERT INTO blob(id, attachment, part, blob)VALUES(?, ?, ?, ?)
'
);
deepEqual
(
context
.
spy
.
args
[
22
][
1
],
[
'
foo
'
,
'
attachment1
'
,
0
,
'
data:;base64,YmFy
'
]);
equal
(
context
.
spy
.
args
[
23
][
0
],
'
INSERT INTO blob(id, attachment, part, blob)VALUES(?, ?, ?, ?)
'
);
deepEqual
(
context
.
spy
.
args
[
23
][
1
],
[
'
foo
'
,
'
attachment2
'
,
0
,
'
data:;base64,YmFyMg==
'
]);
equal
(
context
.
spy
.
args
[
24
][
0
],
'
DELETE FROM documents WHERE id = ?
'
);
deepEqual
(
context
.
spy
.
args
[
24
][
1
],
[
'
foo
'
]);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
remove document
"
,
function
()
{
var
context
=
this
;
stop
();
expect
(
3
);
deleteWebsql
()
context
.
spy
.
then
(
function
(
value
)
{
context
.
spy
=
value
;
return
deleteWebsql
();
})
.
then
(
function
()
{
return
context
.
jio
.
put
(
"
foo
"
,
{});
})
...
...
@@ -457,16 +857,92 @@
database
:
"
qunit
"
,
blob_length
:
20
});
this
.
spy
=
getSpy
();
},
teardown
:
function
()
{
this
.
spy
.
restore
();
delete
this
.
spy
;
}
});
test
(
"
spy webSQL usage
"
,
function
()
{
var
context
=
this
;
stop
();
expect
(
31
);
context
.
spy
.
then
(
function
(
value
)
{
context
.
spy
=
value
;
return
;
})
.
then
(
function
()
{
return
deleteWebsql
();
})
.
then
(
function
()
{
return
context
.
jio
.
put
(
"
foo
"
,
{
"
title
"
:
"
bar
"
});
})
.
then
(
function
()
{
return
context
.
jio
.
putAttachment
(
"
foo
"
,
"
attachment
"
,
big_string
);
})
.
then
(
function
()
{
return
context
.
jio
.
getAttachment
(
"
foo
"
,
"
attachment
"
);
})
.
then
(
function
()
{
spyStorageCreation
(
context
);
equal
(
context
.
spy
.
args
[
12
][
0
],
'
INSERT OR REPLACE INTO documents(id, data) VALUES(?,?)
'
);
deepEqual
(
context
.
spy
.
args
[
12
][
1
],
[
'
foo
'
,
'
{"title":"bar"}
'
]);
equal
(
context
.
spy
.
args
[
13
][
0
],
'
INSERT INTO metadata(doc, prop, stringValue) VALUES(?, ?, ?)
'
);
deepEqual
(
context
.
spy
.
args
[
13
][
1
],
[
'
foo
'
,
'
title
'
,
'
bar
'
]);
equal
(
context
.
spy
.
args
[
14
][
0
],
'
SELECT COUNT(*) FROM documents WHERE id = ?
'
);
deepEqual
(
context
.
spy
.
args
[
14
][
1
],
[
'
foo
'
]);
equal
(
context
.
spy
.
args
[
15
][
0
],
'
INSERT OR REPLACE INTO attachment(id, attachment) VALUES(?, ?)
'
);
deepEqual
(
context
.
spy
.
args
[
15
][
1
],
[
'
foo
'
,
'
attachment
'
]);
equal
(
context
.
spy
.
args
[
16
][
0
],
'
DELETE FROM blob WHERE id = ? AND attachment = ?
'
);
deepEqual
(
context
.
spy
.
args
[
16
][
1
],
[
'
foo
'
,
'
attachment
'
]);
equal
(
context
.
spy
.
args
[
17
][
0
],
'
INSERT INTO blob(id, attachment, part, blob)
'
+
'
VALUES(?, ?, ?, ?)
'
);
deepEqual
(
context
.
spy
.
args
[
17
][
1
],
[
'
foo
'
,
'
attachment
'
,
-
1
,
'
text/plain;charset=utf-8
'
]);
equal
(
context
.
spy
.
args
[
18
][
0
],
'
INSERT INTO blob(id, attachment, part, blob)VALUES(?, ?, ?, ?)
'
);
deepEqual
(
context
.
spy
.
args
[
18
][
1
],
[
'
foo
'
,
'
attachment
'
,
0
,
'
data:;base64,YWFhYWFhYWFhYWFhYWFhYWFhYWE=
'
]);
equal
(
context
.
spy
.
args
[
19
][
0
],
'
INSERT INTO blob(id, attachment, part, blob)VALUES(?, ?, ?, ?)
'
);
deepEqual
(
context
.
spy
.
args
[
19
][
1
],
[
'
foo
'
,
'
attachment
'
,
1
,
'
data:;base64,YWFhYWFhYWFhYWFhYWFhYWFhYWE=
'
]);
equal
(
context
.
spy
.
args
[
20
][
0
],
'
SELECT part, blob FROM blob WHERE id = ?
'
+
'
AND attachment = ? AND part >= ?
'
);
deepEqual
(
context
.
spy
.
args
[
20
][
1
],
[
'
foo
'
,
'
attachment
'
,
-
1
]);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
check result
"
,
function
()
{
var
context
=
this
,
attachment
=
"
attachment
"
;
stop
();
expect
(
3
);
deleteWebsql
()
context
.
spy
.
then
(
function
(
value
)
{
context
.
spy
=
value
;
return
deleteWebsql
();
})
.
then
(
function
()
{
return
context
.
jio
.
put
(
"
foo
"
,
{
"
title
"
:
"
bar
"
});
})
...
...
@@ -499,7 +975,10 @@
stop
();
expect
(
3
);
deleteWebsql
()
context
.
spy
.
then
(
function
(
value
)
{
context
.
spy
=
value
;
return
deleteWebsql
();
})
.
then
(
function
()
{
return
context
.
jio
.
put
(
"
foo
"
,
{
"
title
"
:
"
bar
"
});
})
...
...
@@ -537,16 +1016,87 @@
type
:
"
websql
"
,
database
:
"
qunit
"
});
this
.
spy
=
getSpy
();
},
teardown
:
function
()
{
this
.
spy
.
restore
();
delete
this
.
spy
;
}
});
test
(
"
spy webSQL usage
"
,
function
()
{
var
context
=
this
;
stop
();
expect
(
29
);
context
.
spy
.
then
(
function
(
value
)
{
context
.
spy
=
value
;
return
;
})
.
then
(
function
()
{
return
deleteWebsql
();
})
.
then
(
function
()
{
return
context
.
jio
.
put
(
"
foo
"
,
{
"
title
"
:
"
bar
"
});
})
.
then
(
function
()
{
return
context
.
jio
.
putAttachment
(
"
foo
"
,
"
attachment
"
,
big_string
);
})
.
then
(
function
()
{
return
context
.
jio
.
removeAttachment
(
"
foo
"
,
"
attachment
"
);
})
.
then
(
function
()
{
spyStorageCreation
(
context
);
equal
(
context
.
spy
.
args
[
12
][
0
],
'
INSERT OR REPLACE INTO documents(id, data) VALUES(?,?)
'
);
deepEqual
(
context
.
spy
.
args
[
12
][
1
],
[
'
foo
'
,
'
{"title":"bar"}
'
]);
equal
(
context
.
spy
.
args
[
13
][
0
],
'
INSERT INTO metadata(doc, prop, stringValue) VALUES(?, ?, ?)
'
);
deepEqual
(
context
.
spy
.
args
[
13
][
1
],
[
'
foo
'
,
'
title
'
,
'
bar
'
]);
equal
(
context
.
spy
.
args
[
14
][
0
],
'
SELECT COUNT(*) FROM documents WHERE id = ?
'
);
deepEqual
(
context
.
spy
.
args
[
14
][
1
],
[
'
foo
'
]);
equal
(
context
.
spy
.
args
[
15
][
0
],
'
INSERT OR REPLACE INTO attachment(id, attachment) VALUES(?, ?)
'
);
deepEqual
(
context
.
spy
.
args
[
15
][
1
],
[
'
foo
'
,
'
attachment
'
]);
equal
(
context
.
spy
.
args
[
16
][
0
],
'
DELETE FROM blob WHERE id = ? AND attachment = ?
'
);
deepEqual
(
context
.
spy
.
args
[
16
][
1
],
[
'
foo
'
,
'
attachment
'
]);
equal
(
context
.
spy
.
args
[
17
][
0
],
'
INSERT INTO blob(id, attachment, part, blob)
'
+
'
VALUES(?, ?, ?, ?)
'
);
deepEqual
(
context
.
spy
.
args
[
17
][
1
],
[
'
foo
'
,
'
attachment
'
,
-
1
,
'
text/plain;charset=utf-8
'
]);
equal
(
context
.
spy
.
args
[
18
][
0
],
'
INSERT INTO blob(id, attachment, part, blob)VALUES(?, ?, ?, ?)
'
);
deepEqual
(
context
.
spy
.
args
[
18
][
1
],
[
'
foo
'
,
'
attachment
'
,
0
,
"
data:;base64,YWFhYWFhYWFhYWFhYWFhYWF
"
+
"
hYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==
"
]);
equal
(
context
.
spy
.
args
[
19
][
0
],
'
DELETE FROM attachment WHERE id = ? AND attachment = ?
'
);
deepEqual
(
context
.
spy
.
args
[
19
][
1
],
[
'
foo
'
,
'
attachment
'
]);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
remove attachment
"
,
function
()
{
var
context
=
this
,
attachment
=
"
attachment
"
;
stop
();
expect
(
3
);
deleteWebsql
()
context
.
spy
.
then
(
function
(
value
)
{
context
.
spy
=
value
;
return
deleteWebsql
();
})
.
then
(
function
()
{
return
context
.
jio
.
put
(
"
foo
"
,
{
"
title
"
:
"
bar
"
});
})
...
...
@@ -558,7 +1108,7 @@
"
SELECT id, attachment FROM blob
"
,
[]);
})
.
then
(
function
(
selectResult
)
{
equal
(
selectResult
.
rows
.
length
,
2
,
"
putAttachment done
"
);
equal
(
selectResult
.
rows
.
length
,
3
,
"
putAttachment done
"
);
})
.
then
(
function
()
{
return
context
.
jio
.
removeAttachment
(
"
foo
"
,
attachment
);
...
...
@@ -586,18 +1136,88 @@
setup
:
function
()
{
this
.
jio
=
jIO
.
createJIO
({
type
:
"
websql
"
,
database
:
"
qunit
"
database
:
"
qunit
"
,
blob_length
:
20
});
this
.
spy
=
getSpy
();
},
teardown
:
function
()
{
this
.
spy
.
restore
();
delete
this
.
spy
;
}
});
test
(
"
spy webSQL usage
"
,
function
()
{
var
context
=
this
;
stop
();
expect
(
29
);
context
.
spy
.
then
(
function
(
value
)
{
context
.
spy
=
value
;
return
;
})
.
then
(
function
()
{
return
deleteWebsql
();
})
.
then
(
function
()
{
return
context
.
jio
.
put
(
"
foo
"
,
{
"
title
"
:
"
bar
"
});
})
.
then
(
function
()
{
return
context
.
jio
.
putAttachment
(
"
foo
"
,
"
attachment
"
,
big_string
);
})
.
then
(
function
()
{
spyStorageCreation
(
context
);
equal
(
context
.
spy
.
args
[
12
][
0
],
'
INSERT OR REPLACE INTO documents(id, data) VALUES(?,?)
'
);
deepEqual
(
context
.
spy
.
args
[
12
][
1
],
[
'
foo
'
,
'
{"title":"bar"}
'
]);
equal
(
context
.
spy
.
args
[
13
][
0
],
'
INSERT INTO metadata(doc, prop, stringValue) VALUES(?, ?, ?)
'
);
deepEqual
(
context
.
spy
.
args
[
13
][
1
],
[
'
foo
'
,
'
title
'
,
'
bar
'
]);
equal
(
context
.
spy
.
args
[
14
][
0
],
'
SELECT COUNT(*) FROM documents WHERE id = ?
'
);
deepEqual
(
context
.
spy
.
args
[
14
][
1
],
[
'
foo
'
]);
equal
(
context
.
spy
.
args
[
15
][
0
],
'
INSERT OR REPLACE INTO attachment(id, attachment) VALUES(?, ?)
'
);
deepEqual
(
context
.
spy
.
args
[
15
][
1
],
[
'
foo
'
,
'
attachment
'
]);
equal
(
context
.
spy
.
args
[
16
][
0
],
'
DELETE FROM blob WHERE id = ? AND attachment = ?
'
);
deepEqual
(
context
.
spy
.
args
[
16
][
1
],
[
'
foo
'
,
'
attachment
'
]);
equal
(
context
.
spy
.
args
[
17
][
0
],
'
INSERT INTO blob(id, attachment, part, blob)
'
+
'
VALUES(?, ?, ?, ?)
'
);
deepEqual
(
context
.
spy
.
args
[
17
][
1
],
[
'
foo
'
,
'
attachment
'
,
-
1
,
'
text/plain;charset=utf-8
'
]);
equal
(
context
.
spy
.
args
[
18
][
0
],
'
INSERT INTO blob(id, attachment, part, blob)VALUES(?, ?, ?, ?)
'
);
deepEqual
(
context
.
spy
.
args
[
18
][
1
],
[
'
foo
'
,
'
attachment
'
,
0
,
'
data:;base64,YWFhYWFhYWFhYWFhYWFhYWFhYWE=
'
]);
equal
(
context
.
spy
.
args
[
19
][
0
],
'
INSERT INTO blob(id, attachment, part, blob)VALUES(?, ?, ?, ?)
'
);
deepEqual
(
context
.
spy
.
args
[
19
][
1
],
[
'
foo
'
,
'
attachment
'
,
1
,
'
data:;base64,YWFhYWFhYWFhYWFhYWFhYWFhYWE=
'
]);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
put attachment
"
,
function
()
{
var
context
=
this
,
attachment
=
"
attachment
"
;
stop
();
expect
(
2
);
deleteWebsql
()
context
.
spy
.
then
(
function
(
value
)
{
context
.
spy
=
value
;
return
deleteWebsql
();
})
.
then
(
function
()
{
return
context
.
jio
.
put
(
"
foo
"
,
{
"
title
"
:
"
bar
"
});
})
...
...
@@ -609,7 +1229,7 @@
"
SELECT id, attachment FROM blob
"
,
[]);
})
.
then
(
function
(
selectResult
)
{
equal
(
selectResult
.
rows
.
length
,
2
,
"
putAttachment done
"
);
equal
(
selectResult
.
rows
.
length
,
4
,
"
putAttachment done
"
);
})
.
then
(
function
()
{
return
context
.
jio
.
getAttachment
(
"
foo
"
,
attachment
);
...
...
@@ -628,4 +1248,4 @@
});
});
}(
jIO
,
QUnit
,
openDatabase
,
Blob
));
\ No newline at end of file
}(
jIO
,
QUnit
,
openDatabase
,
Blob
,
sinon
));
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment