<commit_before>describe "controllers", ->
  beforeEach module("mb.services")

  # Create mock for bootboxDialogsHandler
  beforeEach ->
    angular.module("mock", []).config ($provide) ->
      $provide.factory "bootboxDialogsHandler", ->
        confirm: (message, callback) ->
          @callback = callback
        confirmed: -> @callback(true)
        disposed: -> @callback(false)

  beforeEach module("mock")

  describe "DatabasesCtrl", ->
    $scope = null
    doAction = null

    beforeEach inject ($injector, $rootScope, $controller) ->
      $scope = $rootScope.$new()
      confirmationDialog = $injector.get("confirmationDialog")
      doAction = jasmine.createSpy("do action")

      $element = $("<div/>")
          .data("databases", [])

      $controller window.DatabasesCtrl,
        $scope: $scope
        $element: $element
        confirmationDialog: confirmationDialog
        doAction: doAction

    describe "#delete", ->
      it "shows a confirmation dialog", inject (bootboxDialogsHandler) ->
        spyOn(bootboxDialogsHandler, "confirm")
        $scope.delete(name: "test_database_name")
        expect(bootboxDialogsHandler.confirm).toHaveBeenCalledWith \
            "Deleting test_database_name. Are you sure?",
            jasmine.any(Function)

      describe "when the dialog was confirmed", ->
        it "sends a delete request", inject (bootboxDialogsHandler) ->
          # When
          $scope.delete(name: "test_database_name")
          bootboxDialogsHandler.confirmed()

          # Then
          expect(doAction).toHaveBeenCalledWith \
              "/databases/test_database_name",
              "delete"

      describe "when the dialog was disposed", ->
        it "does nothing", inject (bootboxDialogsHandler) ->
          # When
          $scope.delete(name: "test_database_name")
          bootboxDialogsHandler.disposed()

          # Then
          expect(doAction).not.toHaveBeenCalled()

  describe "DocumentsCtrl", ->
    $scope = null
    doAction = null

    beforeEach inject ($injector, $rootScope, $controller) ->
      $scope = $rootScope.$new()
      confirmationDialog = $injector.get("confirmationDialog")
      doAction = jasmine.createSpy("do action")

      $element = $("<div/>")
          .data("db-name", "test_database")
          .data("collection-name", "test_collection")
<commit_msg>Add spec for CollectionsCtrl#delete method.<commit_after># TODO figure out how to dry specs for #delete methods

describe "controllers", ->
  beforeEach module("mb.services")

  # Create mock for bootboxDialogsHandler
  beforeEach ->
    angular.module("mock", []).config ($provide) ->
      $provide.factory "bootboxDialogsHandler", ->
        confirm: (message, callback) ->
          @callback = callback
        confirmed: -> @callback(true)
        disposed: -> @callback(false)

  beforeEach module("mock")

  describe "DatabasesCtrl", ->
    $scope = null
    doAction = null

    beforeEach inject ($injector, $rootScope, $controller) ->
      $scope = $rootScope.$new()
      confirmationDialog = $injector.get("confirmationDialog")
      doAction = jasmine.createSpy("do action")

      $element = $("<div/>")
          .data("databases", [])

      $controller window.DatabasesCtrl,
        $scope: $scope
        $element: $element
        confirmationDialog: confirmationDialog
        doAction: doAction

    describe "#delete", ->
      it "shows a confirmation dialog", inject (bootboxDialogsHandler) ->
        spyOn(bootboxDialogsHandler, "confirm")
        $scope.delete(name: "test_database_name")
        expect(bootboxDialogsHandler.confirm).toHaveBeenCalledWith \
            "Deleting test_database_name. Are you sure?",
            jasmine.any(Function)

      describe "when the dialog was confirmed", ->
        it "sends a delete request", inject (bootboxDialogsHandler) ->
          # When
          $scope.delete(name: "test_database_name")
          bootboxDialogsHandler.confirmed()

          # Then
          expect(doAction).toHaveBeenCalledWith \
              "/databases/test_database_name",
              "delete"

      describe "when the dialog was disposed", ->
        it "does nothing", inject (bootboxDialogsHandler) ->
          # When
          $scope.delete(name: "test_database_name")
          bootboxDialogsHandler.disposed()

          # Then
          expect(doAction).not.toHaveBeenCalled()

  describe "CollectionsCtrl", ->
    $scope = null
    doAction = null

    beforeEach inject ($injector, $rootScope, $controller) ->
      $scope = $rootScope.$new()
      confirmationDialog = $injector.get("confirmationDialog")
      doAction = jasmine.createSpy("do action")

      $element = $("<div/>")
        .data("db-name", "test_database")
        .data("collections", [])

      $controller window.CollectionsCtrl,
          $scope: $scope
          $element: $element
          confirmationDialog: confirmationDialog
          doAction: doAction

    describe "#delete", ->
      it "shows a confirmation dialog", inject (bootboxDialogsHandler) ->
        spyOn(bootboxDialogsHandler, "confirm")
        $scope.delete(name: "dummy-collection-id")
        expect(bootboxDialogsHandler.confirm).toHaveBeenCalledWith \
            "Deleting dummy-collection-id. Are you sure?",
            jasmine.any(Function)

      describe "when the dialog was confirmed", ->
        it "sends a delete request", inject (bootboxDialogsHandler) ->
          # When
          $scope.delete(name: "dummy-collection-id")
          bootboxDialogsHandler.confirmed()

          # Then
          expect(doAction).toHaveBeenCalledWith \
              "/databases/test_database/collections/dummy-collection-id",
              "delete"

      describe "when the dialog was disposed", ->
        it "does nothing", inject (bootboxDialogsHandler) ->
          # When
          $scope.delete(name: "dummy-collection-id")
          bootboxDialogsHandler.disposed()

          # Then
          expect(doAction).not.toHaveBeenCalled()

  describe "DocumentsCtrl", ->
    $scope = null
    doAction = null

    beforeEach inject ($injector, $rootScope, $controller) ->
      $scope = $rootScope.$new()
      confirmationDialog = $injector.get("confirmationDialog")
      doAction = jasmine.createSpy("do action")

      $element = $("<div/>")
          .data("db-name", "test_database")
          .data("collection-name", "test_collection")

{'fraction_non_alphanumeric': 0.12190950085523247, 'fraction_numerical': 0.0, 'mean_word_length': 2.575319622012229, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 50, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1362495', 'n_tokens_mistral': 1784, 'n_tokens_neox': 1740, 'n_words': 382}