destroy.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. var assert = require('assert');
  2. var Adapter = require('../../../lib/adapter');
  3. var Support = require('../../support/bootstrap');
  4. describe('Unit Tests ::', function() {
  5. describe('Destroy', function() {
  6. // Test Setup
  7. before(function(done) {
  8. Support.Setup('test_destroy', function(err) {
  9. if (err) {
  10. return done(err);
  11. }
  12. // Seed the database with two simple records.
  13. Support.Seed('test_destroy', done);
  14. });
  15. });
  16. after(function(done) {
  17. Support.Teardown('test_destroy', done);
  18. });
  19. it('should ensure the record is actually deleted', function(done) {
  20. var query = {
  21. using: 'test_destroy',
  22. criteria: {
  23. where: {
  24. fieldA: 'foo_2'
  25. }
  26. }
  27. };
  28. Adapter.destroy('test', query, function(err) {
  29. if (err) {
  30. return done(err);
  31. }
  32. Adapter.find('test', query, function(err, results) {
  33. if (err) {
  34. return done(err);
  35. }
  36. assert.equal(results.length, 0);
  37. return done();
  38. });
  39. });
  40. });
  41. // Look into the bowels of the PG Driver and ensure the Create function handles
  42. // it's connections properly.
  43. it('should release it\'s connection when completed', function(done) {
  44. var manager = Adapter.datastores.test.manager;
  45. var preConnectionsAvailable = manager.pool._allConnections.length;
  46. var query = {
  47. using: 'test_destroy',
  48. criteria: {}
  49. };
  50. Adapter.destroy('test', query, function(err) {
  51. if (err) {
  52. return done(err);
  53. }
  54. var postConnectionsAvailable = manager.pool._allConnections.length;
  55. assert.equal(preConnectionsAvailable, postConnectionsAvailable);
  56. return done();
  57. });
  58. });
  59. });
  60. });