Indexer accepts arbitrary key to index by. Fix bug: Return an object instead of an array.

This commit is contained in:
Rohan Mitchell
2014-11-27 11:34:35 +11:00
parent 47b479c6c9
commit 8baed4429c
2 changed files with 12 additions and 3 deletions

View File

@@ -11,3 +11,12 @@ describe "indexer", ->
objects = [{id: 1, name: 'one'}, {id: 2, name: 'two'}]
index = Indexer.index objects
expect(index).toEqual({1: {id: 1, name: 'one'}, 2: {id: 2, name: 'two'}})
it "indexes an array of objects by another field", ->
objects = [{widget_id: 1, name: 'one'}, {widget_id: 2, name: 'two'}]
index = Indexer.index objects, 'widget_id'
expect(index).toEqual({1: {widget_id: 1, name: 'one'}, 2: {widget_id: 2, name: 'two'}})
it "returns an object, not an array", ->
index = Indexer.index []
expect(index.constructor).not.toEqual(Array)