Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Bryan Kaperick
jio
Commits
b2948e5d
Commit
b2948e5d
authored
May 30, 2018
by
Bryan Kaperick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added additional testing of the revisions and removed extraneous tests.
parent
5762d991
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
402 deletions
+49
-402
src/jio.storage/bryanstorage.js
src/jio.storage/bryanstorage.js
+5
-2
test/jio.storage/bryanstorage.tests.js
test/jio.storage/bryanstorage.tests.js
+44
-400
No files found.
src/jio.storage/bryanstorage.js
View file @
b2948e5d
...
...
@@ -18,7 +18,6 @@
sub_storage
:
spec
.
sub_storage
}
});
}
BryanStorage
.
prototype
.
get
=
function
(
id_in
)
{
...
...
@@ -28,7 +27,7 @@
sort_on
:
[[
'
_revision
'
,
'
descending
'
]]
//include_docs: true
};
return
this
.
_sub_storage
.
allDocs
(
options
)
return
this
.
allDocs
(
options
)
// Return query results if there are any, else throw error
.
push
(
function
(
query_results
)
{
var
docs
=
query_results
.
data
.
rows
;
...
...
@@ -71,6 +70,10 @@
);
};
BryanStorage
.
prototype
.
allDocs
=
function
()
{
return
this
.
_sub_storage
.
allDocs
.
apply
(
this
.
_sub_storage
,
arguments
);
};
BryanStorage
.
prototype
.
allAttachments
=
function
()
{
return
this
.
_sub_storage
.
allAttachments
.
apply
(
this
.
_sub_storage
,
arguments
);
};
...
...
test/jio.storage/bryanstorage.tests.js
View file @
b2948e5d
/*jslint nomen: true*/
/*global Blob, jiodate*/
(
function
(
jIO
,
QUnit
,
Blob
)
{
(
function
(
jIO
,
QUnit
)
{
"
use strict
"
;
var
test
=
QUnit
.
test
,
stop
=
QUnit
.
stop
,
...
...
@@ -29,204 +29,10 @@
});
/////////////////////////////////////////////////////////////////
// bryanStorage.get
/////////////////////////////////////////////////////////////////
module
(
"
bryanStorage.get
"
);
test
(
"
get called substorage get
"
,
function
()
{
stop
();
expect
(
2
);
// create storage of type "bryan" with memory as substorage
var
jio
=
jIO
.
createJIO
({
type
:
"
bryan
"
,
sub_storage
:
{
type
:
"
memory
"
}
});
jio
.
put
(
"
bar
"
,
{
"
title
"
:
"
foo
"
});
jio
.
get
(
"
bar
"
)
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
"
title
"
:
"
foo
"
,
"
_revision
"
:
0
},
"
Check document
"
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
jio
.
get
(
"
bar
"
)
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
"
title
"
:
"
foo
"
,
"
_revision
"
:
0
},
"
Check document
"
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
});
//.always(function () {
// start();
//});
});
/////////////////////////////////////////////////////////////////
// _revision parameter initialization
/////////////////////////////////////////////////////////////////
module
(
"
bryanStorage initialize _revision
"
);
test
(
"
verifying _revision updates correctly
"
,
function
()
{
stop
();
expect
(
2
);
// create storage of type "bryan" with memory as substorage
var
jio
=
jIO
.
createJIO
({
type
:
"
bryan
"
,
sub_storage
:
{
type
:
"
memory
"
}
});
jio
.
put
(
"
bar
"
,
{
"
title
"
:
"
foo
"
})
.
push
(
function
(
result
)
{
equal
(
result
,
"
bar
"
);
return
jio
.
get
(
"
bar
"
);
})
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
"
title
"
:
"
foo
"
,
"
_revision
"
:
0
},
"
Check document
"
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
/////////////////////////////////////////////////////////////////
// _revision parameter updating with put
/////////////////////////////////////////////////////////////////
module
(
"
bryanStorage _revision with put
"
);
test
(
"
verifying _revision updates correctly
"
,
function
()
{
stop
();
expect
(
1
);
// create storage of type "bryan" with memory as substorage
var
jio
=
jIO
.
createJIO
({
type
:
"
bryan
"
,
sub_storage
:
{
type
:
"
memory
"
}
});
jio
.
put
(
"
bar
"
,
{
"
title
"
:
"
foo
"
})
.
push
(
function
()
{
return
jio
.
put
(
"
bar
"
,
{
"
title2
"
:
"
foo2
"
});
})
.
push
(
function
()
{
return
jio
.
put
(
"
bar
"
,
{
"
title3
"
:
"
foo3
"
});
})
.
push
(
function
()
{
return
jio
.
get
(
"
bar
"
);
})
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
"
title3
"
:
"
foo3
"
,
"
_revision
"
:
2
},
"
Check document after initialization
"
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
/////////////////////////////////////////////////////////////////
// _revision parameter updating with putAttachment
/////////////////////////////////////////////////////////////////
module
(
"
bryanStorage _revision with putAttachment
"
);
test
(
"
verifying _revision updates correctly after putAttachment
"
,
function
()
{
stop
();
expect
(
1
);
// Create storage of type "bryan" with memory as substorage
var
jio
=
jIO
.
createJIO
({
type
:
"
bryan
"
,
sub_storage
:
{
type
:
"
memory
"
}
});
jio
.
put
(
"
bar
"
,
{
"
title
"
:
"
foo
"
})
// Put two unique attachments in the document
.
push
(
function
()
{
return
jio
.
putAttachment
(
"
bar
"
,
"
blob
"
,
new
Blob
([
"
text data
"
],
{
type
:
"
text/plain
"
})
);
})
.
push
(
function
()
{
return
jio
.
putAttachment
(
"
bar
"
,
"
blob2
"
,
new
Blob
([
"
more text data
"
],
{
type
:
"
text/plain
"
})
);
})
// Get metadata for document
.
push
(
function
()
{
return
jio
.
get
(
"
bar
"
);
})
// Verify "_revision" is incremented twice
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
"
title
"
:
"
foo
"
,
"
_revision
"
:
2
},
"
Check document after 2 revisions
"
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
}
);
/////////////////////////////////////////////////////////////////
// _revision parameter updating with removeAttachment
/////////////////////////////////////////////////////////////////
module
(
"
bryanStorage _revision with removeAttachment
"
);
test
(
"
verifying _revision updates correctly after removeAttachment
"
,
function
()
{
stop
();
expect
(
1
);
// create storage of type "bryan" with memory as substorage
var
jio
=
jIO
.
createJIO
({
type
:
"
bryan
"
,
sub_storage
:
{
type
:
"
memory
"
}
});
jio
.
put
(
"
bar
"
,
{
"
title
"
:
"
foo
"
})
.
push
(
function
()
{
return
jio
.
putAttachment
(
"
bar
"
,
"
blob
"
,
new
Blob
([
"
text data
"
],
{
type
:
"
text/plain
"
})
);
})
.
push
(
function
()
{
return
jio
.
putAttachment
(
"
bar
"
,
"
blob2
"
,
new
Blob
([
"
more text data
"
],
{
type
:
"
text/plain
"
})
);
})
.
push
(
function
()
{
return
jio
.
removeAttachment
(
"
bar
"
,
"
blob
"
);
})
.
push
(
function
()
{
return
jio
.
removeAttachment
(
"
bar
"
,
"
blob2
"
);
})
.
push
(
function
()
{
return
jio
.
get
(
"
bar
"
);
})
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
"
title
"
:
"
foo
"
,
"
_revision
"
:
4
},
"
Check document after 4 revisions
"
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
}
);
/////////////////////////////////////////////////////////////////
// _revision parameter updating with RSVP all
/////////////////////////////////////////////////////////////////
/**
module("bryanStorage _revision with RSVP all");
test("verifying _revision updates correctly when puts are done in parallel",
function () {
...
...
@@ -249,216 +55,21 @@
.fail(function (error) {ok(false, error); })
.always(function () {start(); });
});
**/
/////////////////////////////////////////////////////////////////
// bryanStorage.allAttachments
/////////////////////////////////////////////////////////////////
module
(
"
bryanStorage.allAttachments
"
);
test
(
"
allAttachments called substorage allAttachments
"
,
function
()
{
stop
();
expect
(
2
);
var
jio
=
jIO
.
createJIO
({
type
:
"
bryan
"
,
sub_storage
:
{
type
:
"
memory
"
}
});
jio
.
allAttachments
(
"
bar
"
)
.
push
(
function
(
result
)
{
deepEqual
(
result
,
{
attachmentname
:
{}
},
"
Check document
"
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
/////////////////////////////////////////////////////////////////
// bryanStorage.post
/////////////////////////////////////////////////////////////////
module
(
"
bryanStorage.post
"
);
test
(
"
post called substorage post
"
,
function
()
{
stop
();
expect
(
2
);
var
jio
=
jIO
.
createJIO
({
type
:
"
bryan
"
,
sub_storage
:
{
type
:
"
memory
"
}
});
jio
.
post
({
"
title
"
:
"
foo
"
})
.
push
(
function
(
result
)
{
equal
(
result
,
"
youhou
"
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
/////////////////////////////////////////////////////////////////
// bryanStorage.put
/////////////////////////////////////////////////////////////////
module
(
"
bryanStorage.put
"
);
test
(
"
put called substorage put
"
,
function
()
{
stop
();
expect
(
3
);
var
jio
=
jIO
.
createJIO
({
type
:
"
bryan
"
,
sub_storage
:
{
type
:
"
memory
"
}
});
// If .put does not give the appropriate return, fail assertion
jio
.
put
(
"
bar
"
,
{
"
title
"
:
"
foo
"
})
.
push
(
function
(
result
)
{
equal
(
result
,
"
bar
"
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
/////////////////////////////////////////////////////////////////
// bryanStorage.remove
/////////////////////////////////////////////////////////////////
module
(
"
bryanStorage.remove
"
);
test
(
"
remove called substorage remove
"
,
function
()
{
stop
();
expect
(
2
);
var
jio
=
jIO
.
createJIO
({
type
:
"
bryan
"
,
sub_storage
:
{
type
:
"
memory
"
}
});
jio
.
remove
(
"
bar
"
)
.
push
(
function
(
result
)
{
equal
(
result
,
"
bar
"
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
/////////////////////////////////////////////////////////////////
// bryanStorage.getAttachment
/////////////////////////////////////////////////////////////////
module
(
"
bryanStorage.getAttachment
"
);
test
(
"
getAttachment called substorage getAttachment
"
,
function
()
{
stop
();
expect
(
3
);
var
jio
=
jIO
.
createJIO
({
type
:
"
bryan
"
,
sub_storage
:
{
type
:
"
memory
"
}
}),
blob
=
new
Blob
([
""
]);
jio
.
getAttachment
(
"
bar
"
,
"
foo
"
)
.
then
(
function
(
result
)
{
equal
(
result
,
blob
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
/////////////////////////////////////////////////////////////////
// bryanStorage.putAttachment
/////////////////////////////////////////////////////////////////
module
(
"
bryanStorage.putAttachment
"
);
test
(
"
putAttachment called substorage putAttachment
"
,
function
()
{
stop
();
expect
(
4
);
var
jio
=
jIO
.
createJIO
({
type
:
"
bryan
"
,
sub_storage
:
{
type
:
"
memory
"
}
}),
blob
=
new
Blob
([
""
]);
jio
.
putAttachment
(
"
bar
"
,
"
foo
"
,
blob
)
.
then
(
function
(
result
)
{
equal
(
result
,
"
OK
"
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
/////////////////////////////////////////////////////////////////
// bryanStorage.removeAttachment
/////////////////////////////////////////////////////////////////
module
(
"
bryanStorage.removeAttachment
"
);
test
(
"
removeAttachment called substorage removeAttachment
"
,
function
()
{
stop
();
expect
(
3
);
var
jio
=
jIO
.
createJIO
({
type
:
"
bryan
"
,
sub_storage
:
{
type
:
"
memory
"
}
});
jio
.
removeAttachment
(
"
bar
"
,
"
foo
"
)
.
then
(
function
(
result
)
{
equal
(
result
,
"
Removed
"
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
/////////////////////////////////////////////////////////////////
// bryanStorage revision history
/////////////////////////////////////////////////////////////////
module
(
"
bryanStorage
revision
history
"
);
module
(
"
bryanStorage
.revision_
history
"
);
test
(
"
put and get the correct version
"
,
function
()
{
stop
();
expect
(
1
);
var
jio
=
jIO
.
createJIO
({
type
:
"
bryan
"
,
sub_storage
:
{
type
:
"
indexeddb
"
,
database
:
"
newdb4
"
type
:
"
memory
"
//
database: "newdb4"
}
});
jio
.
put
(
"
doc1
"
,
{
...
...
@@ -482,15 +93,15 @@
});
});
module
(
"
bryanStorage
revision history multiple
edits
"
);
module
(
"
bryanStorage
.revision_history_multiple_
edits
"
);
test
(
"
modify first version but save both
"
,
function
()
{
stop
();
expect
(
2
);
expect
(
6
);
var
jio
=
jIO
.
createJIO
({
type
:
"
bryan
"
,
sub_storage
:
{
type
:
"
indexeddb
"
,
database
:
"
otherdb5
"
type
:
"
memory
"
//database: "otherdb8
"
}
});
jio
.
put
(
"
other_doc
"
,
{
...
...
@@ -539,6 +150,39 @@
"
_doc_id
"
:
"
other_doc
"
},
"
Retrieve other document correctly
"
);
})
.
push
(
function
()
{
return
jio
.
allDocs
({
query
:
'
(_doc_id: "main_doc") AND (_revision: 0)
'
,
sort_on
:
[[
'
_revision
'
,
'
descending
'
]]
});
})
.
push
(
function
(
result
)
{
equal
(
result
.
length
,
1
,
"
Correct number of results returned
"
);
})
.
push
(
function
()
{
return
jio
.
allDocs
({
query
:
'
(_doc_id: "main_doc") AND (_revision: 1)
'
});
})
.
push
(
function
(
result
)
{
equal
(
result
.
length
,
1
,
"
Correct number of results returned
"
);
})
.
push
(
function
()
{
return
jio
.
allDocs
({
query
:
'
(_doc_id: "other_doc") AND (_revision: 0)
'
});
})
.
push
(
function
(
result
)
{
equal
(
result
.
length
,
1
,
"
Correct number of results returned
"
);
})
.
push
(
function
()
{
return
jio
.
allDocs
({
query
:
''
});
})
.
push
(
function
(
result
)
{
equal
(
result
.
length
,
5
,
"
Correct number of results returned
"
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
...
...
@@ -547,6 +191,6 @@
});
});
}(
jIO
,
QUnit
,
Blob
));
}(
jIO
,
QUnit
));
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