joosy 1.2.0.alpha.58 → 1.2.0.alpha.59

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,31 +18,52 @@ class Joosy.Resources.REST extends Joosy.Resources.Base
18
18
  @__source = location
19
19
 
20
20
  #
21
- # Creates the proxy of current resource binded as a child of given entity
21
+ # Makes needed changes with clone/wrapper for @at method to extend its' path
22
22
  #
23
- @at: (args...) ->
24
- #
25
- # Class inheritance used to create proxy
26
- #
27
- # @private
28
- #
29
- class Clone extends this
30
-
23
+ @__atWrapper: (definer, args...) ->
31
24
  if args.length == 1 && Object.isArray(args[0])
32
- @at(args[0]...)
25
+ @__atWrapper(definer, args[0]...)
33
26
  else
34
- Clone.__source = args.reduce (path, arg) ->
35
- path += if arg instanceof Joosy.Resources.Base
36
- arg.memberPath()
37
- else
38
- arg.replace(/^\/?/, '/')
27
+ definer (clone) =>
28
+ clone.__source = args.reduce (path, arg) ->
29
+ path += if arg instanceof Joosy.Resources.REST
30
+ arg.memberPath()
31
+ else
32
+ arg.replace(/^\/?/, '/')
33
+ , ''
34
+ clone.__source += '/' + @::__entityName.pluralize()
39
35
 
40
- , ''
36
+ #
37
+ # Creates the proxy of current resource binded as a child of given entity
38
+ #
39
+ # @param [Array] args Array of parent entities. Can be a string or another REST resource.
40
+ #
41
+ # @example Basic usage
42
+ # Comment.at(['admin', @blog, @post]).collectionPath() # => '/admin/blogs/555/posts/666/comments'
43
+ #
44
+ # @note accepts both array notation (Comment.at(['admin', @blog, @post])) and args notation (Comment.at('admin', @blog, @post))
45
+ #
46
+ @at: (args...) ->
47
+ @__atWrapper (callback) =>
48
+ class Clone extends @
49
+ callback(@)
50
+ , args...
41
51
 
42
- if @::__entityName && args[args.length - 1] instanceof Joosy.Resources.Base
43
- Clone.__source += '/' + @::__entityName.pluralize()
44
52
 
45
- Clone
53
+ #
54
+ # Creates the proxy of current resource instance binded as a child of given entity
55
+ #
56
+ # @param [Array] args Array of parent entities. Can be a string or another REST resource.
57
+ #
58
+ # @example Basic usage
59
+ # Comment.build(1).at(['admin', @blog, @post]).memberPath() # => '/admin/blogs/555/posts/666/comments/1'
60
+ #
61
+ # @note accepts both array notation (comment.at(['admin', @blog, @post])) and args notation (comment.at('admin', @blog, @post))
62
+ #
63
+ at: (args...) ->
64
+ @constructor.__atWrapper (callback) =>
65
+ Object.tap @constructor.__makeShim(@), callback
66
+ , args...
46
67
 
47
68
  #
48
69
  # Implements `@collection` default behavior.
@@ -52,54 +73,53 @@ class Joosy.Resources.REST extends Joosy.Resources.Base
52
73
  named = @__entityName.camelize().pluralize() + 'Collection'
53
74
  if window[named] then window[named] else Joosy.Resources.RESTCollection
54
75
 
76
+
55
77
  #
56
- # Builds parents part of member path based on parents array
57
- #
58
- # @param [Array] parents Array of parents
59
- #
60
- # @example Basic usage
61
- # Resource.__parentsPath([otherResource, '/bars/1']) # /other_resources/1/bars/1
78
+ # Interpolates path with masks by given array of params
62
79
  #
63
- @__parentsPath: (parents) ->
64
- parents.reduce (path, parent) ->
65
- path += if Joosy.Module.hasAncestor parent.constructor, Joosy.Resources.REST
66
- parent.memberPath()
67
- else
68
- parent
69
- , ''
80
+ __interpolatePath: (source, ids) ->
81
+ ids = [ids] unless Object.isArray(ids)
82
+ ids.reduce (path, id) ->
83
+ id = id.id() if id instanceof Joosy.Resources.REST
84
+ path.replace /:[^\/]+/, id
85
+ , source
70
86
 
