PageRenderTime 43ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/test/javascript/tests/design_paths.js

http://github.com/apache/couchdb
JavaScript | 74 lines | 47 code | 8 blank | 19 comment | 8 complexity | ac2ab3332ce4f0b6d13697f77c2e6458 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.elixir = true;
  13. couchTests.design_paths = function(debug) {
  14. return console.log('done in test/elixir/test/design_paths.exs');
  15. if (debug) debugger;
  16. var db_name = get_random_db_name()
  17. var dbNames = [db_name, db_name + "/with_slashes"];
  18. for (var i=0; i < dbNames.length; i++) {
  19. var db = new CouchDB(dbNames[i]);
  20. var dbName = encodeURIComponent(dbNames[i]);
  21. db.createDb();
  22. // create a ddoc w bulk_docs
  23. db.bulkSave([{
  24. _id : "_design/test",
  25. views : {
  26. "testing" : {
  27. "map" : "function(){emit(1,1)}"
  28. }
  29. }
  30. }]);
  31. // ddoc is getable
  32. var xhr = CouchDB.request("GET", "/"+dbName+"/_design/test");
  33. var resp = JSON.parse(xhr.responseText);
  34. T(resp._id == "_design/test");
  35. // it's at 2 urls...
  36. var xhr = CouchDB.request("GET", "/"+dbName+"/_design%2Ftest");
  37. var resp = JSON.parse(xhr.responseText);
  38. T(resp._id == "_design/test");
  39. // ensure that views are addressable
  40. resp = db.view("test/testing")
  41. T(resp.total_rows == 0)
  42. // create a ddoc by putting to url with raw slash
  43. var xhr = CouchDB.request("PUT", "/"+dbName+"/_design/test2",{
  44. body : JSON.stringify({
  45. _id : "_design/test2",
  46. views : {
  47. "testing" : {
  48. "map" : "function(){emit(1,1)}"
  49. }
  50. }
  51. })
  52. });
  53. // ddoc is getable
  54. var xhr = CouchDB.request("GET", "/"+dbName+"/_design/test2");
  55. var resp = JSON.parse(xhr.responseText);
  56. T(resp._id == "_design/test2");
  57. // it's at 2 urls...
  58. var xhr = CouchDB.request("GET", "/"+dbName+"/_design%2Ftest2");
  59. var resp = JSON.parse(xhr.responseText);
  60. T(resp._id == "_design/test2");
  61. // ensure that views are addressable
  62. resp = db.view("test2/testing");
  63. T(resp.total_rows == 0);
  64. db.deleteDb();
  65. };
  66. };