joosy 1.2.0.alpha.71 → 1.2.0.alpha.73

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -64,23 +64,6 @@ class Joosy.Resources.Base extends Joosy.Function
64
64
  @entity: (name) ->
65
65
  @::__entityName = name
66
66
 
67
- #
68
- # Sets the collection to use
69
- #
70
- # @note By default will try to seek for `EntityNamesCollection`.
71
- # Will fallback to {Joosy.Resources.Collection}
72
- #
73
- # @param [Class] klass Class to assign as collection
74
- #
75
- @collection: (klass) -> @::__collection = -> klass
76
-
77
- #
78
- # Implements {Joosy.Resources.Base.collection} default behavior.
79
- #
80
- __collection: ->
81
- named = @__entityName.camelize().pluralize() + 'Collection'
82
- if window[named] then window[named] else Joosy.Resources.Collection
83
-
84
67
  #
85
68
  # Dynamically creates collection of inline resources.
86
69
  #
@@ -289,9 +272,8 @@ class Joosy.Resources.Base extends Joosy.Function
289
272
 
290
273
  __map: (data, name, klass) ->
291
274
  if Object.isArray data[name]
292
- entry = new (klass::__collection()) klass
293
- entry.load data[name]
294
- data[name] = entry
275
+ entries = data[name].map (x) -> klass.build x
276
+ data[name] = new Joosy.Resources.Array entries...
295
277
  else if Object.isObject data[name]
296
278
  data[name] = klass.build data[name]
297
279
  data
@@ -1,5 +1,4 @@
1
1
  #= require ./base
2
- #= require ./rest_collection
3
2
 
4
3
  #
5
4
  # Resource with REST/JSON backend
@@ -66,15 +65,6 @@ class Joosy.Resources.REST extends Joosy.Resources.Base
66
65
  at: (args...) ->
67
66
  new (@constructor.at args...) @data
68
67
 
69
- #
70
- # Implements `@collection` default behavior.
71
- # Changes the default fallback to Joosy.Resources.RESTCollection.
72
- #
73
- __collection: ->
74
- named = @__entityName.camelize().pluralize() + 'Collection'
75
- if window[named] then window[named] else Joosy.Resources.RESTCollection
76
-
77
-
78
68
  #
79
69
  # Interpolates path with masks by given array of params
80
70
  #
@@ -262,12 +252,23 @@ class Joosy.Resources.REST extends Joosy.Resources.Base
262
252
  @constructor.__query @memberPath(options), 'DELETE', options.params, callback
263
253
 
264
254
  #
265
- # Requests the required resources from backend
255
+ # Refetches the data from backend and triggers `changed`
256
+ #
257
+ # @param [Hash] options See {Joosy.Resources.REST.find} for possible options
258
+ # @param [Function] callback Resulting callback
259
+ # @param [Object] callback `(error, instance, data) -> ...`
266
260
  #
267
- # @param [String] where Possible values: 'all', id.
268
- # 'all' will query for collection from collectionPath.
269
- # Everything else will be considered as an id string and will make resource
270
- # query for single instance from memberPath.
261
+ reload: (options={}, callback=false) ->
262
+ [options, callback] = @__extractOptionsAndCallback(options, callback)
263
+
264
+ @constructor.__query @memberPath(options), 'GET', options.params, (error, data, xhr) =>
265
+ @load data if data?
266
+ callback?(error, @, data, xhr)
267
+
268
+ #
269
+ # Requests the required resource from backend
270
+ #
271
+ # @param [String] where id or an array of ids for interpolated path
271
272
  # @param [Hash] options Path modification options
272
273
  # @param [Function] callback `(error, instance, data) -> ...`
273
274
  #
@@ -280,24 +281,62 @@ class Joosy.Resources.REST extends Joosy.Resources.Base
280
281
  @find: (where, options={}, callback=false) ->
281
282
  [options, callback] = @::__extractOptionsAndCallback(options, callback)
