Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

feat(rating): remove deprecated code #4723

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 0 additions & 38 deletions src/rating/rating.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,41 +97,3 @@ angular.module('ui.bootstrap.rating', [])
}
};
});

/* Deprecated rating below */

angular.module('ui.bootstrap.rating')

.value('$ratingSuppressWarning', false)

.controller('RatingController', ['$scope', '$attrs', '$controller', '$log', '$ratingSuppressWarning', function($scope, $attrs, $controller, $log, $ratingSuppressWarning) {
if (!$ratingSuppressWarning) {
$log.warn('RatingController is now deprecated. Use UibRatingController instead.');
}

angular.extend(this, $controller('UibRatingController', {
$scope: $scope,
$attrs: $attrs
}));
}])

.directive('rating', ['$log', '$ratingSuppressWarning', function($log, $ratingSuppressWarning) {
return {
require: ['rating', 'ngModel'],
scope: {
readonly: '=?',
onHover: '&',
onLeave: '&'
},
controller: 'RatingController',
templateUrl: 'template/rating/rating.html',
replace: true,
link: function(scope, element, attrs, ctrls) {
if (!$ratingSuppressWarning) {
$log.warn('rating is now deprecated. Use uib-rating instead.');
}
var ratingCtrl = ctrls[0], ngModelCtrl = ctrls[1];
ratingCtrl.init(ngModelCtrl);
}
};
}]);
43 changes: 5 additions & 38 deletions src/rating/test/rating.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('rating directive', function() {
return angular.element(star).attr('title');
});
}

function triggerKeyDown(keyCode) {
var e = $.Event('keydown');
e.which = keyCode;
Expand Down Expand Up @@ -280,13 +280,13 @@ describe('rating directive', function() {
expect(getState('on', 'off')).toEqual([true, true, true, true, true, false, false, false, false, false]);
});
});

describe('Default title', function() {
it('should return the default title for each star', function() {
expect(getTitles()).toEqual(['one', 'two', 'three', 'four', 'five']);
});
});

describe('shows different title when `max` attribute is greater than the titles array ', function() {
var originalConfig = {};
beforeEach(inject(function(uibRatingConfig) {
Expand All @@ -300,12 +300,12 @@ describe('rating directive', function() {
// return it to the original state
angular.extend(uibRatingConfig, originalConfig);
}));

it('should return the default title for each star', function() {
expect(getTitles()).toEqual(['one', 'two', 'three', 'four', 'five', '6', '7', '8', '9', '10']);
});
});

describe('shows custom titles ', function() {
it('should return the custom title for each star', function() {
$rootScope.titles = [44,45,46];
Expand All @@ -326,36 +326,3 @@ describe('rating directive', function() {
});
});
});

/* Deprecation tests below */

describe('rating deprecation', function() {
beforeEach(module('ui.bootstrap.rating'));
beforeEach(module('template/rating/rating.html'));

it('should suppress warning', function() {
module(function($provide) {
$provide.value('$ratingSuppressWarning', true);
});

inject(function($compile, $log, $rootScope) {
spyOn($log, 'warn');

var element = $compile('<rating ng-model="rate"></rating>')($rootScope);
$rootScope.$digest();

expect($log.warn.calls.count()).toBe(0);
});
});

it('should give warning by default', inject(function($compile, $log, $rootScope) {
spyOn($log, 'warn');

var element = $compile('<rating ng-model="rate"></rating>')($rootScope);
$rootScope.$digest();

expect($log.warn.calls.count()).toBe(2);
expect($log.warn.calls.argsFor(0)).toEqual(['RatingController is now deprecated. Use UibRatingController instead.']);
expect($log.warn.calls.argsFor(1)).toEqual(['rating is now deprecated. Use uib-rating instead.']);
}));
});