joosy 1.2.0.beta.1 → 1.2.0.beta.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,13 +20,13 @@ describe 'Joosy.Modules.Resources.Cacher', ->
20
20
 
21
21
  it 'caches', ->
22
22
  @Cacher.cached (instance) =>
23
- expect(instance()).toEqual 1
23
+ expect(instance.get()).toEqual 1
24
24
 
25
25
  expect(localStorage['scalar']).toEqual '[1]'
26
26
  expect(@spy.callCount).toEqual 1
27
27
 
28
28
  instance.refresh (instance) =>
29
- expect(instance()).toEqual 1
29
+ expect(instance.get()).toEqual 1
30
30
  expect(@spy.callCount).toEqual 2
31
31
 
32
32
  describe 'Array', ->
@@ -0,0 +1,32 @@
1
+ describe 'Joosy.Modules.Resources.Function', ->
2
+
3
+ it 'works', ->
4
+ class Generic extends Joosy.Module
5
+ @extend Joosy.Modules.Resources.Function
6
+
7
+ constructor: (@bar) ->
8
+ @foo = 'bar'
9
+
10
+ __call: -> '123'
11
+
12
+ generic = Generic.build 'foo'
13
+
14
+ expect(typeof generic).toEqual 'function'
15
+ expect(generic.foo).toEqual 'bar'
16
+ expect(generic.bar).toEqual 'foo'
17
+ expect(generic()).toEqual '123'
18
+
19
+ describe 'Hash', ->
20
+ it 'works', ->
21
+ class Hash extends Joosy.Resources.Hash
22
+ @extend Joosy.Modules.Resources.Function
23
+
24
+ constructor: (data) ->
25
+ data.bar = 'foo'
26
+ super data
27
+
28
+ hash = Hash.build {foo: 'bar'}
29
+
30
+ expect(typeof hash).toEqual 'function'
31
+ expect(hash 'foo').toEqual 'bar'
32
+ expect(hash 'bar').toEqual 'foo'
@@ -34,9 +34,9 @@ describe "Joosy.Modules.Resources.IdentityMap", ->
34
34
  id: 1
35
35
  test_inlines: [{id: 1}, {id: 2}]
36
36
 
37
- inline('foo', 'bar')
37
+ inline.set('foo', 'bar')
38
38
 
39
- expect(root('test_inlines')[0]('foo')).toEqual 'bar'
39
+ expect(root.get('test_inlines')[0].get('foo')).toEqual 'bar'
40
40
 
41
41
  it "handles nested bi-directional reference", ->
42
42
  biDirectionTestNode = TestNode.build
@@ -44,4 +44,4 @@ describe "Joosy.Modules.Resources.IdentityMap", ->
44
44
  yolo: true
45
45
  children: [{id: 2, parent: {id: 1, yolo: true}}]
46
46
 
47
- expect(biDirectionTestNode).toEqual(biDirectionTestNode('children')[0]('parent'))
47
+ expect(biDirectionTestNode).toEqual(biDirectionTestNode.get('children')[0].get('parent'))
@@ -4,7 +4,7 @@ describe "Joosy.Modules.Resources.Model", ->
4
4
  @include Joosy.Modules.Resources.Model
5
5
 
6
6
  beforeEach ->
7
- @resource = new Model @data =
7
+ @resource = Model.build @data =
8
8
  foo: 'bar'
9
9
  bar: 'baz'
10
10
  very:
@@ -15,35 +15,31 @@ describe "Joosy.Modules.Resources.Model", ->
15
15
  expect(Model::__primaryKey).toEqual 'id'
16
16
 
17
17
  it "remembers where it belongs", ->
18
- resource = new Model foo: 'bar'
18
+ resource = Model.build foo: 'bar'
19
19
  expect(resource.data).toEqual foo: 'bar'
20
20
 
21
- it "produces magic function", ->
22
- expect(typeof(@resource) == 'function').toBeTruthy()
23
- expect(@resource.data).toEqual @data
24
-
25
21
  it "gets values", ->
26
- expect(@resource 'foo').toEqual 'bar'
27
- expect(@resource 'very.deep').toEqual value: 'boo!'
28
- expect(@resource 'very.deep.value').toEqual 'boo!'
22
+ expect(@resource.get 'foo').toEqual 'bar'
23
+ expect(@resource.get 'very.deep').toEqual value: 'boo!'
24
+ expect(@resource.get 'very.deep.value').toEqual 'boo!'
29
25
 
30
26
  it "sets values", ->
31
- expect(@resource 'foo').toEqual 'bar'
32
- @resource 'foo', 'baz'
33
- expect(@resource 'foo').toEqual 'baz'
27
+ expect(@resource.get 'foo').toEqual 'bar'
28
+ @resource.set 'foo', 'baz'
29
+ expect(@resource.get 'foo').toEqual 'baz'
34
30
 
35
- expect(@resource 'very.deep').toEqual value: 'boo!'
36
- @resource 'very.deep', 'banana!'
37
- expect(@resource 'very.deep').toEqual 'banana!'
31
+ expect(@resource.get 'very.deep').toEqual value: 'boo!'
32
+ @resource.set 'very.deep', 'banana!'
33
+ expect(@resource.get 'very.deep').toEqual 'banana!'
38
34
 