282
283
 
283
- id = if Object.isArray(where) then where.last() else where
284
-
285
- if id == 'all'
286
- result = new (@::__collection()) this, options
287
- path = @collectionPath where, options
284
+ id = if where instanceof Array
285
+ where[where.length-1]
288
286
  else
289
- result = @build id
290
- path = @memberPath where, options
287
+ where
288
+
289
+ result = @build id
291
290
 
292
- if Object.isArray(where) && where.length > 1
291
+ # Substitute interpolation mask with actual path
292
+ if where instanceof Array && where.length > 1
293
293
  result.__source = @collectionPath where
294
294
 
295
- @__query path, 'GET', options.params, (error, data, xhr) =>
295
+ @__query @memberPath(where, options), 'GET', options.params, (error, data, xhr) =>
296
296
  result.load data if data?
297
297
  callback?(error, result, data, xhr)
298
298
 
299
299
  result
300
300
 
301
+ #
302
+ # Requests the required collection of resources from backend
303
+ #
304
+ # @param [String] where id or an array of ids for interpolated path
305
+ # @param [Hash] options Path modification options
306
+ # @param [Function] callback `(error, instance, data) -> ...`
307
+ #
308
+ # @option options [String] action Adds the given string as a last path element
309
+ # i.e. /resources/trololo
310
+ # @option options [String] url Sets url for request instead of generated
311
+ # i.e. /some/custom/url
312
+ # @option options [Hash] params Passes the given params to the query
313
+ #
314
+ @all: (where, options={}, callback=false) ->
315
+ if Object.isFunction(where) || Object.isObject(where)
316
+ [options, callback] = @::__extractOptionsAndCallback(where, options)
317
+ where = []
318
+ else
319
+ [options, callback] = @::__extractOptionsAndCallback(options, callback)
320
+
321
+ result = new Joosy.Resources.Array
322
+
323
+ @__query @collectionPath(where, options), 'GET', options.params, (error, rawData, xhr) =>
324
+ if (data = rawData)?
325
+ if Object.isObject(data) && !(data = data[@::__entityName.pluralize()])
326
+ throw new Error "Invalid data for `all` received: #{JSON.stringify(data)}"
327
+
328
+ data = data.map (x) =>
329
+ instance = @build x
330
+ # Substitute interpolation mask with actual path
331
+ instance.__source = @collectionPath where if where.length > 1
332
+ instance
333
+
334
+ result.load data...
335
+
336
+ callback?(error, result, rawData, xhr)
337
+
338
+ result
339
+
301
340
  #
302
341
  # Wrapper for AJAX request
303
342
  #
@@ -322,20 +361,6 @@ class Joosy.Resources.REST extends Joosy.Resources.Base
322
361
 
323
362
  $.ajax options
324
363
 
325
- #
326
- # Refetches the data from backend and triggers `changed`
327
- #
328
- # @param [Hash] options See {Joosy.Resources.REST.find} for possible options
329
- # @param [Function] callback Resulting callback
330
- # @param [Object] callback `(error, instance, data) -> ...`
331
- #
332
- reload: (options={}, callback=false) ->
333
- [options, callback] = @__extractOptionsAndCallback(options, callback)
334
-
335
- @constructor.__query @memberPath(options), 'GET', options.params, (error, data, xhr) =>
336
- @load data if data?
337
- callback?(error, @, data, xhr)
338
-
339
364
  #
340
365
  # utility function for better API support for unrequired first options parameter
341
366
  #
@@ -190,11 +190,11 @@ class Joosy.Form extends Joosy.Module
190
190
  input.filter("[value='#{val}']").attr 'checked', 'checked'
191
191
  else
192
192
  input.val val
193
- if val instanceof Joosy.Resources.RESTCollection
194
- for entity, i in val.data
193
+ if val instanceof Joosy.Resources.Array
194
+ for entity, i in val
195
195
  filler entity.data, @concatFieldName(scope, "[#{property}_attributes][#{i}]")
