From da7a2ee2d31b00b0a48dd82ffea3bc96e9087e3a Mon Sep 17 00:00:00 2001 From: Andrew Jackson Date: Mon, 3 Feb 2014 10:56:47 -0800 Subject: [PATCH 1/2] fix(filterFilter): allow both dotted predicate object fields, and nested predicate objects --- src/ng/filter/filter.js | 2 +- test/ng/filter/filterSpec.js | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/ng/filter/filter.js b/src/ng/filter/filter.js index eabe84a7e0b0..988df88ce12f 100644 --- a/src/ng/filter/filter.js +++ b/src/ng/filter/filter.js @@ -188,7 +188,7 @@ function filterFilter() { (function(path) { if (typeof expression[path] == 'undefined') return; predicates.push(function(value) { - return search(path == '$' ? value : (value && value[path]), expression[path]); + return search(path == '$' ? value : ( (value && value[path]) || getter(value, path)), expression[path]); }); })(key); } diff --git a/test/ng/filter/filterSpec.js b/test/ng/filter/filterSpec.js index 0bb487042ba3..a52df6259191 100644 --- a/test/ng/filter/filterSpec.js +++ b/test/ng/filter/filterSpec.js @@ -49,7 +49,7 @@ describe('Filter: filter', function() { expect(filter(items, function(i) {return i.done;}).length).toBe(1); }); - it('should take object as perdicate', function() { + it('should take object as predicate', function() { var items = [{first: 'misko', last: 'hevery'}, {first: 'adam', last: 'abrons'}]; @@ -61,13 +61,22 @@ describe('Filter: filter', function() { }); - it('should support predicat object with dots in the name', function() { + it('should also support nested objects in predicate', function() { + var items = [{'person': 'misko hevery', 'job': {name: 'bit jockey'}}, + {'person': 'adam abrons', 'job': {name: 'pixelmancer'}}]; + + expect(filter(items, {'job.name':''}).length).toBe(2); + expect(filter(items, {'job.name':'bit'})).toEqual([items[0]]); + }); + + + it('should support predicate object with dots in the name', function() { var items = [{'first.name': 'misko', 'last.name': 'hevery'}, {'first.name': 'adam', 'last.name': 'abrons'}]; expect(filter(items, {'first.name':'', 'last.name':''}).length).toBe(2); expect(filter(items, {'first.name':'misko', 'last.name':''})).toEqual([items[0]]); - }); + }); it('should match any properties for given "$" property', function() { From 26c2b285eac77313737e667375561f48cc00db56 Mon Sep 17 00:00:00 2001 From: Andrew Jackson Date: Mon, 3 Feb 2014 11:00:00 -0800 Subject: [PATCH 2/2] reorder tests --- test/ng/filter/filterSpec.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/test/ng/filter/filterSpec.js b/test/ng/filter/filterSpec.js index a52df6259191..24c5a9703bf6 100644 --- a/test/ng/filter/filterSpec.js +++ b/test/ng/filter/filterSpec.js @@ -61,15 +61,6 @@ describe('Filter: filter', function() { }); - it('should also support nested objects in predicate', function() { - var items = [{'person': 'misko hevery', 'job': {name: 'bit jockey'}}, - {'person': 'adam abrons', 'job': {name: 'pixelmancer'}}]; - - expect(filter(items, {'job.name':''}).length).toBe(2); - expect(filter(items, {'job.name':'bit'})).toEqual([items[0]]); - }); - - it('should support predicate object with dots in the name', function() { var items = [{'first.name': 'misko', 'last.name': 'hevery'}, {'first.name': 'adam', 'last.name': 'abrons'}]; @@ -77,6 +68,15 @@ describe('Filter: filter', function() { expect(filter(items, {'first.name':'', 'last.name':''}).length).toBe(2); expect(filter(items, {'first.name':'misko', 'last.name':''})).toEqual([items[0]]); }); + + + it('should also support nested objects in predicate', function() { + var items = [{'person': 'misko hevery', 'job': {name: 'bit jockey'}}, + {'person': 'adam abrons', 'job': {name: 'pixelmancer'}}]; + + expect(filter(items, {'job.name':''}).length).toBe(2); + expect(filter(items, {'job.name':'bit'})).toEqual([items[0]]); + }); it('should match any properties for given "$" property', function() {