Skip to content
Open
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion lib/cradle/database/views.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ Database.prototype.view = function (path, options, callback) {
options = {};
}

path = path.split('/');
path = function(path) {
path = path.split('/');
path[0] !== '' || path.shift();
path[2] !== '' || path.pop();
return path;
}(path);
path = ['_design', path[0], '_view', path[1]].map(querystring.escape).join('/');

return this._getOrPostView(path, options, callback);
Expand Down
18 changes: 18 additions & 0 deletions test/database-view-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,24 @@ vows.describe('cradle/database/view').addBatch(
},
['mike', 'bill'],
3
),
'with leading slashes': shouldQueryView(
function(db) {
db.view('/pigs/all', this.callback);
},
['bill','mike','alex']
),
'with trailing slashes': shouldQueryView(
function(db) {
db.view('pigs/all/', this.callback);
},
['bill','mike','alex']
),
'with leading and trailing slashes': shouldQueryView(
function(db) {
db.view('/pigs/all/', this.callback);
},
['bill','mike','alex']
)
},
// same as the above test, but with a temporary view
Expand Down