196
196
  else if val instanceof Joosy.Resources.REST
197
- filler val.data, @concatFieldName(scope, "[#{property}_attributes][0]")
197
+ filler val.data, @concatFieldName(scope, "[#{property}_attributes]")
198
198
  else if Object.isObject(val) || Object.isArray(val)
199
199
  filler val, key
200
200
  else
@@ -0,0 +1,38 @@
1
+ #= require ../resources
2
+
3
+ Joosy.Modules.Resources.Cacher =
4
+
5
+ included: ->
6
+ @cache = (cacheKey) -> @::__cacheKey = cacheKey
7
+ @fetcher = (fetcher) -> @::__fetcher = fetcher
8
+
9
+ @cached = (callback, cacheKey=false, fetcher=false) ->
10
+ if typeof(cacheKey) == 'function'
11
+ fetcher = cacheKey
12
+ cacheKey = undefined
13
+
14
+ cacheKey ||= @::__cacheKey
15
+ fetcher ||= @::__fetcher
16
+
17
+ if cacheKey && localStorage && localStorage[cacheKey]
18
+ instance = new @ JSON.parse(localStorage[cacheKey])...
19
+ callback? instance
20
+ instance.refresh()
21
+ else
22
+ @fetch (results) =>
23
+ instance = new @ results...
24
+ callback? instance
25
+
26
+ @fetch = (callback) ->
27
+ @::__fetcher (results...) =>
28
+ localStorage[@::__cacheKey] = JSON.stringify(results) if @::__cacheKey && localStorage
29
+ callback results
30
+
31
+ refresh: (callback) ->
32
+ @constructor.fetch (results) =>
33
+ @load results...
34
+ callback? @
35
+
36
+ # AMD wrapper
37
+ if define?.amd?
38
+ define 'joosy/modules/resources/cacher', -> Joosy.Modules.Resources.Cacher
@@ -0,0 +1 @@
1
+ Joosy.Modules.Resources = {}
@@ -1,7 +1,11 @@
1
+ #= require joosy/modules/resources/cacher
2
+
1
3
  class Joosy.Resources.Array extends Array
2
4
 
3
- Joosy.Module.include.call @, Joosy.Modules.Events
4
- Joosy.Module.include.call @, Joosy.Modules.Filters
5
+ Joosy.Module.merge @, Joosy.Module
6
+
7
+ @include Joosy.Modules.Events
8
+ @include Joosy.Modules.Filters
5
9
 
6
10
  @registerPlainFilters 'beforeLoad'
7
11
 
@@ -19,6 +23,11 @@ class Joosy.Resources.Array extends Array
19
23
  load: ->
20
24
  @__fillData arguments
21
25
 
26
+ clone: (callback) ->
27
+ clone = new @constructor
28
+ clone.data = @slice 0
29
+ clone
30
+
22
31
  push: ->
23
32
  result = super
24
33
  @trigger 'changed'
@@ -45,10 +54,7 @@ class Joosy.Resources.Array extends Array
45
54
  result
46
55
 
47
56
  __fillData: (data, notify=true) ->
48
- data = if data[0] instanceof Array
49
- data[0]
50
- else
51
- @slice.call(data, 0)
57
+ data = @slice.call(data, 0)
52
58
 
53
59
  @splice 0, @length if @length > 0
54
60
  @push entry for entry in @__applyBeforeLoads(data)
@@ -1,8 +1,12 @@
1
+ #= require joosy/modules/resources/cacher
2
+
1
3
  class Joosy.Resources.Hash extends Joosy.Function
2
4
 
3
5
  @include Joosy.Modules.Events
4
6
  @include Joosy.Modules.Filters
5
7
 
8
+ @registerPlainFilters 'beforeLoad'
9
+
6
10
  constructor: (data={}) ->
7
11
  return super ->
8
12
  @__fillData data, false