71
87
  #
72
88
  # Builds collection path
73
89
  #
90
+ # @param [Array] id IDs for interpolation for masked sources
74
91
  # @param [Hash] options See {Joosy.Resources.REST.find} for possible options
75
92
  #
76
93
  # @example Basic usage
77
94
  # Resource.collectionPath() # /resources/
78
95
  #
79
- @collectionPath: (options={}) ->
96
+ @collectionPath: (args...) ->
97
+ @::collectionPath args...
98
+
99
+ #
100
+ # Builds collection path
101
+ #
102
+ # @see Joosy.Resources.REST.collectionPath
103
+ #
104
+ collectionPath: (ids=[], options={}) ->
105
+ if Object.isObject(ids)
106
+ options = ids
107
+ ids = []
108
+
80
109
  return options.url if options.url
81
110
 
82
- if @__source? && !options.parent?
83
- path = @__source
111
+ source = @__source || @constructor.__source
112
+
113
+ if source
114
+ path = @__interpolatePath source, ids
84
115
  else
85
116
  path = '/'
86
- path += @__namespace__.map((s)-> s.toLowerCase()).join('/') + '/' if @__namespace__.length > 0
87
- path += @::__entityName.pluralize()
88
-
89
- if options.parent?
90
- path = @__parentsPath(if Object.isArray(options.parent) then options.parent else [options.parent]) + path
91
-
92
- path += "/#{options.from}" if options.from?
117
+ path += @constructor.__namespace__.map(String::underscore).join('/') + '/' if @constructor.__namespace__.length > 0
118
+ path += @__entityName.pluralize()
93
119
 
120
+ path += "/#{options.from}" if options.from
94
121
  path
95
122
 
96
- #
97
- # Builds collection path
98
- #
99
- # @see Joosy.Resources.REST.collectionPath
100
- #
101
- collectionPath: (options={}) ->
102
- @constructor.collectionPath options
103
123
 
104
124
  #
105
125
  # Builds member path based on the given id.
@@ -110,13 +130,8 @@ class Joosy.Resources.REST extends Joosy.Resources.Base
110
130
  # @example Basic usage
111
131
  # Resource.memberPath(1, from: 'foo') # /resources/1/foo
112
132
  #
113
- @memberPath: (id, options={}) ->
114
- return options.url if options.url
115
-
116
- from = options.from
117
- path = @collectionPath(Object.merge(options, from: undefined)) + "/#{id}"
118
- path += "/#{from}" if from?
119
- path
133
+ @memberPath: (args...) ->
134
+ @::memberPath args...
120
135
 
121
136
  #
122
137
  # Builds member path
@@ -126,8 +141,22 @@ class Joosy.Resources.REST extends Joosy.Resources.Base
126
141
  # @example Basic usage
127
142
  # resource.memberPath(from: 'foo') # /resources/1/foo
128
143
  #
129
- memberPath: (options={}) ->
130
- @constructor.memberPath @id(), options
144
+ memberPath: (ids=[], options={}) ->
145
+ if Object.isObject(ids)
146
+ options = ids
147
+ ids = []
148
+
149
+ return options.url if options.url
150
+
151
+ ids = [ids] unless Object.isArray(ids)
152
+ id = @id() || ids.pop()
153
+
154
+ from = options.from
155
+
156
+ ids.push @id()
157
+ path = @collectionPath(ids, Object.merge(options, from: undefined)) + "/#{id}"
158
+ path += "/#{from}" if from?
159
+ path
131
160
 
132
161
  #
133
162
  # Sends the GET query using collectionPath.
@@ -138,9 +167,7 @@ class Joosy.Resources.REST extends Joosy.Resources.Base
138
167
  # @param [Object] callback Success and Error callbacks to run `{ success: () ->, error: () -> }`
139
168
  #
140
169
  @get: (options, callback) ->
141
- if Object.isFunction(options)
142
- callback = options
143
- options = {}
170
+ [options, callback] = @::__extractOptionsAndCallback(options, callback)
144
171
  @__query @collectionPath(options), 'GET', options.params, callback
145
172
 
146
173
  #
@@ -152,9 +179,7 @@ class Joosy.Resources.REST extends Joosy.Resources.Base
152
179
  # @param [Object] callback Success and Error callbacks to run `{ success: () ->, error: () -> }`
