mongo_browser 0.2.0.rc2 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. data/.gitignore +3 -1
  2. data/.rspec +1 -1
  3. data/.travis.yml +6 -1
  4. data/CHANGELOG.md +15 -0
  5. data/{grunt.js → Gruntfile.js} +10 -8
  6. data/Procfile +1 -0
  7. data/README.md +44 -2
  8. data/Rakefile +1 -12
  9. data/app/assets/images/ajax-loader.gif +0 -0
  10. data/app/assets/javascripts/app/controllers/{breadcrumbs.js.coffee → breadcrumbs_controller.js.coffee} +4 -7
  11. data/app/assets/javascripts/app/controllers/collections/index_controller.js.coffee +38 -0
  12. data/app/assets/javascripts/app/controllers/collections/stats_controller.js.coffee +17 -0
  13. data/app/assets/javascripts/app/controllers/{databases.js.coffee → databases/index_controller.js.coffee} +11 -15
  14. data/app/assets/javascripts/app/controllers/databases/stats_controller.js.coffee +15 -0
  15. data/app/assets/javascripts/app/controllers/documents/index_controller.js.coffee +54 -0
  16. data/app/assets/javascripts/app/controllers/documents/show_controller.js.coffee +38 -0
  17. data/app/assets/javascripts/app/controllers/main_controller.js.coffee +15 -0
  18. data/app/assets/javascripts/app/controllers/servers/show_controller.js.coffee +17 -0
  19. data/app/assets/javascripts/app/directives.js.coffee +23 -0
  20. data/app/assets/javascripts/app/filters.js.coffee +14 -1
  21. data/app/assets/javascripts/app/modules/alerts.js.coffee +58 -0
  22. data/app/assets/javascripts/app/modules/pager.js.coffee +2 -2
  23. data/app/assets/javascripts/app/modules/spinner.js.coffee +29 -0
  24. data/app/assets/javascripts/app/modules/table_filter.js.coffee +4 -4
  25. data/app/assets/javascripts/app/resources.js.coffee +14 -8
  26. data/app/assets/javascripts/app/services.js.coffee +11 -33
  27. data/app/assets/javascripts/application.js.coffee +62 -34
  28. data/app/assets/javascripts/application.test.js.coffee +5 -0
  29. data/app/assets/javascripts/compiled_templates.js.coffee +1 -0
  30. data/app/assets/javascripts/vendor.js.coffee +0 -1
  31. data/app/assets/stylesheets/application.css.scss +36 -18
  32. data/{public/index.html → app/views/index.erb} +8 -8
  33. data/bin/mongo_browser +2 -13
  34. data/config.ru +3 -1
  35. data/lib/mongo_browser.rb +1 -0
  36. data/lib/mongo_browser/api.rb +11 -0
  37. data/lib/mongo_browser/api/collections.rb +34 -0
  38. data/lib/mongo_browser/api/databases.rb +32 -0
  39. data/lib/mongo_browser/api/documents.rb +37 -0
  40. data/lib/mongo_browser/api/mongo.rb +41 -0
  41. data/lib/mongo_browser/application.rb +8 -174
  42. data/lib/mongo_browser/application/development.rb +32 -0
  43. data/lib/mongo_browser/cli.rb +48 -0
  44. data/lib/mongo_browser/entities.rb +43 -0
  45. data/lib/mongo_browser/models/collection.rb +7 -12
  46. data/lib/mongo_browser/models/document.rb +5 -1
  47. data/lib/mongo_browser/models/pager.rb +22 -9
  48. data/lib/mongo_browser/version.rb +1 -1
  49. data/mongo_browser.gemspec +22 -15
  50. data/package.json +30 -0
  51. data/public/ng/templates/alerts.html +6 -0
  52. data/public/ng/templates/collections/index.html +39 -0
  53. data/public/ng/templates/collections/stats.html +18 -0
  54. data/public/ng/templates/databases/index.html +35 -0
  55. data/public/ng/templates/databases/stats.html +18 -0
  56. data/public/ng/templates/documents/index.html +40 -0
  57. data/public/ng/templates/documents/show.html +17 -0
  58. data/{app/assets → public/ng}/templates/pager.html +0 -0
  59. data/{app/assets/templates/server_info.html → public/ng/templates/server/show.html} +1 -1
  60. data/{app/assets → public/ng}/templates/table_filter.html +0 -0
  61. data/script/ci_all +5 -1
  62. data/script/ci_e2e +5 -2
  63. data/script/ci_javascripts +1 -1
  64. data/script/ci_rspec +1 -1
  65. data/spec/javascripts/app/controllers/{breadcrumbs_spec.js.coffee → breadcrumbs_controller_spec.js.coffee} +1 -1
  66. data/spec/javascripts/app/controllers/collections/index_controller_spec.js.coffee +95 -0
  67. data/spec/javascripts/app/controllers/collections/stats_controller_spec.js.coffee +34 -0
  68. data/spec/javascripts/app/controllers/databases/index_controller_spec.js.coffee +93 -0
  69. data/spec/javascripts/app/controllers/databases/stats_controller_spec.js.coffee +30 -0
  70. data/spec/javascripts/app/controllers/documents/index_controller_spec.js.coffee +108 -0
  71. data/spec/javascripts/app/controllers/documents/show_controller_spec.js.coffee +94 -0
  72. data/spec/javascripts/app/controllers/{main_spec.js.coffee → main_controller_spec.js.coffee} +2 -2
  73. data/spec/javascripts/app/controllers/{server_info_spec.js.coffee → server/show_controller_spec.js.coffee} +5 -6
  74. data/spec/javascripts/app/directives_spec.js.coffee +108 -24
  75. data/spec/javascripts/app/filters_spec.js.coffee +31 -5
  76. data/spec/javascripts/app/modules/alerts_spec.js.coffee +138 -0
  77. data/spec/javascripts/app/modules/dialogs_spec.js.coffee +1 -2
  78. data/spec/javascripts/app/modules/pager_spec.js.coffee +0 -1
  79. data/spec/javascripts/app/modules/spinner_spec.js.coffee +65 -0
  80. data/spec/javascripts/app/modules/table_filter_spec.js.coffee +9 -9
  81. data/spec/javascripts/app/resources_spec.js.coffee +99 -0
  82. data/spec/javascripts/app/services_spec.js.coffee +31 -71
  83. data/spec/javascripts/config/{testacular-e2e.conf.js → karma-e2e.conf.js} +1 -1
  84. data/spec/javascripts/config/{testacular.conf.js → karma.conf.js} +2 -3
  85. data/spec/javascripts/e2e/collection_stats_scenario.js.coffee +12 -0
  86. data/spec/javascripts/e2e/collections_scenario.js.coffee +59 -20
  87. data/spec/javascripts/e2e/database_stats_scenario.js.coffee +11 -0
  88. data/spec/javascripts/e2e/databases_scenario.js.coffee +37 -36
  89. data/spec/javascripts/e2e/document_show_scenario.js.coffee +31 -0
  90. data/spec/javascripts/e2e/documents_pagination_scenario.js.coffee +33 -0
  91. data/spec/javascripts/e2e/documents_scenario.js.coffee +43 -4
  92. data/spec/javascripts/e2e/server_info_scenario.js.coffee +8 -2
  93. data/spec/javascripts/helpers/mocks.js.coffee +2 -0
  94. data/spec/javascripts/helpers_e2e/dsl.js.coffee +20 -0
  95. data/spec/javascripts/lib/angular-mocks.js +64 -16
  96. data/spec/javascripts/lib/angular-scenario.js +724 -561
  97. data/spec/javascripts/runner.html +5 -5
  98. data/spec/lib/api/collections_spec.rb +62 -0
  99. data/spec/lib/api/databases_spec.rb +58 -0
  100. data/spec/lib/api/documents_spec.rb +135 -0
  101. data/spec/lib/api/mongo_spec.rb +27 -0
  102. data/spec/lib/cli_spec.rb +19 -0
  103. data/spec/lib/entities_spec.rb +39 -0
  104. data/spec/lib/models/collection_spec.rb +16 -10
  105. data/spec/lib/models/database_spec.rb +4 -4
  106. data/spec/lib/models/document_spec.rb +5 -5
  107. data/spec/lib/models/pager_spec.rb +20 -11
  108. data/spec/spec_helper.rb +7 -15
  109. data/spec/support/api_example_group.rb +45 -0
  110. data/spec/support/fixtures.rb +10 -6
  111. data/spec/support/matchers/expose.rb +18 -0
  112. data/vendor/assets/javascripts/angular/angular-bootstrap.js +1 -1
  113. data/vendor/assets/javascripts/angular/angular-resource.js +78 -56
  114. data/vendor/assets/javascripts/angular/angular-sanitize.js +3 -1
  115. data/vendor/assets/javascripts/angular/angular.js +720 -404
  116. metadata +323 -183
  117. data/app/assets/javascripts/app.js.coffee +0 -8
  118. data/app/assets/javascripts/app/controllers.js.coffee +0 -2
  119. data/app/assets/javascripts/app/controllers/alerts.js.coffee +0 -12
  120. data/app/assets/javascripts/app/controllers/collections.js.coffee +0 -40
  121. data/app/assets/javascripts/app/controllers/documents.js.coffee +0 -49
  122. data/app/assets/javascripts/app/controllers/main.js.coffee +0 -10
  123. data/app/assets/javascripts/app/controllers/server_info.js.coffee +0 -14
  124. data/app/assets/javascripts/templates.js.coffee +0 -1
  125. data/app/assets/javascripts/templates/.gitkeep +0 -0
  126. data/app/assets/templates/collections.html +0 -53
  127. data/app/assets/templates/databases.html +0 -32
  128. data/app/assets/templates/documents.html +0 -45
  129. data/config-e2e.ru +0 -20
  130. data/spec/features/collections_list_spec.rb +0 -64
  131. data/spec/features/documents_list_spec.rb +0 -139
  132. data/spec/features/server_info_spec.rb +0 -23
  133. data/spec/javascripts/app/controllers/alerts_spec.js.coffee +0 -36
  134. data/spec/javascripts/app/controllers/collections_spec.js.coffee +0 -78
  135. data/spec/javascripts/app/controllers/databases_spec.js.coffee +0 -55
  136. data/spec/javascripts/app/controllers/documents_spec.js.coffee +0 -62
  137. data/spec/javascripts/helpers_e2e/app_element.js.coffee +0 -6
  138. data/spec/support/feature_example_group.rb +0 -53
  139. data/spec/support/matchers/have_flash_message.rb +0 -16
  140. data/spec/support/mongod.rb +0 -91
  141. data/spec/support/mongodb.conf +0 -47