@@ -32,11 +36,14 @@ class Joosy.Resources.Hash extends Joosy.Function
32
36
  @__fillData data
33
37
  @
34
38
 
39
+ clone: (callback) ->
40
+ new @constructor Object.clone(@data, true)
41
+
35
42
  __call: (path, value) ->
36
43
  if arguments.length > 1
37
- @__set path, value
44
+ @set path, value
38
45
  else
39
- @__get path
46
+ @get path
40
47
 
41
48
  #
42
49
  # Locates the actual instance of attribute path `foo.bar` from get/set
@@ -1,23 +1,30 @@
1
+ #= require joosy/modules/resources/cacher
2
+
1
3
  class Joosy.Resources.Scalar extends Joosy.Function
2
4
 
3
5
  @include Joosy.Modules.Events
4
6
  @include Joosy.Modules.Filters
5
7
 
8
+ @registerPlainFilters 'beforeLoad'
9
+
6
10
  constructor: (value) ->
7
11
  return super ->
8
- @value = value
12
+ @load value
9
13
 
10
14
  get: ->
11
15
  @value
12
16
 
13
- set: ->
14
- @load arguments...
17
+ set: (@value) ->
18
+ @trigger 'changed'
15
19
 
16
20
  load: (value) ->
17
21
  @value = @__applyBeforeLoads(value)
18
22
  @trigger 'changed'
19
23
  @value
20
24
 
25
+ clone: (callback) ->
26
+ new @constructor @value
27
+
21
28
  __call: ->
22
29
  if arguments.length > 0
23
30
  @set arguments[0]