153
180
  #
154
181
  @post: (options, callback) ->
155
- if Object.isFunction(options)
156
- callback = options
157
- options = {}
182
+ [options, callback] = @::__extractOptionsAndCallback(options, callback)
158
183
  @__query @collectionPath(options), 'POST', options.params, callback
159
184
 
160
185
  #
@@ -166,9 +191,7 @@ class Joosy.Resources.REST extends Joosy.Resources.Base
166
191
  # @param [Object] callback Success and Error callbacks to run `{ success: () ->, error: () -> }`
167
192
  #
168
193
  @put: (options, callback) ->
169
- if Object.isFunction(options)
170
- callback = options
171
- options = {}
194
+ [options, callback] = @::__extractOptionsAndCallback(options, callback)
172
195
  @__query @collectionPath(options), 'PUT', options.params, callback
173
196
 
174
197
  #
@@ -180,9 +203,7 @@ class Joosy.Resources.REST extends Joosy.Resources.Base
180
203
  # @param [Object] callback Success and Error callbacks to run `{ success: () ->, error: () -> }`
181
204
  #
182
205
  @delete: (options, callback) ->
183
- if Object.isFunction(options)
184
- callback = options
185
- options = {}
206
+ [options, callback] = @::__extractOptionsAndCallback(options, callback)
186
207
  @__query @collectionPath(options), 'DELETE', options.params, callback
187
208
 
188
209
  #
@@ -194,9 +215,7 @@ class Joosy.Resources.REST extends Joosy.Resources.Base
194
215
  # @param [Object] callback Success and Error callbacks to run `{ success: () ->, error: () -> }`
195
216
  #
196
217
  get: (options, callback) ->
197
- if Object.isFunction(options)
198
- callback = options
199
- options = {}
218
+ [options, callback] = @__extractOptionsAndCallback(options, callback)
200
219
  @constructor.__query @memberPath(options), 'GET', options.params, callback
201
220
 
202
221
  #
@@ -208,9 +227,7 @@ class Joosy.Resources.REST extends Joosy.Resources.Base
208
227
  # @param [Object] callback Success and Error callbacks to run `{ success: () ->, error: () -> }`
209
228
  #
210
229
  post: (options, callback) ->
211
- if Object.isFunction(options)
212
- callback = options
213
- options = {}
230
+ [options, callback] = @__extractOptionsAndCallback(options, callback)
214
231
  @constructor.__query @memberPath(options), 'POST', options.params, callback
215
232
 
216
233
  #
@@ -222,9 +239,7 @@ class Joosy.Resources.REST extends Joosy.Resources.Base
222
239
  # @param [Object] callback Success and Error callbacks to run `{ success: () ->, error: () -> }`
223
240
  #
224
241
  put: (options, callback) ->
225
- if Object.isFunction(options)
226
- callback = options
227
- options = {}
242
+ [options, callback] = @__extractOptionsAndCallback(options, callback)
228
243
  @constructor.__query @memberPath(options), 'PUT', options.params, callback
229
244
 
230
245
  #
@@ -235,9 +250,7 @@ class Joosy.Resources.REST extends Joosy.Resources.Base
235
250
  # @param [Function] callback Resulting callback
236
251
  #
237
252
  delete: (options, callback) ->
238
- if Object.isFunction(options)
239
- callback = options
240
- options = {}
253
+ [options, callback] = @__extractOptionsAndCallback(options, callback)
241
254
  @constructor.__query @memberPath(options), 'DELETE', options.params, callback
242
255
 
243
256
  #
@@ -251,33 +264,36 @@ class Joosy.Resources.REST extends Joosy.Resources.Base
251
264
  # @param [Function] callback Resulting callback
252
265
  # (will receive retrieved Collection/Resource)
253
266
  #
254
- # @option options [Joosy.Resources.REST] parent Sets the given resource as a base path
255
- # i.e. /parents/1/resources
256
- # @option options [String] parent Sets the given staring as a base path
257
- # i.e. /trololo/resources
258
267
  # @option options [String] from Adds the given string as a last path element
259
268
  # i.e. /resources/trololo