@@ -0,0 +1,17 @@
1
+ <header>
2
+ <h2>Document {{document.id}}</h2>
3
+ </header>
4
+
5
+
6
+ <table ng-hide="isLoading()" class="table table-striped table-hover documents">
7
+ <tbody>
8
+ <tr class="document">
9
+ <td class="data">
10
+ <span class="id">{{document.id}}</span>
11
+ <span>{{document | documentPrettyTime}}</span>
12
+ <refresh-button ng-click="refresh()" class="pull-right"></refresh-button>
13
+ <div ng-bind-html="document.data | jsonDocument"></div>
14
+ </td>
15
+ </tr>
16
+ </tbody>
17
+ </table>
@@ -2,7 +2,7 @@
2
2
  <h2>server info</h2>
3
3
  </header>
4
4
 
5
- <table class="table table-striped table-hover">
5
+ <table ng-hide="isLoading()" class="table table-striped table-hover">
6
6
  <thead>
7
7
  <tr>
8
8
  <th>Property</th>
@@ -12,7 +12,11 @@ echo -e "\nRunning e2e scenarios..\n"
12
12
  ./script/ci_e2e
13
13
  E2E_RESULT=$?
14
14
 
15
- if [ $RSPEC_RESULT -eq 1 -o $CUCUMBER_RESULT -eq 1 -o $JAVASCRIPTS_RESULT -eq 1 -o $E2E_RESULT -eq 1 ]; then
15
+ if [ "$RSPEC_RESULT" = 1 -o \
16
+ "$CUCUMBER_RESULT" = 1 -o \
17
+ "$JAVASCRIPTS_RESULT" = 1 -o \
18
+ "$E2E_RESULT" = 1 ]; then
19
+
16
20
  echo "error"