@@ -0,0 +1,81 @@
1
+ describe 'Joosy.Modules.Resources.Cacher', ->
2
+
3
+ beforeEach ->
4
+ @spy = sinon.spy()
5
+
6
+ afterEach ->
7
+ localStorage.clear()
8
+
9
+ describe 'Scalar', ->
10
+
11
+ beforeEach ->
12
+ spy = @spy
13
+
14
+ class @Cacher extends Joosy.Resources.Scalar
15
+ @include Joosy.Modules.Resources.Cacher
16
+
17
+ @cache 'scalar'
18
+ @fetcher (callback) ->
19
+ spy(); callback 1
20
+
21
+ it 'caches', ->
22
+ @Cacher.cached (instance) =>
23
+ expect(instance()).toEqual 1
24
+
25
+ expect(localStorage['scalar']).toEqual '[1]'
26
+ expect(@spy.callCount).toEqual 1
27
+
28
+ instance.refresh (instance) =>
29
+ expect(instance()).toEqual 1
30
+ expect(@spy.callCount).toEqual 2
31
+
32
+ describe 'Array', ->
33
+
34
+ beforeEach ->
35
+ spy = @spy
36
+
37
+ class @Cacher extends Joosy.Resources.Array
38
+ @include Joosy.Modules.Resources.Cacher
39
+
40
+ @cache 'array'
41
+ @fetcher (callback) ->
42
+ spy(); callback 1, 2
43
+
44
+ it 'caches', ->
45
+ @Cacher.cached (instance) =>
46
+ expect(instance[0]).toEqual 1
47
+ expect(instance[1]).toEqual 2
48
+ expect(instance.length).toEqual 2
49
+
50
+ expect(localStorage['array']).toEqual '[1,2]'
51
+ expect(@spy.callCount).toEqual 1
52
+
53
+ instance.refresh (instance) =>
54
+ expect(instance[0]).toEqual 1
55
+ expect(instance[1]).toEqual 2
56
+ expect(instance.length).toEqual 2
57
+
58
+ expect(@spy.callCount).toEqual 2
59
+
60
+ describe 'Hash', ->
61
+
62
+ beforeEach ->
63
+ spy = @spy
64
+
65
+ class @Cacher extends Joosy.Resources.Hash
66
+ @include Joosy.Modules.Resources.Cacher
67
+
68
+ @cache 'hash'
69
+ @fetcher (callback) ->
70
+ spy(); callback {foo: 'bar'}
71
+
72
+ it 'caches', ->
73
+ @Cacher.cached (instance) =>
74
+ expect(instance.data).toEqual {foo: 'bar'}
75
+
76
+ expect(localStorage['hash']).toEqual '[{"foo":"bar"}]'
77
+ expect(@spy.callCount).toEqual 1
78
+
79
+ instance.refresh (instance) =>
80
+ expect(instance.data).toEqual {foo: 'bar'}
81
+ expect(@spy.callCount).toEqual 2
@@ -0,0 +1,60 @@
1
+ describe "Joosy.Resources.Array", ->
2
+
3
+ describe 'in general', ->
4
+ beforeEach ->
5
+ @array = new Joosy.Resources.Array(1, 2, 3)
6
+
7
+ it 'wraps', ->
8
+ expect(@array instanceof Array).toBeTruthy()
9
+ expect(@array.length).toEqual 3
10
+ expect(@array[0]).toEqual 1
11
+ expect(@array[1]).toEqual 2
12
+ expect(@array[2]).toEqual 3
13
+
14
+ it 'clones', ->
15
+ clone = @array.clone()
16
+ clone.push 5
17
+ clone.unshift 6
18
+ expect(@array.length).toEqual 3
19
+ expect(@array[0]).toEqual 1
20
+ expect(@array[1]).toEqual 2
21
+ expect(@array[2]).toEqual 3
22
+
23
+ it 'triggers', ->
24
+ spy = sinon.spy()
25
+ @array.bind 'changed', spy
26
+
27
+ @array.set(0, 0)
28
+ expect(@array[0]).toEqual 0
29
+
30
+ @array.unshift(9)
31
+ expect(@array[0]).toEqual 9
32
+ expect(@array.length).toEqual 4
33
+
34
+ expect(@array.shift()).toEqual 9
35
+ expect(@array.length).toEqual 3
36
+
37
+ expect(@array.push(9)).toEqual 4
38
+ expect(@array.length).toEqual 4
39
+ expect(@array[3]).toEqual 9
40
+
41
+ expect(@array.pop()).toEqual 9
42
+ expect(@array.length).toEqual 3
43
+
44
+ expect(spy.callCount).toEqual 5
45
+
46
+ describe 'filters', ->
47
+ it 'runs beforeFilter', ->
48
+ class RealArray extends Joosy.Resources.Array
49
+ @beforeLoad (data) ->
50
+ data.push 2
51
+ data
52
+
53
+ array = new RealArray(1)
54
+ expect(array[0]).toEqual 1
55
+ expect(array[1]).toEqual 2
56
+
57
+ array.load(5,6)
58
+ expect(array[0]).toEqual 5
59
+ expect(array[1]).toEqual 6
60
+ expect(array[2]).toEqual 2
@@ -0,0 +1,58 @@
1
+ describe "Joosy.Resources.Hash", ->
2
+
3
+ describe 'in general', ->
4
+ beforeEach ->
5
+ @hash = new Joosy.Resources.Hash({foo: 'bar', bar: {baz: 'yummy!'}})
6
+
7
+ it 'wraps', ->
8
+ expect(typeof(@hash)).toEqual 'function'
9
+ expect(@hash 'foo').toEqual 'bar'
10
+ expect(@hash 'bar').toEqual {baz: 'yummy!'}
11
+ expect(@hash 'bar.baz').toEqual 'yummy!'
12
+
13
+ it 'clones', ->
14
+ clone = @hash.clone()
15
+ clone.data.foo = 'new'
16
+ clone('bar', 'new as well')
17
+ expect(@hash 'foo').toEqual 'bar'
18
+ expect(@hash 'bar').toEqual {baz: 'yummy!'}
19
+ expect(@hash 'bar.baz').toEqual 'yummy!'
20
+
21
+ it 'sets', ->
22
+ @hash('bar.baz', 'the ignition')
23
+ expect(@hash.data.bar.baz).toEqual 'the ignition'
24
+ expect(@hash 'bar.baz').toEqual 'the ignition'
25
+
26
+ it 'gets', ->
27
+ expect(@hash 'foo.bar.baz').toBeUndefined()
28
+ expect(@hash.data.foo.bar).toBeUndefined()
29
+
30
+ it 'triggers', ->
31
+ spy = sinon.spy()
32
+ @hash.bind 'changed', spy
33
+
34
+ @hash 'bar.baz', 'rocking'
35
+ expect(spy.callCount)
36
+
37
+ describe 'nested hash', ->
38
+ beforeEach ->
39
+ @nested = new Joosy.Resources.Hash(trolo: 'lo')
40
+ @hash = new Joosy.Resources.Hash({foo: 'bar', bar: @nested})
41
+
42
+ it 'gets', ->
43
+ expect(@hash 'bar.trolo').toEqual 'lo'
44
+
45
+ it 'sets', ->
46
+ @hash 'bar.trolo', 'lolo'
47
+ expect(@nested.data.trolo).toEqual 'lolo'
48
+
49
+ describe 'filters', ->
50
+ it 'runs beforeFilter', ->
51
+ class Hash extends Joosy.Resources.Hash
52
+ @beforeLoad (data) ->
53
+ data.test = true
54
+ data
55
+
56
+ hash = new Hash(foo: 'bar')
57
+ expect(hash.data.test).toBeTruthy()
58
+ expect(hash 'test').toBeTruthy()
@@ -0,0 +1,41 @@
1
+ describe "Joosy.Resources.Scalar", ->
2
+
3
+ describe 'in general', ->
4
+ beforeEach ->
5
+ @scalar = new Joosy.Resources.Scalar(5)
6
+
7
+ it 'wraps', ->
8
+ expect(@scalar+1).toEqual(6)
9
+ expect("#{@scalar}").toEqual('5')
10
+
11
+ it 'clones', ->
12
+ clone = @scalar.clone()
13
+ clone.set(1)
14
+ expect(@scalar()).toEqual(5)
15
+
16
+ it 'triggers', ->
17
+ spy = sinon.spy()
18
+ @scalar.bind 'changed', spy
19
+
20
+ @scalar.set(7)
21
+ expect(@scalar.get()).toEqual 7
22
+
23
+ @scalar.load(8)
24
+ expect(@scalar.get()).toEqual 8
25
+
26
+ expect(spy.callCount).toEqual 2
27
+
28
+ describe 'filters', ->
29
+ it 'runs beforeFilter', ->
30
+ class Scalar extends Joosy.Resources.Scalar
31
+ @beforeLoad (data) ->
32
+ data + 1
33
+
34
+ scalar = new Scalar(5)
35
+ expect(scalar.get()).toEqual 6
36
+
37
+ scalar.set(5)
38
+ expect(scalar.get()).toEqual 5
39
+
40
+ scalar.load(7)
41
+ expect(scalar.get()).toEqual 8
@@ -29,10 +29,10 @@ describe "Joosy", ->
29
29
  'joosy/modules/filters',