269
+ # @option options [String] url Sets url for request instead of generated
270
+ # i.e. /some/custom/url
260
271
  # @option options [Hash] params Passes the given params to the query
261
272
  #
262
273
  @find: (where, options={}, callback=false) ->
263
- if Object.isFunction(options)
264
- callback = options
265
- options = {}
274
+ [options, callback] = @::__extractOptionsAndCallback(options, callback)
266
275
 
267
- if where == 'all'
268
- result = new (@::__collection()) this, options
276
+ id = if Object.isArray(where) then where.last() else where
269
277
 
270
- @__query @collectionPath(options), 'GET', options.params, (data) =>
271
- result.load data
272
- callback?(result, data)
278
+ if id == 'all'
279
+ result = new (@::__collection()) this, options
280
+ path = @collectionPath where, options
273
281
  else
274
- result = @build where
275
- @__query @memberPath(where, options), 'GET', options.params, (data) =>
276
- result.load data
277
- callback?(result, data)
282
+ result = @build id
283
+ path = @memberPath where, options
284
+
285
+ if Object.isArray(where) && where.length > 1
286
+ result.__source = @collectionPath where
287
+
288
+ @__query path, 'GET', options.params, (data) =>
289
+ result.load data
290
+ callback?(result, data)
278
291
 
279
292
  result
280
293
 
294
+ #
295
+ # Wrapper for AJAX request
296
+ #
281
297
  @__query: (path, method, params, callback) ->
282
298
  options =
283
299
  data: params
@@ -300,10 +316,17 @@ class Joosy.Resources.REST extends Joosy.Resources.Base
300
316
  # @param [Object] callback Success and Error callbacks to run `{ success: () ->, error: () -> }`
301
317
  #
302
318
  reload: (options={}, callback=false) ->
303
- if Object.isFunction(options)
304
- callback = options
305
- options = {}
319
+ [options, callback] = @__extractOptionsAndCallback(options, callback)
306
320
 
307
321
  @constructor.__query @memberPath(options), 'GET', options.params, (data) =>
308
322
  @load data
309
323
  callback? this
324
+
325
+ #
326
+ # utility function for better API support for unrequired first options parameter
327
+ #
328
+ __extractOptionsAndCallback: (options, callback) ->
329
+ if Object.isFunction(options)
330
+ callback = options
331
+ options = {}
332
+ [options, callback]
@@ -22,6 +22,12 @@ class Joosy.Resources.RESTCollection extends Joosy.Resources.Collection
22
22
  callback = options
23
23
  options = {}
24
24
 
25
- @model.__query @model.collectionPath(options), 'GET', options.params, (data) =>
25
+ @model.__query @model.collectionPath(options, @__source), 'GET', options.params, (data) =>
26
26
  @load data
27
27
  callback?(data)
28
+
29
+ load: (args...) ->
30
+ res = super(args...)
31
+ @data.each (x) =>
32
+ x.__source = @__source
33
+ res
@@ -330,6 +330,8 @@ class Joosy.Form extends Joosy.Module
330
330
  __stringifyErrors: (errors) ->
331
331
  result = {}
332
332
 
333
+ errors = errors.errors if Object.isObject(errors?.errors)
334
+
333
335
  Object.each errors, (field, notifications) =>
334
336
  if @substitutions[field]?
335
337
  field = @substitutions[field]
@@ -8,8 +8,8 @@ Joosy.helpers 'Routes', ->
8
8
 
9
9
  @linkTo = (name='', url='', tagOptions={}) ->
10
10
  if Object.isFunction tagOptions
11
- url = name
12
- tagOptions = url
13
- name = tagOptions()
11
+ block = tagOptions
12
+ [url, tagOptions] = [name, url]
13
+ name = block()
14
14
 
15
15
  Joosy.Helpers.Application.contentTag 'a', name, Joosy.Module.merge(tagOptions, 'data-joosy': true, href: url)
@@ -78,7 +78,7 @@
78
78
  generator = generator.apply space
79
79
  for key, klass of space
80
80
  if space.hasOwnProperty(key) &&
81
- Joosy.Module.hasAncestor klass, Joosy.Module
81
+ Joosy.Module.hasAncestor(klass, Joosy.Module)
82
82
  klass.__namespace__ = name
83
83
 
84
84
  #
