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
amrani
jio
Commits
364f4190
Commit
364f4190
authored
Dec 08, 2014
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemente unionstorage allDocs
parent
efa69bc5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
304 additions
and
30 deletions
+304
-30
src/jio.storage/unionstorage.js
src/jio.storage/unionstorage.js
+54
-0
test/jio.storage/unionstorage.tests.js
test/jio.storage/unionstorage.tests.js
+250
-30
No files found.
src/jio.storage/unionstorage.js
View file @
364f4190
/*jslint nomen: true */
/*global RSVP*/
/**
* JIO Union Storage. Type = 'union'.
...
...
@@ -123,6 +124,59 @@
});
};
UnionStorage
.
prototype
.
buildQuery
=
function
()
{
var
promise_list
=
[],
i
,
id_dict
=
{},
len
=
this
.
_storage_list
.
length
,
sub_storage
;
for
(
i
=
0
;
i
<
len
;
i
+=
1
)
{
sub_storage
=
this
.
_storage_list
[
i
];
promise_list
.
push
(
sub_storage
.
buildQuery
.
apply
(
sub_storage
,
arguments
));
}
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
RSVP
.
all
(
promise_list
);
})
.
push
(
function
(
result_list
)
{
var
result
=
[],
sub_result
,
sub_result_len
,
j
;
len
=
result_list
.
length
;
for
(
i
=
0
;
i
<
len
;
i
+=
1
)
{
sub_result
=
result_list
[
i
];
sub_result_len
=
sub_result
.
length
;
for
(
j
=
0
;
j
<
sub_result_len
;
j
+=
1
)
{
if
(
!
id_dict
.
hasOwnProperty
(
sub_result
[
j
].
id
))
{
id_dict
[
sub_result
[
j
].
id
]
=
null
;
result
.
push
(
sub_result
[
j
]);
}
}
}
return
result
;
});
};
UnionStorage
.
prototype
.
hasCapacity
=
function
(
name
)
{
var
i
,
len
,
result
,
sub_storage
;
if
((
name
===
"
list
"
)
||
(
name
===
"
query
"
)
||
(
name
===
"
select
"
))
{
result
=
true
;
len
=
this
.
_storage_list
.
length
;
for
(
i
=
0
;
i
<
len
;
i
+=
1
)
{
sub_storage
=
this
.
_storage_list
[
i
];
result
=
result
&&
sub_storage
.
hasCapacity
(
name
);
}
return
result
;
}
return
false
;
};
jIO
.
addStorage
(
'
union
'
,
UnionStorage
);
}(
jIO
));
test/jio.storage/unionstorage.tests.js
View file @
364f4190
...
...
@@ -8,7 +8,8 @@
expect
=
QUnit
.
expect
,
deepEqual
=
QUnit
.
deepEqual
,
equal
=
QUnit
.
equal
,
module
=
QUnit
.
module
;
module
=
QUnit
.
module
,
throws
=
QUnit
.
throws
;
/////////////////////////////////////////////////////////////////
// Custom test substorage definition
...
...
@@ -21,7 +22,7 @@
throw
new
jIO
.
util
.
jIOError
(
"
Cannot find document
"
,
404
);
}
Storage404
.
prototype
.
get
=
generate404Error
;
jIO
.
addStorage
(
'
storage404
'
,
Storage404
);
jIO
.
addStorage
(
'
union
storage404
'
,
Storage404
);
function
Storage200
()
{
return
this
;
...
...
@@ -42,7 +43,38 @@
deepEqual
(
param
,
{
"
_id
"
:
"
bar
"
,
"
title
"
:
"
foo
"
},
"
post 200 called
"
);
return
param
.
_id
;
};
jIO
.
addStorage
(
'
storage200
'
,
Storage200
);
Storage200
.
prototype
.
hasCapacity
=
function
()
{
return
true
;
};
Storage200
.
prototype
.
buildQuery
=
function
(
options
)
{
deepEqual
(
options
,
{
query
:
'
title: "two"
'
},
"
buildQuery 200 called
"
);
return
[{
id
:
200
,
value
:
{
foo
:
"
bar
"
}
}];
};
jIO
.
addStorage
(
'
unionstorage200
'
,
Storage200
);
function
Storage200v2
()
{
return
this
;
}
Storage200v2
.
prototype
.
hasCapacity
=
function
()
{
return
true
;
};
Storage200v2
.
prototype
.
buildQuery
=
function
(
options
)
{
deepEqual
(
options
,
{
query
:
'
title: "two"
'
},
"
buildQuery 200v2 called
"
);
return
[{
id
:
"
200v2
"
,
value
:
{
bar
:
"
foo
"
}
}];
};
jIO
.
addStorage
(
'
unionstorage200v2
'
,
Storage200v2
);
function
Storage500
()
{
return
this
;
...
...
@@ -53,7 +85,7 @@
}
Storage500
.
prototype
.
get
=
generateError
;
Storage500
.
prototype
.
post
=
generateError
;
jIO
.
addStorage
(
'
storage500
'
,
Storage500
);
jIO
.
addStorage
(
'
union
storage500
'
,
Storage500
);
/////////////////////////////////////////////////////////////////
...
...
@@ -67,9 +99,9 @@
var
jio
=
jIO
.
createJIO
({
type
:
"
union
"
,
storage_list
:
[{
type
:
"
storage404
"
type
:
"
union
storage404
"
},
{
type
:
"
storage404
"
type
:
"
union
storage404
"
}]
});
...
...
@@ -94,9 +126,9 @@
var
jio
=
jIO
.
createJIO
({
type
:
"
union
"
,
storage_list
:
[{
type
:
"
storage200
"
type
:
"
union
storage200
"
},
{
type
:
"
storage404
"
type
:
"
union
storage404
"
}]
});
...
...
@@ -121,9 +153,9 @@
var
jio
=
jIO
.
createJIO
({
type
:
"
union
"
,
storage_list
:
[{
type
:
"
storage404
"
type
:
"
union
storage404
"
},
{
type
:
"
storage200
"
type
:
"
union
storage200
"
}]
});
...
...
@@ -148,9 +180,9 @@
var
jio
=
jIO
.
createJIO
({
type
:
"
union
"
,
storage_list
:
[{
type
:
"
storage500
"
type
:
"
union
storage500
"
},
{
type
:
"
storage200
"
type
:
"
union
storage200
"
}]
});
...
...
@@ -175,9 +207,9 @@
var
jio
=
jIO
.
createJIO
({
type
:
"
union
"
,
storage_list
:
[{
type
:
"
storage404
"
type
:
"
union
storage404
"
},
{
type
:
"
storage500
"
type
:
"
union
storage500
"
}]
});
...
...
@@ -206,9 +238,9 @@
var
jio
=
jIO
.
createJIO
({
type
:
"
union
"
,
storage_list
:
[{
type
:
"
storage500
"
type
:
"
union
storage500
"
},
{
type
:
"
storage200
"
type
:
"
union
storage200
"
}]
});
...
...
@@ -233,9 +265,9 @@
var
jio
=
jIO
.
createJIO
({
type
:
"
union
"
,
storage_list
:
[{
type
:
"
storage200
"
type
:
"
union
storage200
"
},
{
type
:
"
storage500
"
type
:
"
union
storage500
"
}]
});
...
...
@@ -262,9 +294,9 @@
var
jio
=
jIO
.
createJIO
({
type
:
"
union
"
,
storage_list
:
[{
type
:
"
storage500
"
type
:
"
union
storage500
"
},
{
type
:
"
storage200
"
type
:
"
union
storage200
"
}]
});
...
...
@@ -289,9 +321,9 @@
var
jio
=
jIO
.
createJIO
({
type
:
"
union
"
,
storage_list
:
[{
type
:
"
storage200
"
type
:
"
union
storage200
"
},
{
type
:
"
storage500
"
type
:
"
union
storage500
"
}]
});
...
...
@@ -314,9 +346,9 @@
var
jio
=
jIO
.
createJIO
({
type
:
"
union
"
,
storage_list
:
[{
type
:
"
storage404
"
type
:
"
union
storage404
"
},
{
type
:
"
storage200
"
type
:
"
union
storage200
"
}]
});
...
...
@@ -343,9 +375,9 @@
var
jio
=
jIO
.
createJIO
({
type
:
"
union
"
,
storage_list
:
[{
type
:
"
storage500
"
type
:
"
union
storage500
"
},
{
type
:
"
storage200
"
type
:
"
union
storage200
"
}]
});
...
...
@@ -370,9 +402,9 @@
var
jio
=
jIO
.
createJIO
({
type
:
"
union
"
,
storage_list
:
[{
type
:
"
storage200
"
type
:
"
union
storage200
"
},
{
type
:
"
storage500
"
type
:
"
union
storage500
"
}]
});
...
...
@@ -395,9 +427,9 @@
var
jio
=
jIO
.
createJIO
({
type
:
"
union
"
,
storage_list
:
[{
type
:
"
storage404
"
type
:
"
union
storage404
"
},
{
type
:
"
storage200
"
type
:
"
union
storage200
"
}]
});
...
...
@@ -413,5 +445,193 @@
});
});
/////////////////////////////////////////////////////////////////
// unionStorage.hasCapacity
/////////////////////////////////////////////////////////////////
module
(
"
unionStorage.hasCapacity
"
);
test
(
"
hasCapacity list without storage
"
,
function
()
{
var
jio
=
jIO
.
createJIO
({
type
:
"
union
"
,
storage_list
:
[]
});
ok
(
jio
.
hasCapacity
(
"
list
"
));
});
test
(
"
hasCapacity list not implemented in substorage
"
,
function
()
{
var
jio
=
jIO
.
createJIO
({
type
:
"
union
"
,
storage_list
:
[{
type
:
"
unionstorage200
"
},
{
type
:
"
unionstorage404
"
}]
});
throws
(
function
()
{
jio
.
hasCapacity
(
"
list
"
);
},
function
(
error
)
{
ok
(
error
instanceof
jIO
.
util
.
jIOError
);
equal
(
error
.
status_code
,
501
);
equal
(
error
.
message
,
"
Capacity 'list' is not implemented
"
);
return
true
;
}
);
});
test
(
"
hasCapacity list implemented in substorage
"
,
function
()
{
var
jio
=
jIO
.
createJIO
({
type
:
"
union
"
,
storage_list
:
[{
type
:
"
unionstorage200
"
},
{
type
:
"
unionstorage200
"
}]
});
ok
(
jio
.
hasCapacity
(
"
list
"
));
});
test
(
"
hasCapacity sort not manually done in union
"
,
function
()
{
var
jio
=
jIO
.
createJIO
({
type
:
"
union
"
,
storage_list
:
[{
type
:
"
unionstorage200
"
},
{
type
:
"
unionstorage200
"
}]
});
throws
(
function
()
{
jio
.
hasCapacity
(
"
sort
"
);
},
function
(
error
)
{
ok
(
error
instanceof
jIO
.
util
.
jIOError
);
equal
(
error
.
status_code
,
501
);
equal
(
error
.
message
,
"
Capacity 'sort' is not implemented
"
);
return
true
;
}
);
});
/////////////////////////////////////////////////////////////////
// unionStorage.allDocs
/////////////////////////////////////////////////////////////////
module
(
"
unionStorage.allDocs
"
);
test
(
"
allDocs remove duplicated keys
"
,
function
()
{
stop
();
expect
(
3
);
var
jio
=
jIO
.
createJIO
({
type
:
"
union
"
,
storage_list
:
[{
type
:
"
unionstorage200
"
},
{
type
:
"
unionstorage200
"
}]
});
jio
.
allDocs
({
query
:
'
title: "two"
'
})
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
data
:
{
rows
:
[{
id
:
200
,
value
:
{
foo
:
"
bar
"
}
}],
total_rows
:
1
}
});
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
allDocs concatenates results
"
,
function
()
{
stop
();
expect
(
3
);
var
jio
=
jIO
.
createJIO
({
type
:
"
union
"
,
storage_list
:
[{
type
:
"
unionstorage200v2
"
},
{
type
:
"
unionstorage200
"
}]
});
jio
.
allDocs
({
query
:
'
title: "two"
'
})
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
data
:
{
rows
:
[{
id
:
"
200v2
"
,
value
:
{
bar
:
"
foo
"
}
},
{
id
:
200
,
value
:
{
foo
:
"
bar
"
}
}],
total_rows
:
2
}
});
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
allDocs fails in one substorage fails
"
,
function
()
{
stop
();
expect
(
3
);
var
jio
=
jIO
.
createJIO
({
type
:
"
union
"
,
storage_list
:
[{
type
:
"
unionstorage200
"
},
{
type
:
"
unionstorage500
"
}]
});
jio
.
allDocs
({
query
:
'
title: "two"
'
})
.
fail
(
function
(
error
)
{
ok
(
error
instanceof
jIO
.
util
.
jIOError
);
equal
(
error
.
message
,
"
Capacity 'list' is not implemented
"
);
equal
(
error
.
status_code
,
501
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
}(
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