adding by producer id filtering

This commit is contained in:
Will Marshall
2014-07-02 12:13:50 +10:00
committed by Rohan Mitchell
parent e858c0d434
commit 4a116570d1
2 changed files with 27 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
Darkswarm.filter "byProducer", ->
(objects, id) ->
objects ||= []
id ?= 0
objects.filter (obj)->
obj.producer.id == id

View File

@@ -0,0 +1,21 @@
describe 'filtering by producer', ->
filterByProducer = null
objects = [
{
producer:
id: 1
}
{
producer:
id: 2
}
]
beforeEach ->
module 'Darkswarm'
inject ($filter) ->
filterByProducer = $filter('byProducer')
it "filters by producer", ->
expect(filterByProducer(objects, 1)[0]).toBe objects[0]
expect(filterByProducer(objects, 2)[0]).toBe objects[1]