Permalink
Browse files

Merge pull request #8 from natlownes/model_loader_urlFunc_fix_up

model loader fix
  • Loading branch information...
2 parents ad8f48b + 69f5d5a commit c95763340c61c461e5c98c7d4f20600668af909d @markchadwick markchadwick committed Mar 10, 2013
Showing with 32 additions and 1 deletion.
  1. +1 −1 models/loader.coffee
  2. +31 −0 test/models/loader_spec.coffee
View
@@ -14,7 +14,7 @@ module.exports =
collection = new collectionType
if $.isFunction(collection.url)
urlFunc = collection.url
- collection.url = ->
+ collection.url = do ->
apiRoot + urlFunc()
else
collection.url = apiRoot + collection.url
@@ -40,6 +40,37 @@ describe 'Model Loader', ->
load(collections, 'api-root').done ->
done()
+ describe 'when loading multiple collections with url functions', ->
+
+ it "should make a request to each collection's url", (done) ->
+ collectionOneFetches = 0
+ collectionTwoFetches = 0
+
+ test.when 'GET', 'api-root/my/mock/func/url1', (req) ->
+ collectionOneFetches++
+ status: 200
+
+ test.when 'GET', 'api-root/my/mock/func/url2', (req) ->
+ collectionTwoFetches++
+ status: 200
+
+ class FuncOneCollection extends Collection
+ model: MockModel
+ url: -> '/my/mock/func/url1'
+
+ class FuncTwoCollection extends Collection
+ model: MockModel
+ url: -> '/my/mock/func/url2'
+
+ collections =
+ funcOne: FuncOneCollection
+ funcTwo: FuncTwoCollection
+
+ load(collections, 'api-root').done ->
+ expect(collectionOneFetches).to.equal 1
+ expect(collectionTwoFetches).to.equal 1
+ done()
+
it 'should not fetch lazy collections', (done) ->
fetches = 0

0 comments on commit c957633

Please sign in to comment.