(function () {
  'use strict';

  describe('ProviderController', function () {
    var ctrl,
      $controller,
      dependencies,
      $rootScope,
      $ionicLoading,
      ProviderService,
      deferCreateProvider,
      deferStateGo,
      $state,
      $auth,
      $ionicPopup,
      $ionicScrollDelegate,
      $translate,
      stateRedirect,
      deferTranslate;

    beforeEach(module('porttare.controllers'));

    beforeEach(inject(
      function ($q,
        _$controller_,
        _$rootScope_) {

        deferCreateProvider = $q.defer();
        deferStateGo = $q.defer();
        deferTranslate = $q.defer();
        $controller = _$controller_;
        $rootScope = _$rootScope_;
        $ionicLoading = {
          show: sinon.stub(),
          hide: sinon.stub()
        };
        $ionicScrollDelegate = {
          scrollTop: sinon.stub()
        };
        $state = {
          go: sinon.stub().returns(deferStateGo.promise)
        };
        $ionicPopup = {
          alert: sinon.stub()
        };
        $translate = sinon.stub().returns(deferTranslate.promise);
        ProviderService = {
          createNewProvider: sinon.stub().returns(deferCreateProvider.promise)
        };
        $auth = {
          user: {name:'', email:''}
        };
        stateRedirect = 'provider.items.index';
      })
    );


    describe('Create provider', function () {
      beforeEach(function () {
        dependencies = {
          $ionicLoading: $ionicLoading,
          ProviderService: ProviderService,
          $ionicPopup: $ionicPopup,
          $state: $state,
          $auth: $auth,
          $translate: $translate,
          $ionicScrollDelegate: $ionicScrollDelegate
        };

        ctrl = $controller('ProviderController', dependencies);
      });

      beforeEach(inject(function () {
        ctrl.step = 2;
        ctrl.provider = {'ruc':'222222222','razon_social':'Movvigo','nombre_establecimiento':'Movvigo','actividad_economica':'Gasdro','representante_legal':'Movvigo','telefono':'6666666666','email':'something@movvigo.com','website':'www.moviggo.com'};
        ctrl.matrizProvider = {'direccion':'Aqui','hora_de_apertura':'1899-12-31T11:28:00.000Z','hora_de_cierre':'1899-12-31T15:28:00.000Z','inicio_de_labores':{'label':'Lunes','name':'mon','$$hashKey':'object:159'},'final_de_labores':{'label':'Domingo','name':'sun','$$hashKey':'object:165'},'telefono':'666666666'};
        ctrl.submit();
      }));

      it('name and email should exist in authenticated user', function () {
        expect($auth.user.name).to.exist; //jshint ignore:line
        expect($auth.user.email).to.exist; //jshint ignore:line
      });

      it('legal representative and email  should not be empty', function () {
        chai.assert.isNotNull(ctrl.provider.representante_legal, 'exists!'); //jshint ignore:line
        chai.assert.isNotNull(ctrl.provider.email, 'exists!');
      });

      it('ionicLoading.show should be called', function () {
        sinon.assert.calledOnce($ionicLoading.show);
      });

      it('if successful, ionicLoading.hide should be called', function () {
        deferCreateProvider.resolve({provider_profile: {}}); //jshint ignore:line
        $rootScope.$digest();
        sinon.assert.calledOnce($ionicLoading.hide);
      });

      it('if successful, should change state', function () {
        deferCreateProvider.resolve({provider_profile: {}}); //jshint ignore:line
        $rootScope.$digest();
        sinon.assert.alwaysCalledWithExactly($state.go, stateRedirect);
      });

      it('if successful, should show a alert', function () {
        deferCreateProvider.resolve({provider_profile: {}}); //jshint ignore:line
        $rootScope.$digest();
        deferStateGo.resolve();
        $rootScope.$digest();
        sinon.assert.calledOnce($ionicPopup.alert);
      });

      it('if unsuccessful, should show first template', function () {
        deferCreateProvider.reject({ data: { error: 'error' } });
        $rootScope.$digest();
        expect(ctrl.step).to.be.equal(1);
      });

    });
  });
})();

@@ -257,24 +257,39 @@
      $auth,%0A
+      $filter,%0A
       $ionic
@@ -291,24 +291,24 @@
 ionicPopup,%0A
-
       $ionic
@@ -432,16 +432,60 @@
 lers'));
+%0A    beforeEach(module('porttare.filters'));
 %0A%0A    be
@@ -521,16 +521,35 @@
 on ($q,%0A
+        _$filter_,%0A
         
@@ -588,16 +588,45 @@
 pe_) %7B%0A%0A
+        $filter = _$filter_;%0A
         
@@ -1713,24 +1713,52 @@
 uth: $auth,%0A
+          $filter: $filter,%0A
           $t

revise specs