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
Guillaume Royer
jio
Commits
ece651db
Commit
ece651db
authored
Apr 14, 2015
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
unionStorage: add support for attachments
parent
9273600e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
458 additions
and
5 deletions
+458
-5
src/jio.storage/unionstorage.js
src/jio.storage/unionstorage.js
+30
-0
test/jio.storage/unionstorage.tests.js
test/jio.storage/unionstorage.tests.js
+428
-5
No files found.
src/jio.storage/unionstorage.js
View file @
ece651db
...
...
@@ -211,6 +211,36 @@
return
RSVP
.
all
(
promise_list
);
};
UnionStorage
.
prototype
.
getAttachment
=
function
()
{
var
argument_list
=
arguments
,
context
=
this
;
return
this
.
_getWithStorageIndex
.
apply
(
this
,
arguments
)
.
push
(
function
(
result
)
{
var
sub_storage
=
context
.
_storage_list
[
result
[
0
]];
return
sub_storage
.
getAttachment
.
apply
(
sub_storage
,
argument_list
);
});
};
UnionStorage
.
prototype
.
putAttachment
=
function
()
{
var
argument_list
=
arguments
,
context
=
this
;
return
this
.
_getWithStorageIndex
.
apply
(
this
,
arguments
)
.
push
(
function
(
result
)
{
var
sub_storage
=
context
.
_storage_list
[
result
[
0
]];
return
sub_storage
.
putAttachment
.
apply
(
sub_storage
,
argument_list
);
});
};
UnionStorage
.
prototype
.
removeAttachment
=
function
()
{
var
argument_list
=
arguments
,
context
=
this
;
return
this
.
_getWithStorageIndex
.
apply
(
this
,
arguments
)
.
push
(
function
(
result
)
{
var
sub_storage
=
context
.
_storage_list
[
result
[
0
]];
return
sub_storage
.
removeAttachment
.
apply
(
sub_storage
,
argument_list
);
});
};
jIO
.
addStorage
(
'
union
'
,
UnionStorage
);
}(
jIO
,
RSVP
));
test/jio.storage/unionstorage.tests.js
View file @
ece651db
/*global Blob*/
/*jslint nomen: true */
(
function
(
jIO
,
QUnit
)
{
(
function
(
jIO
,
QUnit
,
Blob
)
{
"
use strict
"
;
var
test
=
QUnit
.
test
,
stop
=
QUnit
.
stop
,
...
...
@@ -9,7 +10,8 @@
deepEqual
=
QUnit
.
deepEqual
,
equal
=
QUnit
.
equal
,
module
=
QUnit
.
module
,
throws
=
QUnit
.
throws
;
throws
=
QUnit
.
throws
,
frozen_blob
=
new
Blob
([
"
foobar
"
]);
/////////////////////////////////////////////////////////////////
// Custom test substorage definition
...
...
@@ -35,6 +37,22 @@
equal
(
id
,
"
bar
"
,
"
allAttachments 200 called
"
);
return
{
attachmentname
:
{}};
};
Storage200
.
prototype
.
getAttachment
=
function
(
id
,
name
)
{
equal
(
id
,
"
bar
"
,
"
getAttachment 200 called
"
);
equal
(
name
,
"
foo
"
,
"
getAttachment 200 called
"
);
return
frozen_blob
;
};
Storage200
.
prototype
.
removeAttachment
=
function
(
id
,
name
)
{
equal
(
id
,
"
bar
"
,
"
removeAttachment 200 called
"
);
equal
(
name
,
"
foo
"
,
"
removeAttachment 200 called
"
);
return
"
deleted
"
;
};
Storage200
.
prototype
.
putAttachment
=
function
(
id
,
name
,
blob
)
{
equal
(
id
,
"
bar
"
,
"
putAttachment 200 called
"
);
equal
(
name
,
"
foo
"
,
"
putAttachment 200 called
"
);
deepEqual
(
blob
,
frozen_blob
,
"
putAttachment 200 called
"
);
return
"
stored
"
;
};
Storage200
.
prototype
.
put
=
function
(
id
,
param
)
{
equal
(
id
,
"
bar
"
,
"
put 200 called
"
);
deepEqual
(
param
,
{
"
title
"
:
"
foo
"
},
"
put 200 called
"
);
...
...
@@ -364,7 +382,7 @@
}]
});
jio
.
get
(
"
bar
"
)
jio
.
allAttachments
(
"
bar
"
)
.
fail
(
function
(
error
)
{
ok
(
error
instanceof
Error
);
equal
(
error
.
message
,
"
manually triggered error
"
);
...
...
@@ -391,7 +409,7 @@
}]
});
jio
.
get
(
"
bar
"
)
jio
.
allAttachments
(
"
bar
"
)
.
fail
(
function
(
error
)
{
ok
(
error
instanceof
Error
);
equal
(
error
.
message
,
"
manually triggered error
"
);
...
...
@@ -911,4 +929,409 @@
});
});
}(
jIO
,
QUnit
));
/////////////////////////////////////////////////////////////////
// unionStorage.getAttachment
/////////////////////////////////////////////////////////////////
module
(
"
unionStorage.getAttachment
"
);
test
(
"
getAttachment inexistent document
"
,
function
()
{
stop
();
expect
(
5
);
var
jio
=
jIO
.
createJIO
({
type
:
"
union
"
,
storage_list
:
[{
type
:
"
unionstorage404
"
},
{
type
:
"
unionstorage404
"
}]
});
jio
.
getAttachment
(
"
bar
"
,
"
foo
"
)
.
fail
(
function
(
error
)
{
ok
(
error
instanceof
jIO
.
util
.
jIOError
);
equal
(
error
.
message
,
"
Cannot find document
"
);
equal
(
error
.
status_code
,
404
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
getAttachment document on first storage
"
,
function
()
{
stop
();
expect
(
4
);
var
jio
=
jIO
.
createJIO
({
type
:
"
union
"
,
storage_list
:
[{
type
:
"
unionstorage200
"
},
{
type
:
"
unionstorage404
"
}]
});
jio
.
getAttachment
(
"
bar
"
,
"
foo
"
)
.
then
(
function
(
result
)
{
deepEqual
(
result
,
frozen_blob
,
"
Check Blob
"
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
getAttachment document on second storage
"
,
function
()
{
stop
();
expect
(
5
);
var
jio
=
jIO
.
createJIO
({
type
:
"
union
"
,
storage_list
:
[{
type
:
"
unionstorage404
"
},
{
type
:
"
unionstorage200
"
}]
});
jio
.
getAttachment
(
"
bar
"
,
"
foo
"
)
.
then
(
function
(
result
)
{
deepEqual
(
result
,
frozen_blob
,
"
Check Blob
"
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
getAttachment error on first storage
"
,
function
()
{
stop
();
expect
(
4
);
var
jio
=
jIO
.
createJIO
({
type
:
"
union
"
,
storage_list
:
[{
type
:
"
unionstorage500
"
},
{
type
:
"
unionstorage200
"
}]
});
jio
.
getAttachment
(
"
bar
"
,
"
foo
"
)
.
fail
(
function
(
error
)
{
ok
(
error
instanceof
Error
);
equal
(
error
.
message
,
"
manually triggered error
"
);
equal
(
error
.
status_code
,
undefined
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
getAttachment error on second storage
"
,
function
()
{
stop
();
expect
(
5
);
var
jio
=
jIO
.
createJIO
({
type
:
"
union
"
,
storage_list
:
[{
type
:
"
unionstorage404
"
},
{
type
:
"
unionstorage500
"
}]
});
jio
.
getAttachment
(
"
bar
"
,
"
foo
"
)
.
fail
(
function
(
error
)
{
ok
(
error
instanceof
Error
);
equal
(
error
.
message
,
"
manually triggered error
"
);
equal
(
error
.
status_code
,
undefined
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
/////////////////////////////////////////////////////////////////
// unionStorage.removeAttachment
/////////////////////////////////////////////////////////////////
module
(
"
unionStorage.removeAttachment
"
);
test
(
"
removeAttachment inexistent document
"
,
function
()
{
stop
();
expect
(
5
);
var
jio
=
jIO
.
createJIO
({
type
:
"
union
"
,
storage_list
:
[{
type
:
"
unionstorage404
"
},
{
type
:
"
unionstorage404
"
}]
});
jio
.
removeAttachment
(
"
bar
"
,
"
foo
"
)
.
fail
(
function
(
error
)
{
ok
(
error
instanceof
jIO
.
util
.
jIOError
);
equal
(
error
.
message
,
"
Cannot find document
"
);
equal
(
error
.
status_code
,
404
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
removeAttachment document on first storage
"
,
function
()
{
stop
();
expect
(
4
);
var
jio
=
jIO
.
createJIO
({
type
:
"
union
"
,
storage_list
:
[{
type
:
"
unionstorage200
"
},
{
type
:
"
unionstorage404
"
}]
});
jio
.
removeAttachment
(
"
bar
"
,
"
foo
"
)
.
then
(
function
(
result
)
{
equal
(
result
,
"
deleted
"
,
"
Check result
"
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
removeAttachment document on second storage
"
,
function
()
{
stop
();
expect
(
5
);
var
jio
=
jIO
.
createJIO
({
type
:
"
union
"
,
storage_list
:
[{
type
:
"
unionstorage404
"
},
{
type
:
"
unionstorage200
"
}]
});
jio
.
removeAttachment
(
"
bar
"
,
"
foo
"
)
.
then
(
function
(
result
)
{
equal
(
result
,
"
deleted
"
,
"
Check result
"
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
removeAttachment error on first storage
"
,
function
()
{
stop
();
expect
(
4
);
var
jio
=
jIO
.
createJIO
({
type
:
"
union
"
,
storage_list
:
[{
type
:
"
unionstorage500
"
},
{
type
:
"
unionstorage200
"
}]
});
jio
.
removeAttachment
(
"
bar
"
,
"
foo
"
)
.
fail
(
function
(
error
)
{
ok
(
error
instanceof
Error
);
equal
(
error
.
message
,
"
manually triggered error
"
);
equal
(
error
.
status_code
,
undefined
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
removeAttachment error on second storage
"
,
function
()
{
stop
();
expect
(
5
);
var
jio
=
jIO
.
createJIO
({
type
:
"
union
"
,
storage_list
:
[{
type
:
"
unionstorage404
"
},
{
type
:
"
unionstorage500
"
}]
});
jio
.
removeAttachment
(
"
bar
"
,
"
foo
"
)
.
fail
(
function
(
error
)
{
ok
(
error
instanceof
Error
);
equal
(
error
.
message
,
"
manually triggered error
"
);
equal
(
error
.
status_code
,
undefined
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
/////////////////////////////////////////////////////////////////
// unionStorage.putAttachment
/////////////////////////////////////////////////////////////////
module
(
"
unionStorage.putAttachment
"
);
test
(
"
putAttachment inexistent document
"
,
function
()
{
stop
();
expect
(
5
);
var
jio
=
jIO
.
createJIO
({
type
:
"
union
"
,
storage_list
:
[{
type
:
"
unionstorage404
"
},
{
type
:
"
unionstorage404
"
}]
});
jio
.
putAttachment
(
"
bar
"
,
"
foo
"
,
frozen_blob
)
.
fail
(
function
(
error
)
{
ok
(
error
instanceof
jIO
.
util
.
jIOError
);
equal
(
error
.
message
,
"
Cannot find document
"
);
equal
(
error
.
status_code
,
404
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
putAttachment document on first storage
"
,
function
()
{
stop
();
expect
(
5
);
var
jio
=
jIO
.
createJIO
({
type
:
"
union
"
,
storage_list
:
[{
type
:
"
unionstorage200
"
},
{
type
:
"
unionstorage404
"
}]
});
jio
.
putAttachment
(
"
bar
"
,
"
foo
"
,
frozen_blob
)
.
then
(
function
(
result
)
{
equal
(
result
,
"
stored
"
,
"
Check result
"
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
putAttachment document on second storage
"
,
function
()
{
stop
();
expect
(
6
);
var
jio
=
jIO
.
createJIO
({
type
:
"
union
"
,
storage_list
:
[{
type
:
"
unionstorage404
"
},
{
type
:
"
unionstorage200
"
}]
});
jio
.
putAttachment
(
"
bar
"
,
"
foo
"
,
frozen_blob
)
.
then
(
function
(
result
)
{
equal
(
result
,
"
stored
"
,
"
Check result
"
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
putAttachment error on first storage
"
,
function
()
{
stop
();
expect
(
4
);
var
jio
=
jIO
.
createJIO
({
type
:
"
union
"
,
storage_list
:
[{
type
:
"
unionstorage500
"
},
{
type
:
"
unionstorage200
"
}]
});
jio
.
putAttachment
(
"
bar
"
,
"
foo
"
,
frozen_blob
)
.
fail
(
function
(
error
)
{
ok
(
error
instanceof
Error
);
equal
(
error
.
message
,
"
manually triggered error
"
);
equal
(
error
.
status_code
,
undefined
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
putAttachment error on second storage
"
,
function
()
{
stop
();
expect
(
5
);
var
jio
=
jIO
.
createJIO
({
type
:
"
union
"
,
storage_list
:
[{
type
:
"
unionstorage404
"
},
{
type
:
"
unionstorage500
"
}]
});
jio
.
putAttachment
(
"
bar
"
,
"
foo
"
,
frozen_blob
)
.
fail
(
function
(
error
)
{
ok
(
error
instanceof
Error
);
equal
(
error
.
message
,
"
manually triggered error
"
);
equal
(
error
.
status_code
,
undefined
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
}(
jIO
,
QUnit
,
Blob
));
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