39
- @resource 'another.deep.value', 'banana strikes back'
40
- expect(@resource 'another.deep').toEqual value: 'banana strikes back'
35
+ @resource.set 'another.deep.value', 'banana strikes back'
36
+ expect(@resource.get 'another.deep').toEqual value: 'banana strikes back'
41
37
 
42
38
  it "triggers 'changed' right", ->
43
39
  callback = sinon.spy()
44
40
  @resource.bind 'changed', callback
45
- @resource 'foo', 'baz'
46
- @resource 'foo', 'baz2'
41
+ @resource.set 'foo', 'baz'
42
+ @resource.set 'foo', 'baz2'
47
43
 
48
44
  expect(callback.callCount).toEqual(2)
49
45
 
@@ -54,9 +50,9 @@ describe "Joosy.Modules.Resources.Model", ->
54
50
  data.tested = true
55
51
  data
56
52
 
57
- resource = new R()
53
+ resource = R.build()
58
54
 
59
- expect(resource 'tested').toBeTruthy()
55
+ expect(resource.get 'tested').toBeTruthy()
60
56
 
61
57
  it "should map inlines", ->
62
58
  class RumbaMumba extends Model
@@ -68,18 +64,18 @@ describe "Joosy.Modules.Resources.Model", ->
68
64
  class S extends Model
69
65
  @map 'rumbaMumba', RumbaMumba
70
66
 
71
- resource = new R
67
+ resource = R.build
72
68
  rumbaMumbas: [
73
69
  {foo: 'bar'},
74
70
  {bar: 'baz'}
75
71
  ]
76
- expect(resource('rumbaMumbas') instanceof Joosy.Resources.Array).toBeTruthy()
77
- expect(resource('rumbaMumbas')[0]('foo')).toEqual 'bar'
72
+ expect(resource.get('rumbaMumbas') instanceof Joosy.Resources.Array).toBeTruthy()
73
+ expect(resource.get('rumbaMumbas')[0].get('foo')).toEqual 'bar'
78
74
 
79
- resource = new S
75
+ resource = S.build
80
76
  rumbaMumba: {foo: 'bar'}
81
- expect(resource('rumbaMumba') instanceof Model).toBeTruthy()
82
- expect(resource('rumbaMumba.foo')).toEqual 'bar'
77
+ expect(resource.get('rumbaMumba') instanceof Model).toBeTruthy()
78
+ expect(resource.get('rumbaMumba.foo')).toEqual 'bar'
83
79
 
84
80
  it "allows to override a collection", ->
85
81
  class Array extends Joosy.Resources.Array
@@ -91,9 +87,24 @@ describe "Joosy.Modules.Resources.Model", ->
91
87
  class R extends Model
92
88
  @map 'rumbaMumbas', RumbaMumba
93
89
 
94
- resource = new R
90
+ resource = R.build
95
91
  rumbaMumbas: [
96
92
  {foo: 'bar'},
97
93
  {bar: 'baz'}
98
94
  ]
99
- expect(resource('rumbaMumbas') instanceof Array).toBeTruthy()
95
+ expect(resource.get('rumbaMumbas') instanceof Array).toBeTruthy()
96
+
97
+ it "sets attributes", ->
98
+ class Fluffy extends Model
99
+ @attrAccessor 'foo', 'bar'
100
+
101
+ fluffy = Fluffy.build foo: 'bar', bar: 'foo'
102
+
103
+ expect(fluffy.foo()).toEqual 'bar'
104
+ expect(fluffy.bar()).toEqual 'foo'
105
+
106
+ fluffy.foo 'bar1'
107
+ fluffy.bar 'foo1'
108
+
109
+ expect(fluffy.foo()).toEqual 'bar1'
110
+ expect(fluffy.bar()).toEqual 'foo1'
@@ -128,7 +128,7 @@ describe "Joosy.Resources.REST", ->
128
128
  @callback = sinon.spy (error, target, data) ->
129
129
  expect(target instanceof Fluffy).toEqual true
130
130
  expect(target.id()).toEqual 1
131
- expect(target 'name').toEqual 'test1'
131
+ expect(target.get 'name').toEqual 'test1'
132
132
  expect(data).toEqual $.parseJSON(rawData)
133
133
 
134
134
  it "gets item without params", ->
@@ -207,38 +207,38 @@ describe "Joosy.Resources.REST", ->
207
207
  resource = Fluffy.build id: 1
208
208
 
209
209
  it "with get", ->
210
- resource.get {action: 'foo', params: {foo: 'bar'}}, callback
210
+ resource.send 'get', {action: 'foo', params: {foo: 'bar'}}, callback
211
211
  checkAndRespond @server.requests[0], 'GET', /^\/fluffies\/1\/foo\?foo=bar&_=\d+/, rawData
212
212
 
213
213
  it "with post", ->
214
- resource.post callback
214
+ resource.send 'post', callback
215
215
  checkAndRespond @server.requests[0], 'POST', /^\/fluffies\/1/, rawData
