Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 47 additions & 1 deletion test/javascript/tests/rewrite.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,20 @@ couchTests.rewrite = function(debug) {
{
"from": "/db/*",
"to": "../../*"
}
},
{
"from": "renamedRewriteKeyView",
"to": "_view/rewriteKeyView",
"query": {
"startkey": [
":by"
],
"endkey": [
":by",
{}
]
}
}
],
lists: {
simpleForm: stringFun(function(head, req) {
Expand Down Expand Up @@ -271,6 +284,14 @@ couchTests.rewrite = function(debug) {
emit(doc.b, doc.string);
}
})
},
rewriteKeyView: {
map: stringFun(function(doc){
if (doc.type == "complex") {
emit([doc.string], doc);
emit(['']);
}
})
}
}
}
Expand Down Expand Up @@ -413,6 +434,31 @@ couchTests.rewrite = function(debug) {
T(result['_id'] == "_design/test");
T(typeof(result['_revs_info']) === "object");

// COUCHDB-2722 - The keys from the rewrited query params of a view should be blank when not specified in the URL
// Rewrite start and end key with by parameter
base_url = "/"+dbName+"/_design/test/"
view_url = base_url + "_view/rewriteKeyView"
rewrited_view_url = base_url + "_rewrite/renamedRewriteKeyView"

// When by = 'doc 3'
xhr = CouchDB.request("GET", rewrited_view_url + "?by=doc%203");
T(xhr.status == 200, "with by query param = value");
var result = JSON.parse(xhr.responseText);
T(result.rows.length == 1);

// When by is blank
xhr = CouchDB.request("GET", rewrited_view_url + "?by=");
T(xhr.status == 200, "with by query param = null");
var result = JSON.parse(xhr.responseText);
T(result.rows.length == 5);

// When by is undefined
// the key startkey should be blank instead and not kept as :by instead
xhr = CouchDB.request("GET", rewrited_view_url);
T(xhr.status == 200, "on renamed view without any param");
var result = JSON.parse(xhr.responseText);
T(result.rows.length == 5);

// test path relative to server
designDoc.rewrites.push({
"from": "uuids",
Expand Down