@@ -13,7 +13,7 @@ class Joosy.Module
13
13
  # Gets Object/Class class name.
14
14
  #
15
15
  # @note Never use this to make some magical auto-suggestions!!!
16
- # Remember: minifcation will rename your classes. Therefore it
16
+ # Remember: minification will rename your classes. Therefore it
17
17
  # is only intended for development debugging purposes.
18
18
  #
19
19
  # @return [String]
@@ -9,7 +9,7 @@
9
9
  # Internal storage rules:
10
10
  #
11
11
  # * HTML5 Prefix option is stored with both leading and trailing slashes
12
- # * Helpers pathes are stored without leading trailing slash
12
+ # * Helpers' paths are stored without leading trailing slash
13
13
  # * Route matchers declare leading and trailing slashes as optional
14
14
  #
15
15
  # @example
@@ -0,0 +1,9 @@
1
+ describe "Joosy.Helpers.Routes", ->
2
+
3
+ it "renders data-joosy links", ->
4
+ link = Joosy.Helpers.Routes.linkTo 'test', '/app/link', nice: true
5
+ expect(link).toEqual '<a nice="true" data-joosy="true" href="/app/link">test</a>'
6
+
7
+ it "renders data-joosy links yielding block", ->
8
+ link = Joosy.Helpers.Routes.linkTo '/app/link', nice: true, -> 'test'
9
+ expect(link).toEqual '<a nice="true" data-joosy="true" href="/app/link">test</a>'
@@ -241,6 +241,10 @@ describe "Joosy.Form", ->
241
241
  @target.respond 422, 'Content-Type': 'application/json', '{"foo": "error!"}'
242
242
  expect($(@nudeForm.$fields()[0]).attr 'class').toEqual 'field_with_errors'
243
243
 
244
+ it "should fill class for invalidated fields by default", ->
245
+ @target.respond 422, 'Content-Type': 'application/json', '{"errors":{"foo": "error!"}}'
246
+ expect($(@nudeForm.$fields()[0]).attr 'class').toEqual 'field_with_errors'
247
+
244
248
  it "should trigger 'error' and complete default action if it returned true", ->
245
249
  @nudeForm.error = sinon.spy ->
246
250
  true
@@ -312,7 +316,7 @@ describe "Joosy.Form", ->
312
316
 
313
317
  expect(result).toEqual { "test[zombie]": ['suck'], "test[puppies]": ['rock'] }
314
318
 
315
- it "should prepare complexe response", ->
319
+ it "should prepare complex response", ->
316
320
  @nudeForm.fill @resource
317
321
  errors = {fluffies: {zombie: {mumbas: ['ololo']}}}
318
322
  result = @nudeForm.__stringifyErrors(errors)
@@ -13,6 +13,10 @@ describe "Joosy.Resources.REST", ->
13
13
  @entity 'fluffy'
14
14
  @map 'fluffy_inlines', FluffyInline
15
15
 
16
+ class Interpolated extends Joosy.Resources.REST
17
+ @entity 'test'
18
+ @source '/grand_parents/:grand_parent_id/parents/:parent_id/tests'
19
+
16
20
  Joosy.namespace 'Animal', ->
17
21
  class @Cat extends Joosy.Resources.REST
18
22
  @entity 'cat'
@@ -38,54 +42,87 @@ describe "Joosy.Resources.REST", ->
38
42
 
39
43
  it 'returns base class child', ->
40
44
  clone = @Test.at 'rumbas'
41
- expect(Joosy.Module.hasAncestor clone, @Test).toBeTruthy()
45
+ expect(Joosy.Module.hasAncestor(clone, @Test)).toBeTruthy()
42
46
 
43
47
  it 'accepts string', ->
44
48
  clone = @Test.at 'rumbas'
45
- expect(clone.__source).toEqual '/rumbas'
49
+ expect(clone.collectionPath()).toEqual '/rumbas/tests'
50
+
51
+ it 'makes a class whose instances get new source too', ->
52
+ clone = @Test.at 'rumbas'
53
+ expect(clone.build(1).memberPath()).toEqual '/rumbas/tests/1'
46
54
 
47
55
  it 'accepts another resource instance', ->
48
56
  clone = @Test.at Fluffy.build(1)
