jpbochi / halberd

JavaScript implementation of HAL format
Other
8 stars 3 forks source link

Allow adding an array of links to a resource #1

Closed nareshbhatia closed 10 years ago

nareshbhatia commented 10 years ago

Allow adding an array of links to a resource similar to this: http://haltalk.herokuapp.com/explorer/browser.html#/users. This cound be achieved by allowing multiple calls to Resource.link() with the same "rel" value.

jpbochi commented 10 years ago

will do.

jpbochi commented 10 years ago

@nareshbhatia Apparently, this is already supported. Take a look at this test: https://github.com/jpbochi/halberd/blob/halberd/test/hal.js#L61-L70

nareshbhatia commented 10 years ago

@jpbochi - yes I see the test case. However I just found an issue that prevents sending this resource back in an HTTP response. Just add this line to the end of the test:

console.log(res.toJSON());

You will see this error:

1 failing
1) HAL Resource should add two links with same rel:
 TypeError: Object [object Object],[object Object] has no method 'toJSON'
  at c:\Projects\halberd\hal.js:213:45
  at Array.reduce (native)
  at resourceToJsonObject (c:\Projects\halberd\hal.js:212:56)
  at Resource.toJSON (c:\Projects\halberd\hal.js:248:12)
  at Context.<anonymous> (c:\Projects\halberd\test\hal.js:70:23)
  at Test.Runnable.run (c:\Users\naresh\AppData\Roaming\npm\node_modules\mocha\lib\runnable.js:221:32)
  at Runner.runTest (c:\Users\naresh\AppData\Roaming\npm\node_modules\mocha\lib\runner.js:374:10)
  at c:\Users\naresh\AppData\Roaming\npm\node_modules\mocha\lib\runner.js:452:12
  at next (c:\Users\naresh\AppData\Roaming\npm\node_modules\mocha\lib\runner.js:299:14)
  at c:\Users\naresh\AppData\Roaming\npm\node_modules\mocha\lib\runner.js:309:7
  at next (c:\Users\naresh\AppData\Roaming\npm\node_modules\mocha\lib\runner.js:247:23)
  at Object._onImmediate (c:\Users\naresh\AppData\Roaming\npm\node_modules\mocha\lib\runner.js:276:5)
  at processImmediate [as _immediateCallback] (timers.js:330:15)
jpbochi commented 10 years ago

That's bad. I'll fix it.