30
30
  'joosy/modules/log',
31
31
  'joosy/modules/renderer',
32
+ 'joosy/modules/resources/cacher',
32
33
  'joosy/modules/time_manager',
33
34
  'joosy/page',
34
35
  'joosy/resources/array',
35
- 'joosy/resources/cacher',
36
36
  'joosy/resources/hash',
37
37
  'joosy/resources/scalar',
38
38
  'joosy/router',
@@ -8,7 +8,7 @@ describe "Joosy.Form", ->
8
8
  @nudeForm = "<form id='nude'><input name='test[foo]'/><input name='test[bar]'/><input name='test[bool]' type='checkbox' value='1'/><input name='test[set]' type='radio' value='qwe' /><input name='test[set]' type='radio' value='zxc' /></form>"
9
9
  @putForm = "<form id='put' method='put'><input name='test[camel_baz]'/></form>"
10
10
  @moreForm = "<form id='more' method='put'><input name='test[ololo]'/></form>"
11
- @nestedForm = "<form id='nested'><input name='test[zee][capped][test]'/><input name='test[items_attributes][0][attr]'/><input name='test[items_attributes][1][attr]'/><input name='test[single_attributes][0][attr]'/></form>"
11
+ @nestedForm = "<form id='nested'><input name='test[zee][capped][test]'/><input name='test[items_attributes][0][attr]'/><input name='test[items_attributes][1][attr]'/><input name='test[single_attributes][attr]'/></form>"
12
12
  @exactForm = "<form id='exact'><input name='test[EXact][MATCH]'/></form>"