49
- expect(clone.__source).toEqual '/fluffies/1/tests'
57
+ expect(clone.collectionPath()).toEqual '/fluffies/1/tests'
50
58
 
51
59
  it 'accepts array', ->
52
60
  clone = @Test.at ['rumbas', Fluffy.build(1), 'salsas']
53
- expect(clone.__source).toEqual '/rumbas/fluffies/1/salsas'
61
+ expect(clone.collectionPath()).toEqual '/rumbas/fluffies/1/salsas/tests'
54
62
 
55
63
  it 'accepts sequential attributes', ->
56
64
  clone = @Test.at 'rumbas', 'salsas', Fluffy.build(1)
57
- expect(clone.__source).toEqual '/rumbas/salsas/fluffies/1/tests'
65
+ expect(clone.collectionPath()).toEqual '/rumbas/salsas/fluffies/1/tests'
58
66
 
59
- describe '@memberPath', ->
67
+ describe '::at', ->
60
68
  beforeEach ->
61
- @parent = FluffyParent.build 1
62
- @grandParent = FluffyParent.build 666
69
+ class @Test extends Joosy.Resources.REST
70
+ @entity 'test'
71
+
72
+ it 'returns base class instance', ->
73
+ original = @Test.build id: 1, name: 'foobar'
74
+ clone = original.at 'rumbas'
75
+ expect(clone instanceof @Test).toBeTruthy()
76
+ expect(clone.data).toEqual original.data
77
+
78
+ it 'accepts string', ->
79
+ clone = @Test.build(1).at('rumbas')
80
+ expect(clone.memberPath()).toEqual '/rumbas/tests/1'
81
+
82
+ it 'accepts another resource instance', ->
83
+ clone = @Test.build(1).at(Fluffy.build(1))
84
+ expect(clone.memberPath()).toEqual '/fluffies/1/tests/1'
63
85
 
86
+ it 'accepts array', ->
87
+ clone = @Test.build(1).at ['rumbas', Fluffy.build(1), 'salsas']
88
+ expect(clone.memberPath()).toEqual '/rumbas/fluffies/1/salsas/tests/1'
89
+
90
+ it 'accepts sequential attributes', ->
91
+ clone = @Test.build(1).at 'rumbas', 'salsas', Fluffy.build(1)
92
+ expect(clone.memberPath()).toEqual '/rumbas/salsas/fluffies/1/tests/1'
93
+
94
+ describe '@memberPath', ->
64
95
  it 'builds member path', ->
65
96
  expect(Fluffy.memberPath 1).toEqual '/fluffies/1'
66
97
 
67
- it 'builds member path with single parent', ->
68
- expect(Fluffy.memberPath 1, parent: @parent).toEqual '/fluffy_parents/1/fluffies/1'
98
+ it 'builds member path with from', ->
99
+ expect(Fluffy.memberPath 1, from: 'test').toEqual '/fluffies/1/test'
69
100
 
70
- it 'builds member path with array parent', ->
71
- expect(Fluffy.memberPath 1, parent: [@grandParent, @parent]).toEqual '/fluffy_parents/666/fluffy_parents/1/fluffies/1'
101
+ describe 'with interpolation', ->
102
+ it 'builds member path', ->
103
+ expect(Interpolated.memberPath([1,2,3])).toEqual '/grand_parents/1/parents/2/tests/3'
72
104
 
73
- it 'builds member path with parent and from', ->
74
- expect(Fluffy.memberPath 1, parent: @parent, from: 'test').toEqual '/fluffy_parents/1/fluffies/1/test'
105
+ it 'saves member path for single instance', ->
106
+ item = Interpolated.find [1,2,3]
107
+ checkAndRespond @server.requests[0], 'GET', /^\/grand_parents\/1\/parents\/2\/tests\/3\?_=\d+/, '{"test": {"id": 3}}'
108
+ expect(item.memberPath()).toEqual '/grand_parents/1/parents/2/tests/3'
75
109
 
