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.
- data/.gitignore +3 -1
- data/.rspec +1 -1
- data/.travis.yml +6 -1
- data/CHANGELOG.md +15 -0
- data/{grunt.js → Gruntfile.js} +10 -8
- data/Procfile +1 -0
- data/README.md +44 -2
- data/Rakefile +1 -12
- data/app/assets/images/ajax-loader.gif +0 -0
- data/app/assets/javascripts/app/controllers/{breadcrumbs.js.coffee → breadcrumbs_controller.js.coffee} +4 -7
- data/app/assets/javascripts/app/controllers/collections/index_controller.js.coffee +38 -0
- data/app/assets/javascripts/app/controllers/collections/stats_controller.js.coffee +17 -0
- data/app/assets/javascripts/app/controllers/{databases.js.coffee → databases/index_controller.js.coffee} +11 -15
- data/app/assets/javascripts/app/controllers/databases/stats_controller.js.coffee +15 -0
- data/app/assets/javascripts/app/controllers/documents/index_controller.js.coffee +54 -0
- data/app/assets/javascripts/app/controllers/documents/show_controller.js.coffee +38 -0
- data/app/assets/javascripts/app/controllers/main_controller.js.coffee +15 -0
- data/app/assets/javascripts/app/controllers/servers/show_controller.js.coffee +17 -0
- data/app/assets/javascripts/app/directives.js.coffee +23 -0
- data/app/assets/javascripts/app/filters.js.coffee +14 -1
- data/app/assets/javascripts/app/modules/alerts.js.coffee +58 -0
- data/app/assets/javascripts/app/modules/pager.js.coffee +2 -2
- data/app/assets/javascripts/app/modules/spinner.js.coffee +29 -0
- data/app/assets/javascripts/app/modules/table_filter.js.coffee +4 -4
- data/app/assets/javascripts/app/resources.js.coffee +14 -8
- data/app/assets/javascripts/app/services.js.coffee +11 -33
- data/app/assets/javascripts/application.js.coffee +62 -34
- data/app/assets/javascripts/application.test.js.coffee +5 -0
- data/app/assets/javascripts/compiled_templates.js.coffee +1 -0
- data/app/assets/javascripts/vendor.js.coffee +0 -1
- data/app/assets/stylesheets/application.css.scss +36 -18
- data/{public/index.html → app/views/index.erb} +8 -8
- data/bin/mongo_browser +2 -13
- data/config.ru +3 -1
- data/lib/mongo_browser.rb +1 -0
- data/lib/mongo_browser/api.rb +11 -0
- data/lib/mongo_browser/api/collections.rb +34 -0
- data/lib/mongo_browser/api/databases.rb +32 -0
- data/lib/mongo_browser/api/documents.rb +37 -0
- data/lib/mongo_browser/api/mongo.rb +41 -0
- data/lib/mongo_browser/application.rb +8 -174
- data/lib/mongo_browser/application/development.rb +32 -0
- data/lib/mongo_browser/cli.rb +48 -0
- data/lib/mongo_browser/entities.rb +43 -0
- data/lib/mongo_browser/models/collection.rb +7 -12
- data/lib/mongo_browser/models/document.rb +5 -1
- data/lib/mongo_browser/models/pager.rb +22 -9
- data/lib/mongo_browser/version.rb +1 -1
- data/mongo_browser.gemspec +22 -15
- data/package.json +30 -0
- data/public/ng/templates/alerts.html +6 -0
- data/public/ng/templates/collections/index.html +39 -0
- data/public/ng/templates/collections/stats.html +18 -0
- data/public/ng/templates/databases/index.html +35 -0
- data/public/ng/templates/databases/stats.html +18 -0
- data/public/ng/templates/documents/index.html +40 -0
- data/public/ng/templates/documents/show.html +17 -0
- data/{app/assets → public/ng}/templates/pager.html +0 -0
- data/{app/assets/templates/server_info.html → public/ng/templates/server/show.html} +1 -1
- data/{app/assets → public/ng}/templates/table_filter.html +0 -0
- data/script/ci_all +5 -1
- data/script/ci_e2e +5 -2
- data/script/ci_javascripts +1 -1
- data/script/ci_rspec +1 -1
- data/spec/javascripts/app/controllers/{breadcrumbs_spec.js.coffee → breadcrumbs_controller_spec.js.coffee} +1 -1
- data/spec/javascripts/app/controllers/collections/index_controller_spec.js.coffee +95 -0
- data/spec/javascripts/app/controllers/collections/stats_controller_spec.js.coffee +34 -0
- data/spec/javascripts/app/controllers/databases/index_controller_spec.js.coffee +93 -0
- data/spec/javascripts/app/controllers/databases/stats_controller_spec.js.coffee +30 -0
- data/spec/javascripts/app/controllers/documents/index_controller_spec.js.coffee +108 -0
- data/spec/javascripts/app/controllers/documents/show_controller_spec.js.coffee +94 -0
- data/spec/javascripts/app/controllers/{main_spec.js.coffee → main_controller_spec.js.coffee} +2 -2
- data/spec/javascripts/app/controllers/{server_info_spec.js.coffee → server/show_controller_spec.js.coffee} +5 -6
- data/spec/javascripts/app/directives_spec.js.coffee +108 -24
- data/spec/javascripts/app/filters_spec.js.coffee +31 -5
- data/spec/javascripts/app/modules/alerts_spec.js.coffee +138 -0
- data/spec/javascripts/app/modules/dialogs_spec.js.coffee +1 -2
- data/spec/javascripts/app/modules/pager_spec.js.coffee +0 -1
- data/spec/javascripts/app/modules/spinner_spec.js.coffee +65 -0
- data/spec/javascripts/app/modules/table_filter_spec.js.coffee +9 -9
- data/spec/javascripts/app/resources_spec.js.coffee +99 -0
- data/spec/javascripts/app/services_spec.js.coffee +31 -71
- data/spec/javascripts/config/{testacular-e2e.conf.js → karma-e2e.conf.js} +1 -1
- data/spec/javascripts/config/{testacular.conf.js → karma.conf.js} +2 -3
- data/spec/javascripts/e2e/collection_stats_scenario.js.coffee +12 -0
- data/spec/javascripts/e2e/collections_scenario.js.coffee +59 -20
- data/spec/javascripts/e2e/database_stats_scenario.js.coffee +11 -0
- data/spec/javascripts/e2e/databases_scenario.js.coffee +37 -36
- data/spec/javascripts/e2e/document_show_scenario.js.coffee +31 -0
- data/spec/javascripts/e2e/documents_pagination_scenario.js.coffee +33 -0
- data/spec/javascripts/e2e/documents_scenario.js.coffee +43 -4
- data/spec/javascripts/e2e/server_info_scenario.js.coffee +8 -2
- data/spec/javascripts/helpers/mocks.js.coffee +2 -0
- data/spec/javascripts/helpers_e2e/dsl.js.coffee +20 -0
- data/spec/javascripts/lib/angular-mocks.js +64 -16
- data/spec/javascripts/lib/angular-scenario.js +724 -561
- data/spec/javascripts/runner.html +5 -5
- data/spec/lib/api/collections_spec.rb +62 -0
- data/spec/lib/api/databases_spec.rb +58 -0
- data/spec/lib/api/documents_spec.rb +135 -0
- data/spec/lib/api/mongo_spec.rb +27 -0
- data/spec/lib/cli_spec.rb +19 -0
- data/spec/lib/entities_spec.rb +39 -0
- data/spec/lib/models/collection_spec.rb +16 -10
- data/spec/lib/models/database_spec.rb +4 -4
- data/spec/lib/models/document_spec.rb +5 -5
- data/spec/lib/models/pager_spec.rb +20 -11
- data/spec/spec_helper.rb +7 -15
- data/spec/support/api_example_group.rb +45 -0
- data/spec/support/fixtures.rb +10 -6
- data/spec/support/matchers/expose.rb +18 -0
- data/vendor/assets/javascripts/angular/angular-bootstrap.js +1 -1
- data/vendor/assets/javascripts/angular/angular-resource.js +78 -56
- data/vendor/assets/javascripts/angular/angular-sanitize.js +3 -1
- data/vendor/assets/javascripts/angular/angular.js +720 -404
- metadata +323 -183
- data/app/assets/javascripts/app.js.coffee +0 -8
- data/app/assets/javascripts/app/controllers.js.coffee +0 -2
- data/app/assets/javascripts/app/controllers/alerts.js.coffee +0 -12
- data/app/assets/javascripts/app/controllers/collections.js.coffee +0 -40
- data/app/assets/javascripts/app/controllers/documents.js.coffee +0 -49
- data/app/assets/javascripts/app/controllers/main.js.coffee +0 -10
- data/app/assets/javascripts/app/controllers/server_info.js.coffee +0 -14
- data/app/assets/javascripts/templates.js.coffee +0 -1
- data/app/assets/javascripts/templates/.gitkeep +0 -0
- data/app/assets/templates/collections.html +0 -53
- data/app/assets/templates/databases.html +0 -32
- data/app/assets/templates/documents.html +0 -45
- data/config-e2e.ru +0 -20
- data/spec/features/collections_list_spec.rb +0 -64
- data/spec/features/documents_list_spec.rb +0 -139
- data/spec/features/server_info_spec.rb +0 -23
- data/spec/javascripts/app/controllers/alerts_spec.js.coffee +0 -36
- data/spec/javascripts/app/controllers/collections_spec.js.coffee +0 -78
- data/spec/javascripts/app/controllers/databases_spec.js.coffee +0 -55
- data/spec/javascripts/app/controllers/documents_spec.js.coffee +0 -62
- data/spec/javascripts/helpers_e2e/app_element.js.coffee +0 -6
- data/spec/support/feature_example_group.rb +0 -53
- data/spec/support/matchers/have_flash_message.rb +0 -16
- data/spec/support/mongod.rb +0 -91
- 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>
|
File without changes
|
File without changes
|
data/script/ci_all
CHANGED
@@ -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
|
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
|
data/script/ci_e2e
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
#!/bin/bash
|
2
2
|
|
3
3
|
# Start test backend instance
|
4
|
-
bundle exec thin start -R config
|
4
|
+
bundle exec thin start -R config.ru -e test -p 3001 -d
|
5
5
|
|
6
|
-
|
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
|
data/script/ci_javascripts
CHANGED
data/script/ci_rspec
CHANGED
@@ -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.")
|