13
13
  @arrayForm = "<form id='array'><input name='test[arr][1][0][1]'/></form>"
14
14
 
@@ -38,7 +38,7 @@ describe "Joosy.Form", ->
38
38
  test: 'test'
39
39
  EXact:
40
40
  MATCH: 'works'
41
- items: (new Joosy.Resources.RESTCollection(Test)).load([{attr: 'one'}, {attr: 'two'}])
41
+ items: new Joosy.Resources.Array Test.build(attr: 'one'), Test.build(attr: 'two')
42
42
  single: Test.build(attr: 'sin')
43
43
 
44
44
  afterEach ->
@@ -85,49 +85,14 @@ describe "Joosy.Resources.Base", ->
85
85
  {foo: 'bar'},
86
86
  {bar: 'baz'}
87
87
  ]
88
- expect(resource('rumbaMumbas') instanceof Joosy.Resources.Collection).toBeTruthy()
89
- expect(resource('rumbaMumbas').at(0)('foo')).toEqual 'bar'
88
+ expect(resource('rumbaMumbas') instanceof Joosy.Resources.Array).toBeTruthy()
89
+ expect(resource('rumbaMumbas')[0]('foo')).toEqual 'bar'
90
90
 
91
91
  resource = S.build
92
92
  rumbaMumba: {foo: 'bar'}
93
93
  expect(resource('rumbaMumba') instanceof Joosy.Resources.Base).toBeTruthy()
94
94
  expect(resource('rumbaMumba.foo')).toEqual 'bar'
95
95
 
96
- it "should use magic collections", ->
97
- class window.RumbaMumbasCollection extends Joosy.Resources.Collection
98
-
99
- class RumbaMumba extends Joosy.Resources.Base
100
- @entity 'rumba_mumba'
101
- class R extends Joosy.Resources.Base
102
- @map 'rumbaMumbas', RumbaMumba
103
-
104
- resource = R.build
105
- rumbaMumbas: [
106
- {foo: 'bar'},
107
- {bar: 'baz'}
108
- ]
109
- expect(resource('rumbaMumbas') instanceof RumbaMumbasCollection).toBeTruthy()
110
- expect(resource('rumbaMumbas').at(0)('foo')).toEqual 'bar'
111
-
112
- window.RumbaMumbasCollection = undefined
113
-
114
- it "should use manually set collections", ->
115
- class OloCollection extends Joosy.Resources.Collection
116
-
117
- class RumbaMumba extends Joosy.Resources.Base
118
- @entity 'rumba_mumba'
119
- @collection OloCollection
120
- class R extends Joosy.Resources.Base
121
- @map 'rumbaMumbas', RumbaMumba
122
-
123
- resource = R.build
124
- rumbaMumbas: [
125
- {foo: 'bar'},
126
- {bar: 'baz'}
127
- ]
128
- expect(resource('rumbaMumbas') instanceof OloCollection).toBeTruthy()
129
- expect(resource('rumbaMumbas').at(0)('foo')).toEqual 'bar'
130
-
131
96
  describe "identity map", ->
132
97
  it "handles builds", ->
133
98
  foo = Test.build 1