76
- it 'builds member path with parent, from and params', ->
77
- expect(Fluffy.memberPath 1, parent: @parent, from: 'test', params: {foo: 'bar'}).toEqual '/fluffy_parents/1/fluffies/1/test'
110
+ it 'saves member path for instances collection', ->
111
+ items = Interpolated.find [1,2,'all']
112
+ checkAndRespond @server.requests[0], 'GET', /^\/grand_parents\/1\/parents\/2\/tests\?_=\d+/, '{"tests": [{"test": {"id": 3}}]}'
113
+ expect(items.at(0).memberPath()).toEqual '/grand_parents/1/parents/2/tests/3'
78
114
 
115
+ describe '@collectionPath', ->
116
+ it 'builds collection path', ->
117
+ expect(Fluffy.collectionPath()).toEqual '/fluffies'
79
118
 
80
- it "builds collection path", ->
81
- parent = FluffyParent.build 1
82
- grandParent = FluffyParent.build 666
119
+ it 'builds collection path with from', ->
120
+ expect(Fluffy.collectionPath from: 'test').toEqual '/fluffies/test'
121
+
122
+ describe 'with interpolation', ->
123
+ it 'builds collection path', ->
124
+ expect(Interpolated.collectionPath([1,2])).toEqual '/grand_parents/1/parents/2/tests'
83
125
 
84
- expect(Fluffy.collectionPath()).toEqual '/fluffies'
85
- expect(Fluffy.collectionPath parent: parent).toEqual '/fluffy_parents/1/fluffies'
86
- expect(Fluffy.collectionPath parent: [grandParent, parent]).toEqual '/fluffy_parents/666/fluffy_parents/1/fluffies'
87
- expect(Fluffy.collectionPath parent: parent, from: 'test').toEqual '/fluffy_parents/1/fluffies/test'
88
- expect(Fluffy.collectionPath parent: parent, from: 'test', params: {foo: 'bar'}).toEqual '/fluffy_parents/1/fluffies/test'
89
126
 
90
127
  describe '@find(:id)', ->
91
128
  rawData = '{"fluffy": {"id": 1, "name": "test1"}}'
@@ -107,11 +144,6 @@ describe "Joosy.Resources.REST", ->
107
144
  checkAndRespond @server.requests[0], 'GET', /^\/fluffies\/1\/action\?_=\d+/, rawData
108
145
  expect(@callback.callCount).toEqual 1
109
146
 
110
- it "gets item with from and parent", ->
111
- resource = Fluffy.find 1, {parent: FluffyParent.build(1), from: 'action'}, @callback
112
- checkAndRespond @server.requests[0], 'GET', /^\/fluffy_parents\/1\/fluffies\/1\/action\?_=\d+/, rawData
113
- expect(@callback.callCount).toEqual 1
114
-
115
147
  it "gets item with params", ->
116
148
  resource = Fluffy.find 1, params: {foo: 'bar'}, @callback
117
149
  checkAndRespond @server.requests[0], 'GET', /^\/fluffies\/1\?foo=bar&_=\d+/, rawData
@@ -127,7 +159,7 @@ describe "Joosy.Resources.REST", ->
127
159
  expect(resource).toBe cbResource
128
160
  checkAndRespond @server.requests[0], 'GET', /^\/fluffies\/1\?_=\d+/, rawData
129
161
 
130
- describe '@find(\'all\')', ->
162
+ describe "@find('all')", ->
131
163
  rawData = '{"page": 42, "fluffies": [{"id": 1, "name": "test1"}, {"id": 2, "name": "test2"}]}'
132
164
 
133
165
  beforeEach ->
@@ -147,11 +179,6 @@ describe "Joosy.Resources.REST", ->
147
179
  checkAndRespond @server.requests[0], 'GET', /^\/fluffies\/action\?_=\d+/, rawData
148
180
  expect(@callback.callCount).toEqual 1
149
181
 
150
- it "gets collection with from and parent", ->
151
- resource = Fluffy.find 'all', {parent: FluffyParent.build(1), from: 'action'}, @callback
152
- checkAndRespond @server.requests[0], 'GET', /^\/fluffy_parents\/1\/fluffies\/action\?_=\d+/, rawData
153
- expect(@callback.callCount).toEqual 1
154
-
155
182
  it "gets collection with params", ->
156
183
  resource = Fluffy.find 'all', params: {foo: 'bar'}, @callback
157
184
  checkAndRespond @server.requests[0], 'GET', /^\/fluffies\?foo=bar&_=\d+/, rawData