joosy 1.2.0.alpha.73 → 1.2.0.beta.1
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.
- checksums.yaml +4 -4
- data/Gruntfile.coffee +56 -18
- data/bower.json +1 -1
- data/build/joosy/form.js +1 -0
- data/build/joosy/resources.js +1 -0
- data/build/joosy.js +2 -2774
- data/package.json +5 -4
- data/source/joosy/application.coffee +9 -7
- data/source/joosy/{extensions/resources-form/form.coffee → form.coffee} +58 -51
- data/source/joosy/helpers/form.coffee +241 -0
- data/source/joosy/helpers/index.coffee +3 -0
- data/source/joosy/helpers/routes.coffee +3 -1
- data/source/joosy/helpers/view.coffee +9 -9
- data/source/joosy/joosy.coffee +3 -5
- data/source/joosy/module.coffee +9 -4
- data/source/joosy/modules/dom.coffee +33 -31
- data/source/joosy/modules/events.coffee +24 -20
- data/source/joosy/modules/filters.coffee +38 -35
- data/source/joosy/modules/page/title.coffee +3 -3
- data/source/joosy/modules/renderer.coffee +23 -18
- data/source/joosy/modules/resources/identity_map.coffee +45 -0
- data/source/joosy/modules/resources/model.coffee +146 -0
- data/source/joosy/modules/widgets_manager.coffee +8 -8
- data/source/joosy/resources/array.coffee +0 -5
- data/source/joosy/resources/hash.coffee +8 -13
- data/source/joosy/resources/index.coffee +2 -0
- data/source/joosy/{extensions/resources → resources}/rest.coffee +48 -19
- data/source/joosy/resources/scalar.coffee +8 -10
- data/source/joosy/router.coffee +13 -12
- data/source/joosy/templaters/jst.coffee +3 -2
- data/source/joosy/widget.coffee +17 -15
- data/source/joosy.coffee +2 -0
- data/source/vendor/es5-shim.js +1316 -0
- data/source/vendor/inflections.js +598 -0
- data/source/vendor/metamorph.js +457 -0
- data/spec/helpers/matchers.coffee +4 -4
- data/spec/joosy/core/application_spec.coffee +1 -1
- data/spec/joosy/core/helpers/view_spec.coffee +2 -2
- data/spec/joosy/core/joosy_spec.coffee +8 -4
- data/spec/joosy/core/modules/dom_spec.coffee +7 -7
- data/spec/joosy/core/modules/events_spec.coffee +2 -2
- data/spec/joosy/core/modules/filters_spec.coffee +7 -8
- data/spec/joosy/core/modules/module_spec.coffee +5 -5
- data/spec/joosy/core/router_spec.coffee +3 -3
- data/spec/joosy/core/widget_spec.coffee +6 -6
- data/spec/joosy/environments/amd_spec.coffee +4 -2
- data/spec/joosy/environments/global_spec.coffee +1 -1
- data/spec/joosy/{extensions/form → form}/form_spec.coffee +9 -16
- data/spec/joosy/{extensions/form → form}/helpers/forms_spec.coffee +5 -5
- data/spec/joosy/{core/resources → resources}/array_spec.coffee +2 -2
- data/spec/joosy/{core/resources → resources}/hash_spec.coffee +0 -8
- data/spec/joosy/{core/modules/resources → resources/modules}/cacher_spec.coffee +0 -0
- data/spec/joosy/resources/modules/identity_map_spec.coffee +47 -0
- data/spec/joosy/{extensions/resources/base_spec.coffee → resources/modules/model_spec.coffee} +28 -48
- data/spec/joosy/{extensions/resources → resources}/rest_spec.coffee +29 -22
- data/spec/joosy/{core/resources → resources}/scalar_spec.coffee +8 -8
- data/templates/application/application.coffee.tt +0 -2
- data/templates/environment/app/haml/index.haml +2 -2
- data/templates/environment/package.json +1 -1
- metadata +23 -19
- data/build/joosy/extensions/resources-form.js +0 -590
- data/build/joosy/extensions/resources.js +0 -561
- data/source/joosy/extensions/resources/base.coffee +0 -282
- data/source/joosy/extensions/resources/index.coffee +0 -1
- data/source/joosy/extensions/resources-form/helpers/form.coffee +0 -104
- data/source/joosy/extensions/resources-form/index.coffee +0 -1
- data/source/metamorph.coffee +0 -410
@@ -89,9 +89,9 @@ describe "Joosy.Router", ->
|
|
89
89
|
Joosy.Router.compileRoute '/such/a/long/long/url/:with/:plenty/:of/:params', '123'
|
90
90
|
|
91
91
|
expect(Joosy.Router.routes['^/?such/a/long/long/url/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$']).toEqual
|
92
|
-
|
93
|
-
|
94
|
-
|
92
|
+
capture: ['with', 'plenty', 'of', 'params']
|
93
|
+
to: '123'
|
94
|
+
as: undefined
|
95
95
|
|
96
96
|
it 'compiles aliased route', ->
|
97
97
|
Joosy.Router.compileRoute '/such/a/long/long/url/:with/:plenty/:of/:params', '456', '123'
|
@@ -12,7 +12,7 @@ describe "Joosy.Widget", ->
|
|
12
12
|
|
13
13
|
for instance in entries
|
14
14
|
for filter in ['paint', 'beforePaint', 'erase', 'fetch']
|
15
|
-
spies[instance+'/'+filter] = sinon.spy()
|
15
|
+
spies[instance + '/' + filter] = sinon.spy()
|
16
16
|
|
17
17
|
class @A extends Joosy.Widget
|
18
18
|
@view """
|
@@ -55,8 +55,8 @@ describe "Joosy.Widget", ->
|
|
55
55
|
sinon.spy @[instance], '__load'
|
56
56
|
sinon.spy @[instance], '__unload'
|
57
57
|
|
58
|
-
@nestingMap =
|
59
|
-
'#content':
|
58
|
+
@nestingMap =
|
59
|
+
'#content':
|
60
60
|
instance: @b
|
61
61
|
nested:
|
62
62
|
'#subcontent': {instance: @d}
|
@@ -79,7 +79,7 @@ describe "Joosy.Widget", ->
|
|
79
79
|
|
80
80
|
@c.__bootstrap null, {}, $('#content', @$ground)
|
81
81
|
|
82
|
-
['paint', 'beforePaint']
|
82
|
+
for filter in ['paint', 'beforePaint']
|
83
83
|
expect(@spies["a/#{filter}"].callCount).toEqual 1
|
84
84
|
expect(@spies["b/#{filter}"].callCount).toEqual 0
|
85
85
|
expect(@spies["c/#{filter}"].callCount).toEqual 1
|
@@ -219,7 +219,7 @@ describe "Joosy.Widget", ->
|
|
219
219
|
class @F extends Joosy.Widget
|
220
220
|
@view "F"
|
221
221
|
|
222
|
-
['a', 'b', 'c', 'd', 'e', 'f']
|
222
|
+
for instance in ['a', 'b', 'c', 'd', 'e', 'f']
|
223
223
|
@[instance] = new @[instance.toUpperCase()] 'params'
|
224
224
|
|
225
225
|
@nestingMap =
|
@@ -333,7 +333,7 @@ describe "Joosy.Widget", ->
|
|
333
333
|
@A.fetch (complete) -> setTimeout complete, 100
|
334
334
|
|
335
335
|
@C.fetch (complete) -> setTimeout complete, 0
|
336
|
-
@C.independent()
|
336
|
+
@C.independent()
|
337
337
|
|
338
338
|
runs ->
|
339
339
|
@a.__bootstrap null, @nestingMap, @$ground
|
@@ -16,13 +16,14 @@ describe "Joosy", ->
|
|
16
16
|
runs ->
|
17
17
|
requirejs ['joosy/module'], (module) ->
|
18
18
|
result = true
|
19
|
-
expect(
|
19
|
+
expect(typeof(module.hasAncestor) == 'function').toBeTruthy()
|
20
20
|
|
21
21
|
waitsFor (-> result), 'Unable to download Joosy', 1000
|
22
22
|
|
23
23
|
it "registers internal components as modules", ->
|
24
|
-
expect(Object.keys(require.s.contexts._.registry).
|
24
|
+
expect(Object.keys(require.s.contexts._.registry).sort()).toEqual [
|
25
25
|
'joosy/application',
|
26
|
+
'joosy/form',
|
26
27
|
'joosy/layout',
|
27
28
|
'joosy/modules/dom',
|
28
29
|
'joosy/modules/events',
|
@@ -34,6 +35,7 @@ describe "Joosy", ->
|
|
34
35
|
'joosy/page',
|
35
36
|
'joosy/resources/array',
|
36
37
|
'joosy/resources/hash',
|
38
|
+
'joosy/resources/rest',
|
37
39
|
'joosy/resources/scalar',
|
38
40
|
'joosy/router',
|
39
41
|
'joosy/templaters/jst',
|
@@ -1,8 +1,6 @@
|
|
1
1
|
describe "Joosy.Form", ->
|
2
2
|
|
3
3
|
beforeEach ->
|
4
|
-
Joosy.Resources.Base?.resetIdentity()
|
5
|
-
|
6
4
|
@server = sinon.fakeServer.create()
|
7
5
|
@seedGround()
|
8
6
|
@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>"
|
@@ -78,8 +76,7 @@ describe "Joosy.Form", ->
|
|
78
76
|
|
79
77
|
it "should not stack _method inputs", ->
|
80
78
|
form = new Joosy.Form @putForm
|
81
|
-
|
82
|
-
form.fill @resource
|
79
|
+
form.fill @resource for i in [1..3]
|
83
80
|
marker = @putForm.find "input[name=_method]"
|
84
81
|
expect(marker.length).toEqual 1
|
85
82
|
expect(marker.attr 'value').toEqual 'PUT'
|
@@ -135,7 +132,7 @@ describe "Joosy.Form", ->
|
|
135
132
|
expect(@nudeForm.$fields()[1].value).toEqual 'bar'
|
136
133
|
expect(@nudeForm.$container.attr 'action').toEqual '/tests/1/calculate'
|
137
134
|
|
138
|
-
resource = @Test.build 'someId'
|
135
|
+
resource = @Test.build id: 'someId'
|
139
136
|
|
140
137
|
@nudeForm.fill resource,
|
141
138
|
action: resource.memberPath(action: 'calculate')
|
@@ -188,15 +185,13 @@ describe "Joosy.Form", ->
|
|
188
185
|
|
189
186
|
it 'should allow multiple submit', ->
|
190
187
|
@nudeForm = new Joosy.Form @nudeForm
|
191
|
-
|
192
|
-
@nudeForm.$container.submit()
|
188
|
+
@nudeForm.$container.submit() for i in [1..3]
|
193
189
|
expect(@requests.length).toEqual 3
|
194
190
|
|
195
191
|
it 'should optionally prevent multiple submit', ->
|
196
192
|
@nudeForm = new Joosy.Form @nudeForm, debounce: true
|
197
|
-
[200, 404, 500]
|
198
|
-
|
199
|
-
@nudeForm.$container.submit()
|
193
|
+
for code in [200, 404, 500]
|
194
|
+
@nudeForm.$container.submit() for i in [1..3]
|
200
195
|
expect(@requests.length).toEqual 1
|
201
196
|
@requests[0].respond(code, {}, '{}')
|
202
197
|
expect(@requests.length).toEqual 1
|
@@ -212,14 +207,12 @@ describe "Joosy.Form", ->
|
|
212
207
|
|
213
208
|
it 'should optionally allow multiple submit', ->
|
214
209
|
@nudeForm = new Joosy.Form @nudeForm, debounce: false
|
215
|
-
|
216
|
-
@nudeForm.$container.submit()
|
210
|
+
@nudeForm.$container.submit() for i in [1..3]
|
217
211
|
expect(@requests.length).toEqual 3
|
218
212
|
|
219
213
|
it 'should prevent multiple submit', ->
|
220
214
|
@nudeForm = new Joosy.Form @nudeForm
|
221
|
-
|
222
|
-
@nudeForm.$container.submit()
|
215
|
+
@nudeForm.$container.submit() for i in [1..3]
|
223
216
|
expect(@requests.length).toEqual 1
|
224
217
|
|
225
218
|
describe "Callbacks", ->
|
@@ -228,11 +221,11 @@ describe "Joosy.Form", ->
|
|
228
221
|
@nudeForm = new Joosy.Form @nudeForm, @spy=sinon.spy()
|
229
222
|
@nudeForm.fill @resource
|
230
223
|
@nudeForm.$container.submit()
|
231
|
-
@target = @server.requests.
|
224
|
+
@target = @server.requests[@server.requests.length-1]
|
232
225
|
|
233
226
|
it "should trigger 'success'", ->
|
234
227
|
expect(@target.method).toEqual 'POST'
|
235
|
-
expect(@target.url.
|
228
|
+
expect(@target.url.match /\/tests\/1$/).toBeTruthy()
|
236
229
|
@target.respond 200, 'Content-Type': 'application/json', '{"form": "works"}'
|
237
230
|
expect(@spy.callCount).toEqual 1
|
238
231
|
expect(@spy.args[0][0]).toEqual {form: 'works'}
|
@@ -1,12 +1,12 @@
|
|
1
1
|
describe "Joosy.Helpers.Form", ->
|
2
|
-
class Test extends Joosy.Resources.
|
2
|
+
class Test extends Joosy.Resources.REST
|
3
3
|
@entity 'test'
|
4
4
|
|
5
5
|
h = Joosy.Helpers.Application
|
6
|
-
resource = Test.build 1
|
6
|
+
resource = Test.build id: 1
|
7
7
|
|
8
8
|
describe "simple", ->
|
9
|
-
['text', 'file', 'hidden', 'password']
|
9
|
+
for type in ['text', 'file', 'hidden', 'password']
|
10
10
|
it "renders #{type}Field", ->
|
11
11
|
expect(h["#{type}Field"] 'a', 'b', {a: 'b'}).toBeTag 'input', '', id: 'a_b', name: 'a[b]', a: 'b', type: type
|
12
12
|
|
@@ -56,7 +56,7 @@ describe "Joosy.Helpers.Form", ->
|
|
56
56
|
h.formFor(resource, callback)
|
57
57
|
form = callback.args[0][0]
|
58
58
|
|
59
|
-
['text', 'file', 'hidden', 'password']
|
59
|
+
for type in ['text', 'file', 'hidden', 'password']
|
60
60
|
it "renders #{type}Field", ->
|
61
61
|
expect(form["#{type}Field"] 'b', {a: 'b'}).toBeTag 'input', '', id: 'test_b', name: 'test[b]', a: 'b', type: type
|
62
62
|
|
@@ -84,7 +84,7 @@ describe "Joosy.Helpers.Form", ->
|
|
84
84
|
h.formFor(resource, extendIds: true, callback)
|
85
85
|
form = callback.args[0][0]
|
86
86
|
|
87
|
-
['text', 'file', 'hidden', 'password']
|
87
|
+
for type in ['text', 'file', 'hidden', 'password']
|
88
88
|
it "renders #{type}Field", ->
|
89
89
|
expect(form["#{type}Field"] 'b', {a: 'b'}).toBeTag 'input', '', id: 'test_1_b', name: 'test[b]', a: 'b', type: type
|
90
90
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
describe
|
1
|
+
describe 'Joosy.Resources.Array', ->
|
2
2
|
|
3
3
|
describe 'in general', ->
|
4
4
|
beforeEach ->
|
@@ -18,7 +18,7 @@ describe "Joosy.Resources.Array", ->
|
|
18
18
|
expect(@array.length).toEqual 3
|
19
19
|
expect(@array[0]).toEqual 1
|
20
20
|
expect(@array[1]).toEqual 2
|
21
|
-
expect(@array[2]).toEqual 3
|
21
|
+
expect(@array[2]).toEqual 3
|
22
22
|
|
23
23
|
it 'triggers', ->
|
24
24
|
spy = sinon.spy()
|
@@ -10,14 +10,6 @@ describe "Joosy.Resources.Hash", ->
|
|
10
10
|
expect(@hash 'bar').toEqual {baz: 'yummy!'}
|
11
11
|
expect(@hash 'bar.baz').toEqual 'yummy!'
|
12
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
13
|
it 'sets', ->
|
22
14
|
@hash('bar.baz', 'the ignition')
|
23
15
|
expect(@hash.data.bar.baz).toEqual 'the ignition'
|
File without changes
|
@@ -0,0 +1,47 @@
|
|
1
|
+
describe "Joosy.Modules.Resources.IdentityMap", ->
|
2
|
+
|
3
|
+
class Model extends Joosy.Resources.Hash
|
4
|
+
@include Joosy.Modules.Resources.Model
|
5
|
+
@extend Joosy.Modules.Resources.IdentityMap
|
6
|
+
|
7
|
+
class TestInline extends Model
|
8
|
+
@entity 'test_inline'
|
9
|
+
|
10
|
+
class Test extends Model
|
11
|
+
@entity 'test'
|
12
|
+
@map 'test_inlines', TestInline
|
13
|
+
|
14
|
+
class TestNode extends Model
|
15
|
+
@entity 'test_node'
|
16
|
+
@map 'children', TestNode
|
17
|
+
@map 'parent', TestNode
|
18
|
+
|
19
|
+
beforeEach ->
|
20
|
+
Model.identityReset()
|
21
|
+
|
22
|
+
it "sets proper identity holder", ->
|
23
|
+
expect(Test.build().__identityHolder).toEqual Model
|
24
|
+
|
25
|
+
it "handles builds", ->
|
26
|
+
foo = Test.build id: 1
|
27
|
+
bar = Test.build id: 1
|
28
|
+
|
29
|
+
expect(foo).toEqual bar
|
30
|
+
|
31
|
+
it "handles maps", ->
|
32
|
+
inline = TestInline.build(id: 1)
|
33
|
+
root = Test.build
|
34
|
+
id: 1
|
35
|
+
test_inlines: [{id: 1}, {id: 2}]
|
36
|
+
|
37
|
+
inline('foo', 'bar')
|
38
|
+
|
39
|
+
expect(root('test_inlines')[0]('foo')).toEqual 'bar'
|
40
|
+
|
41
|
+
it "handles nested bi-directional reference", ->
|
42
|
+
biDirectionTestNode = TestNode.build
|
43
|
+
id: 1
|
44
|
+
yolo: true
|
45
|
+
children: [{id: 2, parent: {id: 1, yolo: true}}]
|
46
|
+
|
47
|
+
expect(biDirectionTestNode).toEqual(biDirectionTestNode('children')[0]('parent'))
|
data/spec/joosy/{extensions/resources/base_spec.coffee → resources/modules/model_spec.coffee}
RENAMED
@@ -1,22 +1,10 @@
|
|
1
|
-
describe "Joosy.Resources.
|
1
|
+
describe "Joosy.Modules.Resources.Model", ->
|
2
2
|
|
3
|
-
|
4
|
-
Joosy.Resources.
|
5
|
-
|
6
|
-
class TestInline extends Joosy.Resources.Base
|
7
|
-
@entity 'test_inline'
|
8
|
-
|
9
|
-
class Test extends Joosy.Resources.REST
|
10
|
-
@entity 'test'
|
11
|
-
@map 'test_inlines', TestInline
|
12
|
-
|
13
|
-
class TestNode extends Joosy.Resources.Base
|
14
|
-
@entity 'test_node'
|
15
|
-
@map 'children', TestNode
|
16
|
-
@map 'parent', TestNode
|
3
|
+
class Model extends Joosy.Resources.Hash
|
4
|
+
@include Joosy.Modules.Resources.Model
|
17
5
|
|
18
6
|
beforeEach ->
|
19
|
-
@resource =
|
7
|
+
@resource = new Model @data =
|
20
8
|
foo: 'bar'
|
21
9
|
bar: 'baz'
|
22
10
|
very:
|
@@ -24,14 +12,14 @@ describe "Joosy.Resources.Base", ->
|
|
24
12
|
value: 'boo!'
|
25
13
|
|
26
14
|
it "has primary key", ->
|
27
|
-
expect(
|
15
|
+
expect(Model::__primaryKey).toEqual 'id'
|
28
16
|
|
29
17
|
it "remembers where it belongs", ->
|
30
|
-
resource = new
|
18
|
+
resource = new Model foo: 'bar'
|
31
19
|
expect(resource.data).toEqual foo: 'bar'
|
32
20
|
|
33
21
|
it "produces magic function", ->
|
34
|
-
expect(
|
22
|
+
expect(typeof(@resource) == 'function').toBeTruthy()
|
35
23
|
expect(@resource.data).toEqual @data
|
36
24
|
|
37
25
|
it "gets values", ->
|
@@ -60,27 +48,27 @@ describe "Joosy.Resources.Base", ->
|
|
60
48
|
expect(callback.callCount).toEqual(2)
|
61
49
|
|
62
50
|
it "handles the before filter", ->
|
63
|
-
class R extends
|
51
|
+
class R extends Model
|
64
52
|
@beforeLoad (data) ->
|
65
53
|
data ||= {}
|
66
54
|
data.tested = true
|
67
55
|
data
|
68
56
|
|
69
|
-
resource = R
|
57
|
+
resource = new R()
|
70
58
|
|
71
59
|
expect(resource 'tested').toBeTruthy()
|
72
60
|
|
73
61
|
it "should map inlines", ->
|
74
|
-
class RumbaMumba extends
|
62
|
+
class RumbaMumba extends Model
|
75
63
|
@entity 'rumba_mumba'
|
76
64
|
|
77
|
-
class R extends
|
65
|
+
class R extends Model
|
78
66
|
@map 'rumbaMumbas', RumbaMumba
|
79
67
|
|
80
|
-
class S extends
|
68
|
+
class S extends Model
|
81
69
|
@map 'rumbaMumba', RumbaMumba
|
82
70
|
|
83
|
-
resource = R
|
71
|
+
resource = new R
|
84
72
|
rumbaMumbas: [
|
85
73
|
{foo: 'bar'},
|
86
74
|
{bar: 'baz'}
|
@@ -88,32 +76,24 @@ describe "Joosy.Resources.Base", ->
|
|
88
76
|
expect(resource('rumbaMumbas') instanceof Joosy.Resources.Array).toBeTruthy()
|
89
77
|
expect(resource('rumbaMumbas')[0]('foo')).toEqual 'bar'
|
90
78
|
|
91
|
-
resource = S
|
79
|
+
resource = new S
|
92
80
|
rumbaMumba: {foo: 'bar'}
|
93
|
-
expect(resource('rumbaMumba') instanceof
|
81
|
+
expect(resource('rumbaMumba') instanceof Model).toBeTruthy()
|
94
82
|
expect(resource('rumbaMumba.foo')).toEqual 'bar'
|
95
83
|
|
96
|
-
|
97
|
-
|
98
|
-
foo = Test.build 1
|
99
|
-
bar = Test.build 1
|
100
|
-
|
101
|
-
expect(foo).toEqual bar
|
102
|
-
|
103
|
-
it "handles maps", ->
|
104
|
-
inline = TestInline.build(1)
|
105
|
-
root = Test.build
|
106
|
-
id: 1
|
107
|
-
test_inlines: [{id: 1}, {id: 2}]
|
108
|
-
|
109
|
-
inline('foo', 'bar')
|
84
|
+
it "allows to override a collection", ->
|
85
|
+
class Array extends Joosy.Resources.Array
|
110
86
|
|
111
|
-
|
87
|
+
class RumbaMumba extends Model
|
88
|
+
@entity 'rumba_mumba'
|
89
|
+
@collection Array
|
112
90
|
|
113
|
-
|
114
|
-
|
115
|
-
id: 1
|
116
|
-
yolo: true
|
117
|
-
children: [{id: 2, parent: {id: 1, yolo: true}}]
|
91
|
+
class R extends Model
|
92
|
+
@map 'rumbaMumbas', RumbaMumba
|
118
93
|
|
119
|
-
|
94
|
+
resource = new R
|
95
|
+
rumbaMumbas: [
|
96
|
+
{foo: 'bar'},
|
97
|
+
{bar: 'baz'}
|
98
|
+
]
|
99
|
+
expect(resource('rumbaMumbas') instanceof Array).toBeTruthy()
|
@@ -1,8 +1,5 @@
|
|
1
1
|
describe "Joosy.Resources.REST", ->
|
2
2
|
|
3
|
-
beforeEach ->
|
4
|
-
Joosy.Resources.Base?.resetIdentity()
|
5
|
-
|
6
3
|
class FluffyInline extends Joosy.Resources.REST
|
7
4
|
@entity 'fluffy_inline'
|
8
5
|
|
@@ -50,18 +47,18 @@ describe "Joosy.Resources.REST", ->
|
|
50
47
|
|
51
48
|
it 'makes a class whose instances get new source too', ->
|
52
49
|
clone = @Test.at 'rumbas'
|
53
|
-
expect(clone.build(1).memberPath()).toEqual '/rumbas/tests/1'
|
50
|
+
expect(clone.build(id: 1).memberPath()).toEqual '/rumbas/tests/1'
|
54
51
|
|
55
52
|
it 'accepts another resource instance', ->
|
56
|
-
clone = @Test.at Fluffy.build(1)
|
53
|
+
clone = @Test.at Fluffy.build(id: 1)
|
57
54
|
expect(clone.collectionPath()).toEqual '/fluffies/1/tests'
|
58
55
|
|
59
56
|
it 'accepts array', ->
|
60
|
-
clone = @Test.at ['rumbas', Fluffy.build(1), 'salsas']
|
57
|
+
clone = @Test.at ['rumbas', Fluffy.build(id: 1), 'salsas']
|
61
58
|
expect(clone.collectionPath()).toEqual '/rumbas/fluffies/1/salsas/tests'
|
62
59
|
|
63
60
|
it 'accepts sequential attributes', ->
|
64
|
-
clone = @Test.at 'rumbas', 'salsas', Fluffy.build(1)
|
61
|
+
clone = @Test.at 'rumbas', 'salsas', Fluffy.build(id: 1)
|
65
62
|
expect(clone.collectionPath()).toEqual '/rumbas/salsas/fluffies/1/tests'
|
66
63
|
|
67
64
|
describe '::at', ->
|
@@ -70,25 +67,25 @@ describe "Joosy.Resources.REST", ->
|
|
70
67
|
@entity 'test'
|
71
68
|
|
72
69
|
it 'returns base class instance', ->
|
73
|
-
original = @Test.build id: 1, name: 'foobar'
|
70
|
+
original = @Test.build id: 1, name: 'foobar', 'thing': 'baseclass'
|
74
71
|
clone = original.at 'rumbas'
|
75
72
|
expect(clone instanceof @Test).toBeTruthy()
|
76
73
|
expect(clone.data).toEqual original.data
|
77
74
|
|
78
75
|
it 'accepts string', ->
|
79
|
-
clone = @Test.build(1).at('rumbas')
|
76
|
+
clone = @Test.build(id: 1).at('rumbas')
|
80
77
|
expect(clone.memberPath()).toEqual '/rumbas/tests/1'
|
81
78
|
|
82
79
|
it 'accepts another resource instance', ->
|
83
|
-
clone = @Test.build(1).at(Fluffy.build(1))
|
80
|
+
clone = @Test.build(id: 1).at(Fluffy.build(id: 1))
|
84
81
|
expect(clone.memberPath()).toEqual '/fluffies/1/tests/1'
|
85
82
|
|
86
83
|
it 'accepts array', ->
|
87
|
-
clone = @Test.build(1).at ['rumbas', Fluffy.build(1), 'salsas']
|
84
|
+
clone = @Test.build(id: 1).at ['rumbas', Fluffy.build(id: 1), 'salsas']
|
88
85
|
expect(clone.memberPath()).toEqual '/rumbas/fluffies/1/salsas/tests/1'
|
89
86
|
|
90
87
|
it 'accepts sequential attributes', ->
|
91
|
-
clone = @Test.build(1).at 'rumbas', 'salsas', Fluffy.build(1)
|
88
|
+
clone = @Test.build(id: 1).at 'rumbas', 'salsas', Fluffy.build(id: 1)
|
92
89
|
expect(clone.memberPath()).toEqual '/rumbas/salsas/fluffies/1/tests/1'
|
93
90
|
|
94
91
|
describe '@memberPath', ->
|
@@ -207,7 +204,7 @@ describe "Joosy.Resources.REST", ->
|
|
207
204
|
expect(data).toEqual {foo: 'bar'}
|
208
205
|
|
209
206
|
describe "member", ->
|
210
|
-
resource = Fluffy.build 1
|
207
|
+
resource = Fluffy.build id: 1
|
211
208
|
|
212
209
|
it "with get", ->
|
213
210
|
resource.get {action: 'foo', params: {foo: 'bar'}}, callback
|
@@ -244,15 +241,25 @@ describe "Joosy.Resources.REST", ->
|
|
244
241
|
resource.delete callback
|
245
242
|
checkAndRespond @server.requests[0], 'DELETE', /^\/fluffies/, rawData
|
246
243
|
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
244
|
+
describe "save", ->
|
245
|
+
beforeEach ->
|
246
|
+
class @Resource extends Joosy.Resources.REST
|
247
|
+
@entity 'resource'
|
248
|
+
|
249
|
+
@beforeSave (data) ->
|
250
|
+
data.tested = true
|
251
|
+
data
|
252
|
+
|
253
|
+
it "creates", ->
|
254
|
+
resource = new @Resource(foo: 'bar')
|
255
|
+
resource.save()
|
251
256
|
|
252
|
-
|
257
|
+
checkAndRespond @server.requests[0], 'POST', /^\/resources/, rawData
|
258
|
+
expect(@server.requests[0].requestBody).toEqual 'foo=bar&tested=true'
|
253
259
|
|
254
|
-
|
255
|
-
|
260
|
+
it "updates", ->
|
261
|
+
resource = new @Resource(id: 1, foo: 'bar')
|
262
|
+
resource.save()
|
256
263
|
|
257
|
-
|
258
|
-
|
264
|
+
checkAndRespond @server.requests[0], 'PUT', /^\/resources\/1/, rawData
|
265
|
+
expect(@server.requests[0].requestBody).toEqual 'id=1&foo=bar&tested=true'
|
@@ -10,18 +10,18 @@ describe "Joosy.Resources.Scalar", ->
|
|
10
10
|
|
11
11
|
it 'clones', ->
|
12
12
|
clone = @scalar.clone()
|
13
|
-
clone
|
13
|
+
clone(1)
|
14
14
|
expect(@scalar()).toEqual(5)
|
15
15
|
|
16
16
|
it 'triggers', ->
|
17
17
|
spy = sinon.spy()
|
18
18
|
@scalar.bind 'changed', spy
|
19
19
|
|
20
|
-
@scalar
|
21
|
-
expect(@scalar
|
20
|
+
@scalar(7)
|
21
|
+
expect(@scalar()).toEqual 7
|
22
22
|
|
23
23
|
@scalar.load(8)
|
24
|
-
expect(@scalar
|
24
|
+
expect(@scalar()).toEqual 8
|
25
25
|
|
26
26
|
expect(spy.callCount).toEqual 2
|
27
27
|
|
@@ -32,10 +32,10 @@ describe "Joosy.Resources.Scalar", ->
|
|
32
32
|
data + 1
|
33
33
|
|
34
34
|
scalar = new Scalar(5)
|
35
|
-
expect(scalar
|
35
|
+
expect(scalar()).toEqual 6
|
36
36
|
|
37
|
-
scalar
|
38
|
-
expect(scalar
|
37
|
+
scalar(5)
|
38
|
+
expect(scalar()).toEqual 5
|
39
39
|
|
40
40
|
scalar.load(7)
|
41
|
-
expect(scalar
|
41
|
+
expect(scalar()).toEqual 8
|
@@ -2,6 +2,6 @@
|
|
2
2
|
%html
|
3
3
|
%head
|
4
4
|
%title
|
5
|
-
%link{:href => "
|
6
|
-
%script{:src => "
|
5
|
+
%link{:href => "application.css", :media => "screen", :rel => "stylesheet", :type => "text/css"}
|
6
|
+
%script{:src => "application.js", :type => "text/javascript"}
|
7
7
|
%body
|