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
Yaxel Perez
jio
Commits
315da2d6
Commit
315da2d6
authored
Mar 10, 2015
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MemoryStorage.get now returns attachment list
parent
eab60f05
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
46 deletions
+43
-46
src/jio.storage/memorystorage.js
src/jio.storage/memorystorage.js
+16
-18
test/jio.storage/memorystorage.tests.js
test/jio.storage/memorystorage.tests.js
+27
-28
No files found.
src/jio.storage/memorystorage.js
View file @
315da2d6
...
...
@@ -33,7 +33,6 @@
this
.
_database
=
{};
}
MemoryStorage
.
prototype
.
put
=
function
(
metadata
)
{
if
(
!
this
.
_database
.
hasOwnProperty
(
metadata
.
_id
))
{
this
.
_database
[
metadata
.
_id
]
=
{
...
...
@@ -45,8 +44,13 @@
};
MemoryStorage
.
prototype
.
get
=
function
(
param
)
{
var
doc
,
key
,
found
=
false
,
attachments
=
{};
try
{
return
JSON
.
parse
(
this
.
_database
[
param
.
_id
].
doc
);
doc
=
JSON
.
parse
(
this
.
_database
[
param
.
_id
].
doc
);
}
catch
(
error
)
{
if
(
error
instanceof
TypeError
)
{
throw
new
jIO
.
util
.
jIOError
(
...
...
@@ -58,22 +62,16 @@
}
// XXX NotImplemented: list all attachments
// var doc = JSON.parse(this._database[param._id].doc),
// key,
// found = false,
// attachments = {};
//
// for (key in this._database[param._id].attachments) {
// if (this._database[param._id].attachments.hasOwnProperty(key)) {
// found = true;
// attachments[key] = {};
// }
// }
// if (found) {
// doc._attachments = attachments;
// }
// return doc;
for
(
key
in
this
.
_database
[
param
.
_id
].
attachments
)
{
if
(
this
.
_database
[
param
.
_id
].
attachments
.
hasOwnProperty
(
key
))
{
found
=
true
;
attachments
[
key
]
=
{};
}
}
if
(
found
)
{
doc
.
_attachments
=
attachments
;
}
return
doc
;
};
MemoryStorage
.
prototype
.
remove
=
function
(
param
)
{
...
...
test/jio.storage/memorystorage.tests.js
View file @
315da2d6
...
...
@@ -155,34 +155,33 @@
});
});
// test("get document with attachment", function () {
// var id = "putattmt1";
//
// this.jio.__storage._database[id] = {
// "doc": JSON.stringify({}),
// "attachments": {
// putattmt2: undefined
// }
// };
//
// stop();
// expect(1);
//
// this.jio.get({"_id": id})
// .then(function (result) {
// deepEqual(result, {
// "_id": id,
// "_attachment": {},
// "title": "myPost1"
// }, "Check document");
// })
// .fail(function (error) {
// ok(false, error);
// })
// .always(function () {
// start();
// });
// });
test
(
"
get document with attachment
"
,
function
()
{
var
id
=
"
putattmt1
"
;
this
.
jio
.
__storage
.
_database
[
id
]
=
{
"
doc
"
:
JSON
.
stringify
({}),
"
attachments
"
:
{
putattmt2
:
undefined
}
};
stop
();
expect
(
1
);
this
.
jio
.
get
({
"
_id
"
:
id
})
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
"
_id
"
:
id
,
"
_attachments
"
:
{
putattmt2
:
{}}
},
"
Check document
"
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
/////////////////////////////////////////////////////////////////
// memoryStorage.remove
...
...
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