17
21
  exit 1
18
22
  else
@@ -1,9 +1,12 @@
1
1
  #!/bin/bash
2
2
 
3
3
  # Start test backend instance
4
- bundle exec thin start -R config-e2e.ru -e test -p 3001 -d
4
+ bundle exec thin start -R config.ru -e test -p 3001 -d
5
5
 
6
- testacular start spec/javascripts/config/testacular-e2e.conf.js --single-run
6
+ # Wait for thin
7
+ sleep 1
8
+
9
+ karma start spec/javascripts/config/karma-e2e.conf.js --single-run
7
10
  RESULT=$?
8
11
 
9
12
  # Kill test backend instance
@@ -1,4 +1,4 @@
1
1
  #!/bin/bash
2
2
 
3
3
  grunt html2js
4
- testacular start spec/javascripts/config/testacular.conf.js --single-run
4
+ karma start spec/javascripts/config/karma.conf.js --single-run
@@ -1,3 +1,3 @@
1
1
  #!/bin/bash
2
2
 
3
- bundle exec rspec spec/
3
+ bundle exec rspec spec/ --format documentation
@@ -1,5 +1,5 @@
1
1
  describe "breadcrumbs", ->
2
- beforeEach module("mb.controllers")
2
+ beforeEach module("mb")
3
3
 
