PageRenderTime 41ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/share/www/script/test/design_paths.js

http://github.com/apache/couchdb
JavaScript | 72 lines | 44 code | 9 blank | 19 comment | 8 complexity | cdd3da7d1d6f24797920f984bfcd3e96 MD5 | raw file
Possible License(s): BSD-3-Clause, Apache-2.0
  1. // Licensed under the Apache License, Version 2.0 (the "License"); you may not
  2. // use this file except in compliance with the License. You may obtain a copy of
  3. // the License at
  4. //
  5. // http://www.apache.org/licenses/LICENSE-2.0
  6. //
  7. // Unless required by applicable law or agreed to in writing, software
  8. // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  9. // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  10. // License for the specific language governing permissions and limitations under
  11. // the License.
  12. couchTests.design_paths = function(debug) {
  13. if (debug) debugger;
  14. var dbNames = ["test_suite_db", "test_suite_db/with_slashes"];
  15. for (var i=0; i < dbNames.length; i++) {
  16. var db = new CouchDB(dbNames[i]);
  17. var dbName = encodeURIComponent(dbNames[i]);
  18. db.deleteDb();
  19. db.createDb();
  20. // create a ddoc w bulk_docs
  21. db.bulkSave([{
  22. _id : "_design/test",
  23. views : {
  24. "testing" : {
  25. "map" : "function(){emit(1,1)}"
  26. }
  27. }
  28. }]);
  29. // ddoc is getable
  30. var xhr = CouchDB.request("GET", "/"+dbName+"/_design/test");
  31. var resp = JSON.parse(xhr.responseText);
  32. T(resp._id == "_design/test");
  33. // it's at 2 urls...
  34. var xhr = CouchDB.request("GET", "/"+dbName+"/_design%2Ftest");
  35. var resp = JSON.parse(xhr.responseText);
  36. T(resp._id == "_design/test");
  37. // ensure that views are addressable
  38. resp = db.view("test/testing")
  39. T(resp.total_rows == 0)
  40. // create a ddoc by putting to url with raw slash
  41. var xhr = CouchDB.request("PUT", "/"+dbName+"/_design/test2",{
  42. body : JSON.stringify({
  43. _id : "_design/test2",
  44. views : {
  45. "testing" : {
  46. "map" : "function(){emit(1,1)}"
  47. }
  48. }
  49. })
  50. });
  51. // ddoc is getable
  52. var xhr = CouchDB.request("GET", "/"+dbName+"/_design/test2");
  53. var resp = JSON.parse(xhr.responseText);
  54. T(resp._id == "_design/test2");
  55. // it's at 2 urls...
  56. var xhr = CouchDB.request("GET", "/"+dbName+"/_design%2Ftest2");
  57. var resp = JSON.parse(xhr.responseText);
  58. T(resp._id == "_design/test2");
  59. // ensure that views are addressable
  60. resp = db.view("test2/testing");
  61. T(resp.total_rows == 0);
  62. };
  63. };