From a08cbc02e78e789a66e9af771c410e8ad1646e25 Mon Sep 17 00:00:00 2001 From: Vojta Jina Date: Fri, 23 Mar 2012 15:53:04 -0700 Subject: feat($compile): do not interpolate boolean attributes, rather evaluate them So that we can have non string values, e.g. ng-value="true" for radio inputs Breaks boolean attrs are evaluated rather than interpolated To migrate your code, change: to: Affected directives: * ng-multiple * ng-selected * ng-checked * ng-disabled * ng-readonly * ng-required --- test/directive/booleanAttrDirSpecs.js | 46 +++++++++++++++++++++++------------ test/directive/inputSpec.js | 4 +-- test/directive/selectSpec.js | 2 +- test/service/compilerSpec.js | 16 ------------ 4 files changed, 33 insertions(+), 35 deletions(-) (limited to 'test') diff --git a/test/directive/booleanAttrDirSpecs.js b/test/directive/booleanAttrDirSpecs.js index 8d71c2d8..7a4244a8 100644 --- a/test/directive/booleanAttrDirSpecs.js +++ b/test/directive/booleanAttrDirSpecs.js @@ -17,7 +17,7 @@ describe('boolean attr directives', function() { it('should bind disabled', inject(function($rootScope, $compile) { - element = $compile('')($rootScope) + element = $compile('')($rootScope) $rootScope.isDisabled = false; $rootScope.$digest(); expect(element.attr('disabled')).toBeFalsy(); @@ -28,7 +28,7 @@ describe('boolean attr directives', function() { it('should bind checked', inject(function($rootScope, $compile) { - element = $compile('')($rootScope) + element = $compile('')($rootScope) $rootScope.isChecked = false; $rootScope.$digest(); expect(element.attr('checked')).toBeFalsy(); @@ -39,7 +39,7 @@ describe('boolean attr directives', function() { it('should bind selected', inject(function($rootScope, $compile) { - element = $compile('')($rootScope) + element = $compile('')($rootScope) jqLite(document.body).append(element) $rootScope.isSelected=false; $rootScope.$digest(); @@ -51,7 +51,7 @@ describe('boolean attr directives', function() { it('should bind readonly', inject(function($rootScope, $compile) { - element = $compile('')($rootScope) + element = $compile('')($rootScope) $rootScope.isReadonly=false; $rootScope.$digest(); expect(element.attr('readOnly')).toBeFalsy(); @@ -62,7 +62,7 @@ describe('boolean attr directives', function() { it('should bind multiple', inject(function($rootScope, $compile) { - element = $compile('')($rootScope) + element = $compile('')($rootScope) $rootScope.isMultiple=false; $rootScope.$digest(); expect(element.attr('multiple')).toBeFalsy(); @@ -88,24 +88,38 @@ describe('boolean attr directives', function() { expect(element.attr('href')).toEqual('http://server'); expect(element.attr('rel')).toEqual('REL'); })); +}); - it('should bind Text with no Bindings', inject(function($compile, $rootScope) { - forEach(['checked', 'disabled', 'multiple', 'readonly', 'selected'], function(name) { - element = $compile('
')($rootScope) - $rootScope.$digest(); - expect(element.attr(name)).toBe(name); - dealoc(element); - }); +describe('ng-src', function() { - element = $compile('
')($rootScope) + it('should interpolate the expression and bind to src', inject(function($compile, $rootScope) { + var element = $compile('
')($rootScope) $rootScope.$digest(); - expect(element.attr('src')).toEqual('some'); + expect(element.attr('src')).toEqual('some/'); + + $rootScope.$apply(function() { + $rootScope.id = 1; + }); + expect(element.attr('src')).toEqual('some/1'); + dealoc(element); + })); +}); + + +describe('ng-href', function() { - element = $compile('
')($rootScope) + it('should interpolate the expression and bind to href', inject(function($compile, $rootScope) { + var element = $compile('
')($rootScope) $rootScope.$digest(); - expect(element.attr('href')).toEqual('some'); + expect(element.attr('href')).toEqual('some/'); + + $rootScope.$apply(function() { + $rootScope.id = 1; + }); + expect(element.attr('href')).toEqual('some/1'); + dealoc(element); })); }); diff --git a/test/directive/inputSpec.js b/test/directive/inputSpec.js index 8d0e44b3..e5f083b3 100644 --- a/test/directive/inputSpec.js +++ b/test/directive/inputSpec.js @@ -941,8 +941,8 @@ describe('input', function() { describe('required', function() { - it('should allow bindings on required', function() { - compileInput(''); + it('should allow bindings on ng-required', function() { + compileInput(''); scope.$apply(function() { scope.required = false; diff --git a/test/directive/selectSpec.js b/test/directive/selectSpec.js index 3f8fb56e..2e3cfaaf 100644 --- a/test/directive/selectSpec.js +++ b/test/directive/selectSpec.js @@ -780,7 +780,7 @@ describe('select', function() { createSelect({ 'ng-model': 'value', 'ng-options': 'item.name for item in values', - 'ng-required': '{{required}}' + 'ng-required': 'required' }, true); diff --git a/test/service/compilerSpec.js b/test/service/compilerSpec.js index 698fc23e..dc2e20cf 100644 --- a/test/service/compilerSpec.js +++ b/test/service/compilerSpec.js @@ -1411,22 +1411,6 @@ describe('$compile', function() { }); - it('should set boolean attributes', function() { - attr.$set('disabled', 'true'); - attr.$set('readOnly', 'true'); - expect(element.attr('disabled')).toEqual('disabled'); - expect(element.attr('readonly')).toEqual('readonly'); - - attr.$set('disabled', 'false'); - expect(element.attr('disabled')).toEqual(undefined); - - attr.$set('disabled', false); - attr.$set('readOnly', false); - expect(element.attr('disabled')).toEqual(undefined); - expect(element.attr('readonly')).toEqual(undefined); - }); - - it('should remove attribute', function() { attr.$set('ngMyAttr', 'value'); expect(element.attr('ng-my-attr')).toEqual('value'); -- cgit v1.2.3