4
4
  $scope = null
5
5
 
@@ -0,0 +1,95 @@
1
+ describe "collections index controller", ->
2
+ beforeEach module("mb")
3
+ beforeEach module("mocks")
4
+
5
+ controller = null
6
+ $scope = null
7
+
8
+ $httpBackend = null
9
+
10
+ beforeEach inject ($injector, $rootScope, $controller) ->
11
+ $routeParams = $injector.get("$routeParams")
12
+ $routeParams.dbName = "test_database"
13
+
14
+ $httpBackend = $injector.get("$httpBackend")
15
+ $httpBackend.whenGET("/api/databases/test_database/collections")
16
+ .respond([])
17
+
18
+ $scope = $rootScope.$new()
19
+ controller = $controller "collections.index",
20
+ $scope: $scope
21
+
22
+ $httpBackend.flush()
23
+
24
+ afterEach ->
25
+ $httpBackend.verifyNoOutstandingExpectation()
26
+ $httpBackend.verifyNoOutstandingRequest()
27
+
28
+ describe "$scope", ->
29
+
30
+ describe "$scope.isLoading", ->
31
+ it "returns true when the resouce it loading", ->
32
+ controller.loading = true
33
+ expect($scope.isLoading()).toBeTruthy()
34
+
35
+ it "otherwise returns false", ->
36
+ controller.loading = false
37
+ expect($scope.isLoading()).toBeFalsy()
38
+
39
+ describe "$scope.delete", ->
40
+ collection = null
41
+ dialogsHandler = null
42
+
43
+ beforeEach inject ($injector) ->
44
+ dialogsHandler = $injector.get("dialogsHandler")
45
+ collection = name: "dummy-collection-id"
46
+
47
+ it "shows the confirmation dialog", ->
48
+ spyOn(dialogsHandler, "confirm")
49
+ $scope.delete(collection)
50
+
51
+ expect(dialogsHandler.confirm).toHaveBeenCalledWith "Deleting dummy-collection-id. Are you sure?",
52
+ jasmine.any(Function)
53
+
54
+ describe "when the dialog was confirmed", ->
55
+ it "calls delete method", ->
56
+ spyOn(controller, "deleteWithConfirmation").andCallThrough()
57
+ spyOn(controller, "delete")
58
+
59
+ $scope.delete(collection)
60
+ dialogsHandler.confirmed()
61
+
62
+ expect(controller.deleteWithConfirmation).toHaveBeenCalledWith(collection)
63
+ expect(controller.delete).toHaveBeenCalledWith(collection)
64
+
65
+ describe "when the dialog was disposed", ->
66
+ it "does nothing", ->
67
+ spyOn(controller, "delete")
68
+
69
+ $scope.delete(collection)
70
+ dialogsHandler.disposed()
71
+
72
+ expect(controller.delete).not.toHaveBeenCalled()
73
+
74
+ describe "controller", ->
75
+
76
+ describe "controller.delete", ->
77
+ collection = null
78
+ alerts = null
79
+
80
+ beforeEach inject ($injector) ->
81
+ alerts = $injector.get("alerts")
82
+
83
+ collection = dbName: "test_database", name: "dummy-collection-id"
84
+ $httpBackend.whenDELETE("/api/databases/test_database/collections/dummy-collection-id")
85
+ .respond(true)
86
+
87
+ controller.delete(collection)
88
+
89
+ it "sends a delete request", ->
90
+ $httpBackend.flush()
91
+
92
+ it "displays a flash message", ->
93
+ spyOn(alerts, "info")
94
+ $httpBackend.flush()
95
+ expect(alerts.info).toHaveBeenCalledWith("Collection dummy-collection-id has been deleted.")
@@ -0,0 +1,34 @@
1
+ describe "collections stats controller", ->
2
+ beforeEach module("mb")
3
+
4
+ $scope = null
5
+ $httpBackend = null
6
+
7
+ beforeEach inject ($injector, $rootScope, $controller) ->
8
+ $routeParams = $injector.get("$routeParams")
9
+ $routeParams.dbName = "test_database"
10
+ $routeParams.collectionName = "test_collection"
11
+
12
+ $httpBackend = $injector.get("$httpBackend")
13
+ $httpBackend.whenGET("/api/databases/test_database/collections/test_collection/stats")
14
+ .respond(foo: "bar")
15
+
16
+ $scope = $rootScope.$new()
17
+ $controller "collections.stats",
18
+ $scope: $scope
19
+
20
+ $httpBackend.flush()
21
+
22
+ afterEach ->
23
+ $httpBackend.verifyNoOutstandingExpectation()
24
+ $httpBackend.verifyNoOutstandingRequest()
25
+
26
+ it "assings database name", ->
27
+ expect($scope.dbName).toEqual("test_database")
28
+
29
+ it "assings collection name", ->
30
+ expect($scope.collectionName).toEqual("test_collection")
31
+
32
+ it "fetches the collection stats", ->
33
+ expect($scope.stats).toBeDefined()
34
+ expect(angular.equals({ foo: "bar" }, $scope.stats)).toBeTruthy()
@@ -0,0 +1,93 @@
1
+ describe "databases index controller", ->
2
+ beforeEach module("mb")
3
+ beforeEach module("mocks")
4
+
5
+ controller = null
6
+ $scope = null
7
+
8
+ $httpBackend = null
9
+
10
+ beforeEach inject ($injector, $rootScope, $controller) ->
11
+ alerts = $injector.get("alerts")
12
+
13
+ $httpBackend = $injector.get("$httpBackend")
14
+ $httpBackend.whenGET("/api/databases").respond([])
15
+
16
+ $scope = $rootScope.$new()
17
+ controller = $controller "databases.index",
18
+ $scope: $scope
19
+
20
+ $httpBackend.flush()
21
+
22
+ afterEach ->
23
+ $httpBackend.verifyNoOutstandingExpectation()
24
+ $httpBackend.verifyNoOutstandingRequest()
25
+
26
+ describe "$scope", ->
27
+
28
+ describe "$scope.isLoading", ->
29
+ it "returns true when the resouce it loading", ->
30
+ controller.loading = true
31
+ expect($scope.isLoading()).toBeTruthy()
32
+
33
+ it "otherwise returns false", ->
34
+ controller.loading = false
35
+ expect($scope.isLoading()).toBeFalsy()
36
+
37
+ describe "$scope.delete", ->
38
+ database = null
39
+ dialogsHandler = null
40
+
41
+ beforeEach inject ($injector) ->
42
+ dialogsHandler = $injector.get("dialogsHandler")
43
+ database = name: "test_database"
44
+
45
+ it "shows the confirmation dialog", ->
46
+ spyOn(dialogsHandler, "confirm")
47
+ $scope.delete(database)
48
+
49
+ expect(dialogsHandler.confirm).toHaveBeenCalledWith "Deleting test_database. Are you sure?",
50
+ jasmine.any(Function)
51
+
52
+ describe "when the dialog was confirmed", ->
53
+ it "calls delete method", ->
54
+ spyOn(controller, "dropWithConfirmation").andCallThrough()
55
+ spyOn(controller, "drop")
56
+
57
+ $scope.delete(database)
58
+ dialogsHandler.confirmed()
59
+
60
+ expect(controller.dropWithConfirmation).toHaveBeenCalledWith(database)
61
+ expect(controller.drop).toHaveBeenCalledWith(database)
62
+
63
+ describe "when the dialog was disposed", ->
64
+ it "does nothing", ->
65
+ spyOn(controller, "drop")
66
+
67
+ $scope.delete(database)
68
+ dialogsHandler.disposed()
69
+
70
+ expect(controller.drop).not.toHaveBeenCalled()
71
+
72
+ describe "controller", ->
73
+
74
+ describe "controller.drop", ->
75
+ database = null
76
+ alerts = null
77
+
78
+ beforeEach inject ($injector) ->
79
+ alerts = $injector.get("alerts")
80
+
81
+ database = name: "test_database"
82
+ $httpBackend.whenDELETE("/api/databases/test_database")
83
+ .respond(true)
84
+
85
+ controller.drop(database)
86
+
87
+ it "sends a delete request", ->
88
+ $httpBackend.flush()
89
+
90
+ it "displays a flash message", ->
91
+ spyOn(alerts, "info")
92
+ $httpBackend.flush()
93
+ expect(alerts.info).toHaveBeenCalledWith("Database test_database has been deleted.")
@@ -0,0 +1,30 @@
1
+ describe "databases stats controller", ->
2
+ beforeEach module("mb")
3
+
4
+ $scope = null
5
+ $httpBackend = null
6
+
7
+ beforeEach inject ($injector, $rootScope, $controller) ->
8
+ $routeParams = $injector.get("$routeParams")
9
+ $routeParams.dbName = "test_database"
10
+
11
+ $httpBackend = $injector.get("$httpBackend")
12
+ $httpBackend.whenGET("/api/databases/test_database/stats")
13
+ .respond(foo: "bar")
14
+
15
+ $scope = $rootScope.$new()
16
+ $controller "databases.stats",
17
+ $scope: $scope
18
+
19
+ $httpBackend.flush()
20
+
21
+ afterEach ->
22
+ $httpBackend.verifyNoOutstandingExpectation()
23
+ $httpBackend.verifyNoOutstandingRequest()
24
+
25
+ it "assigns database name", ->
26
+ expect($scope.dbName).toEqual("test_database")
27
+
28
+ it "fetches the collection stats", ->
29
+ expect($scope.stats).toBeDefined()
30
+ expect(angular.equals({ foo: "bar" }, $scope.stats)).toBeTruthy()
@@ -0,0 +1,108 @@
1
+ describe "documents index controller", ->
2
+ beforeEach module("mb")
3
+ beforeEach module("mocks")
4
+
5
+ controller = null
6
+ $scope = null
7
+
8
+ $httpBackend = null
9
+
10
+ beforeEach inject ($injector, $rootScope, $controller) ->
11
+ alerts = $injector.get("alerts")
12
+
13
+ $routeParams = $injector.get("$routeParams")
14
+ $routeParams.dbName = "test_database"
15
+ $routeParams.collectionName = "test_collection"
16
+
17
+ $httpBackend = $injector.get("$httpBackend")
18
+ $httpBackend.whenGET("/api/databases/test_database/collections/test_collection/documents?page=1")
19
+ .respond([])
20
+
21
+ $scope = $rootScope.$new()
22
+ controller = $controller "documents.index",
23
+ $scope: $scope
24
+
25
+ $scope.$digest()
26
+ $httpBackend.flush()
27
+
28
+ afterEach ->
29
+ $httpBackend.verifyNoOutstandingExpectation()
30
+ $httpBackend.verifyNoOutstandingRequest()
31
+
32
+ describe "$scope", ->
33
+
34
+ describe "$scope.showDocuments", ->
35
+ it "returns true when the collection size is > 0", ->
36
+ $scope.size = 1
37
+ expect($scope.showDocuments()).toBeTruthy()
38
+
39
+ it "return false when the collection size is 0", ->
40
+ $scope.size = 0
41
+ expect($scope.showDocuments()).toBeFalsy()
42
+
43
+ describe "$scope.isLoading", ->
44
+ it "returns true when the resouce it loading", ->
45
+ controller.loading = true
46
+ expect($scope.isLoading()).toBeTruthy()
47
+
48
+ it "otherwise returns false", ->
49
+ controller.loading = false
50
+ expect($scope.isLoading()).toBeFalsy()
51
+
52
+ describe "$scope.delete", ->
53
+ document = null
54
+ dialogsHandler = null
55
+
56
+ beforeEach inject ($injector) ->
57
+ dialogsHandler = $injector.get("dialogsHandler")
58
+ document = {}
59
+
60
+ it "shows the confirmation dialog", ->
61
+ spyOn(dialogsHandler, "confirm")
62
+ $scope.delete(document)
63
+
64
+ expect(dialogsHandler.confirm).toHaveBeenCalledWith "Are you sure?",
65
+ jasmine.any(Function)
66
+
67
+ describe "when the dialog was confirmed", ->
68
+ it "calls delete method", ->
69
+ spyOn(controller, "deleteWithConfirmation").andCallThrough()
70
+ spyOn(controller, "delete")
71
+
72
+ $scope.delete(document)
73
+ dialogsHandler.confirmed()
74
+
75
+ expect(controller.deleteWithConfirmation).toHaveBeenCalledWith(document)
76
+ expect(controller.delete).toHaveBeenCalledWith(document)
77
+
78
+ describe "when the dialog was disposed", ->
79
+ it "does nothing", ->
80
+ spyOn(controller, "delete")
81
+
82
+ $scope.delete(document)
83
+ dialogsHandler.disposed()
84
+
85
+ expect(controller.delete).not.toHaveBeenCalled()
86
+
87
+ describe "controller", ->
88
+
89
+ describe "controller.delete", ->
90
+ document = null
91
+ alerts = null
92
+
93
+ beforeEach inject ($injector) ->
94
+ alerts = $injector.get("alerts")
95
+
96
+ document = id: "document-id"
97
+ $httpBackend.whenDELETE("/api/databases/test_database/collections/test_collection/documents/document-id")
98
+ .respond(true)
99
+
100
+ controller.delete(document)
101
+
102
+ it "sends a delete request", ->
103
+ $httpBackend.flush()
104
+
105
+ it "displays a flash message", ->
106
+ spyOn(alerts, "info")
107
+ $httpBackend.flush()
108
+ expect(alerts.info).toHaveBeenCalledWith("Document document-id has been deleted.")