216
216
 
217
217
  it "with put", ->
218
- resource.put callback
218
+ resource.send 'put', callback
219
219
  checkAndRespond @server.requests[0], 'PUT', /^\/fluffies\/1/, rawData
220
220
 
221
221
  it "with delete", ->
222
- resource.delete callback
222
+ resource.send 'delete', callback
223
223
  checkAndRespond @server.requests[0], 'DELETE', /^\/fluffies\/1/, rawData
224
224
 
225
225
  describe "collection", ->
226
226
  resource = Fluffy
227
227
 
228
228
  it "with get", ->
229
- resource.get {action: 'foo', params: {foo: 'bar'}}, callback
229
+ resource.send 'get', {action: 'foo', params: {foo: 'bar'}}, callback
230
230
  checkAndRespond @server.requests[0], 'GET', /^\/fluffies\/foo\?foo=bar&_=\d+/, rawData
231
231
 
232
232
  it "with post", ->
233
- resource.post callback
233
+ resource.send 'post', callback
234
234
  checkAndRespond @server.requests[0], 'POST', /^\/fluffies/, rawData
235
235
 
236
236
  it "with put", ->
237
- resource.put callback
237
+ resource.send 'put', callback
238
238
  checkAndRespond @server.requests[0], 'PUT', /^\/fluffies/, rawData
239
239
 
240
240
  it "with delete", ->
241
- resource.delete callback
241
+ resource.send 'delete', callback
242
242
  checkAndRespond @server.requests[0], 'DELETE', /^\/fluffies/, rawData
243
243
 
244
244
  describe "save", ->
@@ -2,26 +2,21 @@ describe "Joosy.Resources.Scalar", ->
2
2
 
3
3
  describe 'in general', ->
4
4
  beforeEach ->
5
- @scalar = new Joosy.Resources.Scalar(5)
5
+ @scalar = Joosy.Resources.Scalar.build(5)
6
6
 
7
7
  it 'wraps', ->
8
8
  expect(@scalar+1).toEqual(6)
9
9
  expect("#{@scalar}").toEqual('5')
10
10
 
11
- it 'clones', ->
12
- clone = @scalar.clone()
13
- clone(1)
14
- expect(@scalar()).toEqual(5)
15
-
16
11
  it 'triggers', ->
17
12
  spy = sinon.spy()
18
13
  @scalar.bind 'changed', spy
19
14
 
20
- @scalar(7)
21
- expect(@scalar()).toEqual 7
15
+ @scalar.set(7)
16
+ expect(@scalar.get()).toEqual 7
22
17
 
23
18
  @scalar.load(8)
24
- expect(@scalar()).toEqual 8
19
+ expect(@scalar.get()).toEqual 8
25
20
 
26
21
  expect(spy.callCount).toEqual 2
27
22
 
@@ -31,11 +26,11 @@ describe "Joosy.Resources.Scalar", ->
31
26
  @beforeLoad (data) ->
32
27
  data + 1
33
28
 
34
- scalar = new Scalar(5)
35
- expect(scalar()).toEqual 6
29
+ scalar = Scalar.build(5)
30
+ expect(scalar.get()).toEqual 6
36
31
 
37
- scalar(5)
38
- expect(scalar()).toEqual 5
32
+ scalar.set(5)
33
+ expect(scalar.get()).toEqual 5
39
34
 
40
35
  scalar.load(7)
41
- expect(scalar()).toEqual 8
36
+ expect(scalar.get()).toEqual 8
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: joosy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0.beta.1
4
+ version: 1.2.0.beta.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Boris Staal
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-09-07 00:00:00.000000000 Z
13
+ date: 2013-09-10 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: sprockets
@@ -79,6 +79,7 @@ files:
79
79
  - source/joosy/modules/renderer.coffee
80
80
  - source/joosy/modules/resources.coffee
81
81
  - source/joosy/modules/resources/cacher.coffee
82
+ - source/joosy/modules/resources/function.coffee
82
83
  - source/joosy/modules/resources/identity_map.coffee
83
84
  - source/joosy/modules/resources/model.coffee
84
85
  - source/joosy/modules/time_manager.coffee
@@ -121,6 +122,7 @@ files:
121
122
  - spec/joosy/resources/array_spec.coffee
122
123
  - spec/joosy/resources/hash_spec.coffee
123
124
  - spec/joosy/resources/modules/cacher_spec.coffee
125
+ - spec/joosy/resources/modules/function_spec.coffee
124
126
  - spec/joosy/resources/modules/identity_map_spec.coffee
125
127
  - spec/joosy/resources/modules/model_spec.coffee
126
128
  - spec/joosy/resources/rest_spec.coffee
@@ -171,9 +173,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
173
  version: 1.3.1
172
174
  requirements: []
173
175
  rubyforge_project:
174
- rubygems_version: 2.0.6
176
+ rubygems_version: 2.0.3
175
177
  signing_key:
176
178
  specification_version: 4
177
179
  summary: Joosy Framework
178
180
  test_files: []
179
- has_rdoc: