showcase: renaming controllers to NameController and using always $scope and $rootSco...
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Sun, 13 Sep 2015 23:44:53 +0000 (01:44 +0200)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Sun, 13 Sep 2015 23:44:53 +0000 (01:44 +0200)
angularjs/showcase/src/showcase/app/cars/cars-error-modal.controller.js
angularjs/showcase/src/showcase/app/cars/cars-error-modal.controller.spec.js
angularjs/showcase/src/showcase/app/cars/cars.controller.js
angularjs/showcase/src/showcase/app/cars/cars.controller.spec.js
angularjs/showcase/src/showcase/app/cars/cars.html
angularjs/showcase/src/showcase/app/welcome/welcome.controller.js
angularjs/showcase/src/showcase/app/welcome/welcome.controller.spec.js
angularjs/showcase/src/showcase/app/welcome/welcome.html
angularjs/showcase/src/showcase/app/widgets/example-controller-as.directive.spec.js

index 2f6456a..d40d7e8 100644 (file)
@@ -3,11 +3,11 @@
 
   angular
     .module('app.cars')
-    .controller('CarsErrorModal', CarsErrorModal);
+    .controller('CarsErrorModalController', CarsErrorModalController);
 
   /**
    * @ngdoc controller
-   * @name app.cars.controller:CarsErrorModal
+   * @name app.cars.controller:CarsErrorModalController
    *
    * @requires $modalInstance
    * @requires app.cars.cars
@@ -21,7 +21,7 @@
    * Controller for error modal in cars application.
    */
   /* @ngInject */
-  function CarsErrorModal($modalInstance, cars) {
+  function CarsErrorModalController($modalInstance, cars) {
     var vm = this;
 
     vm.cars = cars;
index f85e9f4..bf72b5d 100644 (file)
@@ -6,13 +6,13 @@ describe('app.cars', function() {
     close: jasmine.createSpy('modalInstance.close'),
     dismiss: jasmine.createSpy('modalInstance.dismiss')
   };
-  var CarsErrorModal;
+  var CarsErrorModalController;
 
   beforeEach(function() {
     module('app.cars');
 
     inject(function($controller) {
-      CarsErrorModal = $controller('CarsErrorModal', {
+      CarsErrorModalController = $controller('CarsErrorModalController', {
         $modalInstance: $modalInstance,
         cars: cars
       });
@@ -20,16 +20,16 @@ describe('app.cars', function() {
 
   });
 
-  describe('CarsErrorModal controller', function () {
+  describe('CarsErrorModalController controller', function () {
 
     it('should invoke $modalInstance.close', function () {
-      CarsErrorModal.ok();
+      CarsErrorModalController.ok();
 
       expect($modalInstance.close).toHaveBeenCalledWith('car1');
     });
 
     it('should invoke $modalInstance.dismiss', function () {
-      CarsErrorModal.cancel();
+      CarsErrorModalController.cancel();
 
       expect($modalInstance.dismiss).toHaveBeenCalledWith('cancel');
     });
index 7734c20..dec4420 100644 (file)
@@ -3,11 +3,11 @@
 
   angular
     .module('app.cars')
-    .controller('Cars', Cars);
+    .controller('CarsController', CarsController);
 
   /**
    * @ngdoc controller
-   * @name app.cars.controller:Cars
+   * @name app.cars.controller:CarsController
    *
    * @requires $modal
    * @requires $timeout
    * </p>
    *
    * @description
-   * Cars controller.
+   * CarsController controller.
    */
   /* @ngInject */
-  function Cars($modal, $timeout, cars) {
+  function CarsController($modal, $timeout, cars) {
     var vm = this;
 
     vm.example = {
@@ -40,7 +40,7 @@
         },
         // Error
         function(reason) {
-          console.log('Cars controller error: ' + reason);
+          console.log('CarsController controller error: ' + reason);
           vm.doModal('lg');
         }
       );
 
       cars.getById(1).then(
         function (value) {
-          console.log('getCar getById: Cars controller value: ' + JSON.stringify(value));
+          console.log('getCar getById: CarsController controller value: ' + JSON.stringify(value));
         },
         function(reason) {
-          console.log('getCar getById: Cars controller reason: ' + JSON.stringify(reason));
+          console.log('getCar getById: CarsController controller reason: ' + JSON.stringify(reason));
         }
       );
 
       cars.getExpectedValue().then(
         function (value) {
-          console.log('getCar getExpectedValue: Cars controller value: ' + JSON.stringify(value));
+          console.log('getCar getExpectedValue: CarsController controller value: ' + JSON.stringify(value));
         },
         function(reason) {
-          console.log('getCar getExpectedValue: Cars controller reason: ' + JSON.stringify(reason));
+          console.log('getCar getExpectedValue: CarsController controller reason: ' + JSON.stringify(reason));
         }
       );
 
 
       cars.getExpectedValue().then(
         function (value) {
-          console.log('getResolvedPromise getExpectedValue: Cars controller value: ' + JSON.stringify(value));
+          console.log('getResolvedPromise getExpectedValue: CarsController controller value: ' +
+            JSON.stringify(value));
         },
         function(reason) {
-          console.log('getResolvedPromise getExpectedValue: Cars controller reason: ' + JSON.stringify(reason));
+          console.log('getResolvedPromise getExpectedValue: CarsController controller reason: ' +
+            JSON.stringify(reason));
         }
       );
 
@@ -95,7 +97,7 @@
       var modalInstance = $modal.open({
         animation: true,
         templateUrl: 'app/cars/cars-error-modal.html',
-        controller: 'CarsErrorModal as vm',
+        controller: 'CarsErrorModalController as vm',
         size: size,
         backdrop: 'static',
         keyboard: false,
index b4f2030..81f1924 100644 (file)
@@ -10,14 +10,14 @@ describe('app.cars', function() {
       return {};
     }
   };
-  var Cars;
+  var CarsController;
   var $q;
 
   beforeEach(function() {
     module('app.cars');
 
     inject(function($controller, $modal, $timeout, _$q_) {
-      Cars = $controller('Cars', {
+      CarsController = $controller('CarsController', {
         $modal: $modal,
         $timeout: $timeout,
         cars: cars
@@ -43,10 +43,10 @@ describe('app.cars', function() {
           };
         });
 
-      Cars.getCars();
+      CarsController.getCars();
 
       expect(cars.getAll).toHaveBeenCalled();
-      expect(Cars.cars).toEqual(onFulfilledValue);
+      expect(CarsController.cars).toEqual(onFulfilledValue);
     });
   });
 
@@ -114,14 +114,14 @@ describe('app.cars', function() {
       })
   };
   var $timeout;
-  var Cars;
+  var CarsController;
   var $q;
 
   beforeEach(function() {
     module('app.cars');
 
     inject(function($controller, _$timeout_, _$q_) {
-      Cars = $controller('Cars', {
+      CarsController = $controller('CarsController', {
         $modal: $modal,
         $timeout: _$timeout_,
         cars: cars
@@ -135,46 +135,46 @@ describe('app.cars', function() {
 
     it('should invoke GET all cars in service with success: alternative way', function () {
 
-      Cars.getCars();
+      CarsController.getCars();
 
       expect(cars.getAll).toHaveBeenCalled();
-      expect(Cars.cars).toEqual(onFulfilledValue);
+      expect(CarsController.cars).toEqual(onFulfilledValue);
     });
 
     it('should invoke GET all cars in service with error: alternative way', function () {
       isSuccessCallBack = false;
-      spyOn(Cars, 'doModal')
+      spyOn(CarsController, 'doModal')
         .and.callFake(function() {
           return {};
         });
 
-      Cars.getCars();
+      CarsController.getCars();
 
       expect(cars.getAll).toHaveBeenCalled();
-      expect(Cars.doModal).toHaveBeenCalled();
+      expect(CarsController.doModal).toHaveBeenCalled();
 
       isSuccessCallBack = true;
     });
 
     it('should invoke $modal.open', function () {
 
-      Cars.doModal('lg');
+      CarsController.doModal('lg');
 
       expect($modal.open).toHaveBeenCalled();
     });
 
     it('should invoke $modalInstance.result with success', function () {
 
-      Cars.doModal('lg');
+      CarsController.doModal('lg');
 
       expect($modalInstance.result.then).toHaveBeenCalled();
-      expect(Cars.selected).toEqual(onFulfilledValue);
+      expect(CarsController.selected).toEqual(onFulfilledValue);
     });
 
     it('should invoke $modalInstance.result with error', function () {
       isSuccessCallBack = false;
 
-      Cars.doModal('lg');
+      CarsController.doModal('lg');
 
       expect($modalInstance.result.then).toHaveBeenCalled();
 
@@ -183,7 +183,7 @@ describe('app.cars', function() {
 
     it('should invoke $modalInstance.opened with success', function () {
 
-      Cars.doModal('lg');
+      CarsController.doModal('lg');
 
       expect($modalInstance.opened.then).toHaveBeenCalled();
 
@@ -192,7 +192,7 @@ describe('app.cars', function() {
     it('should invoke $modalInstance.opened with error', function () {
       isSuccessCallBack = false;
 
-      Cars.doModal('lg');
+      CarsController.doModal('lg');
 
       expect($modalInstance.opened.then).toHaveBeenCalled();
 
@@ -201,7 +201,7 @@ describe('app.cars', function() {
 
     it('should invoke $modalInstance.rendered with success', function () {
 
-      Cars.doModal('lg');
+      CarsController.doModal('lg');
 
       expect($modalInstance.rendered.then).toHaveBeenCalled();
 
@@ -210,7 +210,7 @@ describe('app.cars', function() {
     it('should invoke $modalInstance.rendered with error', function () {
       isSuccessCallBack = false;
 
-      Cars.doModal('lg');
+      CarsController.doModal('lg');
 
       expect($modalInstance.rendered.then).toHaveBeenCalled();
 
@@ -219,7 +219,7 @@ describe('app.cars', function() {
 
     it('should invoke $modalInstance.close because of timeout', function () {
 
-      Cars.doModal('lg');
+      CarsController.doModal('lg');
       $timeout.flush();
 
       expect($modalInstance.close).toHaveBeenCalledWith('closed by timeout');
@@ -228,7 +228,7 @@ describe('app.cars', function() {
 
     it('should invoke $modalInstance.dismiss because of timeout', function () {
 
-      Cars.doModal('lg');
+      CarsController.doModal('lg');
       $timeout.flush();
 
       expect($modalInstance.dismiss).toHaveBeenCalledWith('dismissed by timeout');
index fda95e9..28d2756 100644 (file)
@@ -1,7 +1,7 @@
 <!DOCTYPE html>
 <div class="container">
 
-  <form name="myForm" ng-controller="Cars as vm">
+  <form name="myForm" ng-controller="CarsController as vm">
     <label>Single word:</label>
     <input type="text" name="input" ng-model="vm.example.text"
            ng-pattern="vm.example.word" required ng-trim="false">
index dacf8b5..bf94b1e 100644 (file)
@@ -3,16 +3,16 @@
 
   angular
     .module('app.welcome')
-    .controller('Welcome', Welcome);
+    .controller('WelcomeController', WelcomeController);
 
   // When using <div ng-app="app" ng-strict-di> (strict mode) we must always
   // manually identify dependencies.
   // Instead I am going to use ngInject because it is cool :)
-  // Welcome.$inject = ['$location'];
+  // WelcomeController.$inject = ['$location'];
 
   /**
    * @ngdoc controller
-   * @name app.welcome.controller:Welcome
+   * @name app.welcome.controller:WelcomeController
    *
    * @requires $location
    *
    * </p>
    *
    * @description
-   * Welcome controller.
+   * WelcomeController controller.
    */
   /* @ngInject */
-  function Welcome($location) {
+  function WelcomeController($location) {
     var vm = this;
 
     vm.hello = 'Hello World';
index b86f10d..d45ec79 100644 (file)
@@ -1,23 +1,23 @@
 describe('app.welcome', function() {
   'use strict';
 
-  var controller;
-  var scope;
+  var WelcomeController;
+  var $scope;
 
   beforeEach(function() {
     module('app.welcome');
 
     inject(function($controller, _$rootScope_) {
-      scope = _$rootScope_.$new();
-      scope.hello = 'Hello World';
-      controller = $controller('Welcome', {$scope: scope});
+      $scope = _$rootScope_.$new();
+      $scope.hello = 'Hello World';
+      WelcomeController = $controller('WelcomeController', {$scope: $scope});
     });
   });
 
-  describe('Welcome controller', function () {
+  describe('WelcomeController controller', function () {
 
     it('should be created successfully', function () {
-      expect(controller).toBeDefined();
+      expect(WelcomeController).toBeDefined();
     });
   });
 
index b2e2f94..fc49266 100644 (file)
@@ -1,5 +1,5 @@
 <!DOCTYPE html>
-<div class="container" ng-controller="Welcome as vm">
+<div class="container" ng-controller="WelcomeController as vm">
   <div class="row">
     {{ vm.hello }}
 
index 74fabb8..7efccf9 100644 (file)
@@ -2,29 +2,29 @@
   'use strict';
 
   describe('exampleControllerAsDirective', function() {
-    var compile;
-    var rootScope;
+    var $compile;
+    var $rootScope;
     var template;
 
     beforeEach(module('app.widgets'));
 
-    beforeEach(inject(function($compile, $rootScope) {
-      compile = $compile;
-      rootScope = $rootScope;
+    beforeEach(inject(function(_$compile_, _$rootScope_) {
+      $compile = _$compile_;
+      $rootScope = _$rootScope_;
       template = '<controller-as-directive>';
     }));
 
     it('should assign min value 3', function() {
-      var scope;
+      var $scope;
       var element;
       var vm;
 
-      scope = rootScope.$new();
+      $scope = $rootScope.$new();
       // IN THE REAL WORLD, BETTER DECLARE THE CONTROLLER RELATED TO MY DIRECTIVE IN A DIFFERENT FILE AND
       // TEST THE CONTROLLER WITH ITS OWN SPEC!!!!!
       // see: http://stackoverflow.com/a/15314876
-      element = compile(template)(scope);
-      scope.$digest();
+      element = $compile(template)($scope);
+      $scope.$digest();
 
       vm = element.controller('controllerAsDirective');