ende 0.2.9 → 0.2.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (143) hide show
  1. checksums.yaml +4 -4
  2. data/lib/assets/javascripts/aura/extensions/devise.js.coffee +2 -2
  3. data/lib/assets/javascripts/widgets/viewer/main.js.coffee +1 -1
  4. data/lib/ende/version.rb +1 -1
  5. data/vendor/assets/components/build.js +638 -133
  6. data/vendor/components/indefinido-indemma/.gitignore +14 -0
  7. data/vendor/components/indefinido-indemma/.gitignore~ +2 -0
  8. data/vendor/components/indefinido-indemma/.ruby-gemset +1 -0
  9. data/vendor/components/indefinido-indemma/.ruby-version +1 -0
  10. data/vendor/components/indefinido-indemma/Gemfile +13 -0
  11. data/vendor/components/indefinido-indemma/Guardfile +39 -0
  12. data/vendor/components/indefinido-indemma/History.md +0 -0
  13. data/vendor/components/indefinido-indemma/Readme.md +447 -0
  14. data/vendor/components/indefinido-indemma/build/development.js +340 -0
  15. data/vendor/components/indefinido-indemma/build/release.js +22039 -0
  16. data/vendor/components/indefinido-indemma/build/test.js +22039 -0
  17. data/vendor/components/indefinido-indemma/component.json +7 -3
  18. data/vendor/components/indefinido-indemma/components/chaijs-assertion-error/component.json +18 -0
  19. data/vendor/components/indefinido-indemma/components/chaijs-assertion-error/index.js +110 -0
  20. data/vendor/components/indefinido-indemma/components/chaijs-chai/component.json +47 -0
  21. data/vendor/components/indefinido-indemma/components/chaijs-chai/index.js +1 -0
  22. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/assertion.js +130 -0
  23. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/core/assertions.js +1270 -0
  24. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/interface/assert.js +1080 -0
  25. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/interface/expect.js +12 -0
  26. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/interface/should.js +76 -0
  27. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/addChainableMethod.js +94 -0
  28. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/addMethod.js +37 -0
  29. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/addProperty.js +40 -0
  30. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/eql.js +129 -0
  31. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/flag.js +32 -0
  32. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/getActual.js +19 -0
  33. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/getEnumerableProperties.js +25 -0
  34. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/getMessage.js +49 -0
  35. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/getName.js +20 -0
  36. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/getPathValue.js +102 -0
  37. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/getProperties.js +35 -0
  38. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/index.js +108 -0
  39. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/inspect.js +320 -0
  40. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/objDisplay.js +48 -0
  41. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/overwriteMethod.js +51 -0
  42. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/overwriteProperty.js +54 -0
  43. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/test.js +26 -0
  44. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/transferFlags.js +44 -0
  45. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/type.js +45 -0
  46. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai.js +80 -0
  47. data/vendor/components/indefinido-indemma/components/component-bind/component.json +14 -0
  48. data/vendor/components/indefinido-indemma/components/component-bind/index.js +24 -0
  49. data/vendor/components/indefinido-indemma/components/component-jquery/component.json +14 -0
  50. data/vendor/components/indefinido-indemma/components/component-jquery/index.js +9601 -0
  51. data/vendor/components/indefinido-indemma/components/component-type/component.json +18 -0
  52. data/vendor/components/indefinido-indemma/components/component-type/index.js +32 -0
  53. data/vendor/components/indefinido-indemma/components/indefinido-advisable/component.json +21 -0
  54. data/vendor/components/indefinido-indemma/components/indefinido-advisable/index.js +1 -0
  55. data/vendor/components/indefinido-indemma/components/indefinido-advisable/lib/advisable.js +60 -0
  56. data/vendor/components/indefinido-indemma/components/indefinido-observable/component.json +25 -0
  57. data/vendor/components/indefinido-indemma/components/indefinido-observable/components/cjohansen-sinon/sinon.js +4290 -0
  58. data/vendor/components/indefinido-indemma/components/indefinido-observable/index.js +1 -0
  59. data/vendor/components/indefinido-indemma/components/indefinido-observable/lib/adapters/rivets.js +26 -0
  60. data/vendor/components/indefinido-indemma/components/indefinido-observable/lib/observable.js +323 -0
  61. data/vendor/components/indefinido-indemma/components/indefinido-observable/vendor/shims/accessors-legacy.js +92 -0
  62. data/vendor/components/indefinido-indemma/components/indefinido-observable/vendor/shims/accessors.js +173 -0
  63. data/vendor/components/indefinido-indemma/components/indefinido-observable/vendor/shims/array.indexOf.js +8 -0
  64. data/vendor/components/indefinido-indemma/components/indefinido-observable/vendor/shims/object.create.js +77 -0
  65. data/vendor/components/indefinido-indemma/components/kapit-observe-utils/component.json +13 -0
  66. data/vendor/components/indefinido-indemma/components/paulmillr-es6-shim/component.json +17 -0
  67. data/vendor/components/indefinido-indemma/components/paulmillr-es6-shim/es6-shim.js +996 -0
  68. data/vendor/components/indefinido-indemma/components/pluma-assimilate/component.json +25 -0
  69. data/vendor/components/indefinido-indemma/components/pluma-assimilate/dist/assimilate.js +127 -0
  70. data/vendor/components/indefinido-indemma/karma.conf.js +86 -0
  71. data/vendor/components/indefinido-indemma/lib/record/associable.js +229 -82
  72. data/vendor/components/indefinido-indemma/lib/record/errors.js +1 -0
  73. data/vendor/components/indefinido-indemma/lib/record/persistable.js +32 -0
  74. data/vendor/components/indefinido-indemma/lib/record/queryable.js +32 -0
  75. data/vendor/components/indefinido-indemma/lib/record/resource.js +12 -4
  76. data/vendor/components/indefinido-indemma/lib/record/rest.js +1 -1
  77. data/vendor/components/indefinido-indemma/lib/record/restfulable.js +38 -27
  78. data/vendor/components/indefinido-indemma/lib/record/scopable.js +15 -2
  79. data/vendor/components/indefinido-indemma/lib/record/storable.js +48 -0
  80. data/vendor/components/indefinido-indemma/lib/record/validatable.js +10 -5
  81. data/vendor/components/indefinido-indemma/lib/record/validations/cpf.js +1 -1
  82. data/vendor/components/indefinido-indemma/lib/record.js +15 -12
  83. data/vendor/components/indefinido-indemma/spec/record/associable_spec.js +137 -0
  84. data/vendor/components/indefinido-indemma/spec/record/persistable_spec.js +36 -0
  85. data/vendor/components/indefinido-indemma/spec/record/queryable_spec.js +33 -0
  86. data/vendor/components/indefinido-indemma/spec/record/resource_spec.js +93 -0
  87. data/vendor/components/indefinido-indemma/spec/record/rest_spec.js +32 -0
  88. data/vendor/components/indefinido-indemma/spec/record/restfulable_spec.js +288 -0
  89. data/vendor/components/indefinido-indemma/spec/record/scopable_spec.js +212 -0
  90. data/vendor/components/indefinido-indemma/spec/record/storable_spec.js +53 -0
  91. data/vendor/components/indefinido-indemma/spec/record/translationable.js +28 -0
  92. data/vendor/components/indefinido-indemma/spec/record/validatable_spec.js +111 -0
  93. data/vendor/components/indefinido-indemma/spec/record/validations/associated_spec.js +43 -0
  94. data/vendor/components/indefinido-indemma/spec/record/validations/confirmation_spec.js +36 -0
  95. data/vendor/components/indefinido-indemma/spec/record/validations/cpf_spec.js +35 -0
  96. data/vendor/components/indefinido-indemma/spec/record/validations/presence_spec.js +28 -0
  97. data/vendor/components/indefinido-indemma/spec/record/validations/remote_spec.js +87 -0
  98. data/vendor/components/indefinido-indemma/spec/record/validations/type_spec.js +48 -0
  99. data/vendor/components/indefinido-indemma/spec/record_spec.js +37 -0
  100. data/vendor/components/indefinido-indemma/spec/spec_helper.js +11 -0
  101. data/vendor/components/indefinido-indemma/spec/support/value_objects/phone.js +45 -0
  102. data/vendor/components/indefinido-indemma/src/lib/extensions/rivets.coffee +17 -0
  103. data/vendor/components/indefinido-indemma/src/lib/record/associable.coffee +342 -0
  104. data/vendor/components/indefinido-indemma/src/lib/record/errors.coffee +20 -0
  105. data/vendor/components/indefinido-indemma/src/lib/record/maid.coffee +16 -0
  106. data/vendor/components/indefinido-indemma/src/lib/record/persistable.coffee +27 -0
  107. data/vendor/components/indefinido-indemma/src/lib/record/queryable.coffee +29 -0
  108. data/vendor/components/indefinido-indemma/src/lib/record/resource.coffee +106 -0
  109. data/vendor/components/indefinido-indemma/src/lib/record/rest.coffee +28 -0
  110. data/vendor/components/indefinido-indemma/src/lib/record/restfulable.coffee +348 -0
  111. data/vendor/components/indefinido-indemma/src/lib/record/scopable.coffee +275 -0
  112. data/vendor/components/indefinido-indemma/src/lib/record/storable.coffee +46 -0
  113. data/vendor/components/indefinido-indemma/src/lib/record/translationable.coffee +18 -0
  114. data/vendor/components/indefinido-indemma/src/lib/record/validatable.coffee +217 -0
  115. data/vendor/components/indefinido-indemma/src/lib/record/validations/associated.coffee +32 -0
  116. data/vendor/components/indefinido-indemma/src/lib/record/validations/confirmation.coffee +19 -0
  117. data/vendor/components/indefinido-indemma/src/lib/record/validations/cpf.coffee +58 -0
  118. data/vendor/components/indefinido-indemma/src/lib/record/validations/presence.coffee +19 -0
  119. data/vendor/components/indefinido-indemma/src/lib/record/validations/remote.coffee +65 -0
  120. data/vendor/components/indefinido-indemma/src/lib/record/validations/type.coffee +32 -0
  121. data/vendor/components/indefinido-indemma/src/lib/record.coffee +136 -0
  122. data/vendor/components/indefinido-indemma/src/spec/record/associable_spec.coffee +130 -0
  123. data/vendor/components/indefinido-indemma/src/spec/record/persistable_spec.coffee +30 -0
  124. data/vendor/components/indefinido-indemma/src/spec/record/queryable_spec.coffee +27 -0
  125. data/vendor/components/indefinido-indemma/src/spec/record/resource_spec.coffee +69 -0
  126. data/vendor/components/indefinido-indemma/src/spec/record/rest_spec.coffee +22 -0
  127. data/vendor/components/indefinido-indemma/src/spec/record/restfulable_spec.coffee +207 -0
  128. data/vendor/components/indefinido-indemma/src/spec/record/scopable_spec.coffee +191 -0
  129. data/vendor/components/indefinido-indemma/src/spec/record/storable_spec.coffee +40 -0
  130. data/vendor/components/indefinido-indemma/src/spec/record/translationable.coffee +19 -0
  131. data/vendor/components/indefinido-indemma/src/spec/record/validatable_spec.coffee +100 -0
  132. data/vendor/components/indefinido-indemma/src/spec/record/validations/associated_spec.coffee +35 -0
  133. data/vendor/components/indefinido-indemma/src/spec/record/validations/confirmation_spec.coffee +25 -0
  134. data/vendor/components/indefinido-indemma/src/spec/record/validations/cpf_spec.coffee +28 -0
  135. data/vendor/components/indefinido-indemma/src/spec/record/validations/presence_spec.coffee +24 -0
  136. data/vendor/components/indefinido-indemma/src/spec/record/validations/remote_spec.coffee +74 -0
  137. data/vendor/components/indefinido-indemma/src/spec/record/validations/type_spec.coffee +33 -0
  138. data/vendor/components/indefinido-indemma/src/spec/record_spec.coffee +23 -0
  139. data/vendor/components/indefinido-indemma/src/spec/spec_helper.coffee +9 -0
  140. data/vendor/components/indefinido-indemma/src/spec/support/value_objects/phone.coffee +30 -0
  141. data/vendor/components/indefinido-indemma/vendor/object/mixin.js +196 -0
  142. data/vendor/components/indefinido-indemma/vendor/owl/pluralize.js +190 -0
  143. metadata +130 -2
@@ -0,0 +1,130 @@
1
+ root = exports ? window
2
+
3
+ require 'indemma/lib/record/associable'
4
+
5
+ describe 'record', ->
6
+ record = root.record
7
+
8
+ it 'should create a record'
9
+
10
+ describe 'model', ->
11
+ model = root.model
12
+ arthur = radio = null
13
+ person = corporation = null
14
+
15
+ beforeEach ->
16
+ corporation = model.call
17
+ resource: 'corporation'
18
+
19
+ # TODO implement support for self referential associations
20
+ friend = model.call
21
+ resource: 'friends'
22
+
23
+
24
+ person = model.call
25
+ resource : 'person'
26
+ has_many : 'friends'
27
+ belongs_to: 'corporation'
28
+
29
+ radio = corporation
30
+ _id: 1
31
+ name: 'Local Radio'
32
+
33
+ ford = friend
34
+ _id: 2
35
+ name: 'Ford Perfect'
36
+
37
+ arthur = person
38
+ _id: 3
39
+ name: 'Arthur Philip Dent'
40
+
41
+ describe 'has_one', ->
42
+ it 'should add a has_one property with the associations descriptions', ->
43
+ $.type(person.has_one).should.be.eq 'array'
44
+
45
+
46
+ describe 'belongs_to', ->
47
+ it 'should add a belongs_to property with the associations descriptions', ->
48
+ $.type(person.belongs_to).should.be.eq 'array'
49
+
50
+
51
+ describe "#associated_id", ->
52
+ it 'should return an partial resource when acessing associated', ->
53
+ arthur.corporation_id = radio._id
54
+
55
+ arthur.should.have.property 'corporation'
56
+ arthur.corporation.should.be.object
57
+ arthur.corporation.should.have.property 'resource'
58
+ arthur.corporation.should.have.property '_id', radio._id
59
+
60
+ xit 'should fetch the resource when accessing associated and resource not present', (done) ->
61
+ radio = corporation
62
+ _id: 1
63
+ name: 'Local Radio'
64
+
65
+ arthur.corporation_id = radio._id
66
+
67
+ arthur.corporation.should.be.object
68
+ arthur.corporation.should.have.property 'resource', radio.resource
69
+ arthur.corporation._id.should.be null
70
+ arthur.corporation.locking.should.be.object
71
+
72
+ arthur.corporation.locking.done (corporation) ->
73
+ corporation.should.have.property '_id' , radio.id
74
+ corporation.should.have.property 'name', radio.name
75
+
76
+
77
+ describe "#associated", ->
78
+
79
+ it 'should update associated id and record when associated record changes', ->
80
+ radio = corporation
81
+ _id: 1
82
+ name: 'Local Radio'
83
+ sustained: true
84
+
85
+ expect(arthur.corporation).to.be.undefined
86
+
87
+ arthur.corporation = radio
88
+
89
+ arthur.should.to.have.property 'corporation', radio
90
+ arthur.should.to.have.property 'corporation_id', radio._id
91
+
92
+
93
+ describe "#build_associated", ->
94
+ it 'should add builded object to association named attribute', ->
95
+ arthur = person
96
+ name: 'Arthur Dent'
97
+
98
+ corporation = arthur.build_corporation()
99
+ arthur.should.have.property 'corporation'
100
+ expect(corporation).to.be.ok
101
+
102
+ describe 'has_many', ->
103
+ it 'should add a has_many property with the associations descriptions', ->
104
+ $.type(person.has_many).should.be.eq 'array'
105
+
106
+ it 'should return a record factory with associations stored', ->
107
+ person.has_many.should.be.array
108
+
109
+ has_many = Array.prototype.splice.call person.has_many, 0
110
+
111
+ has_many.should.contain 'friends'
112
+
113
+ describe '#()', ->
114
+
115
+ it 'should return a record with an association object', ->
116
+ person().should.have.property 'friends'
117
+
118
+ describe '{generated_association}', ->
119
+ association = null
120
+
121
+ beforeEach -> association = person().friends
122
+
123
+ it 'should have query methods', ->
124
+ association.should.have.property 'all'
125
+ association.should.have.property 'each'
126
+ association.should.have.property 'reload'
127
+
128
+ describe '#all', ->
129
+
130
+ it 'should auto observe nested associations attributes'
@@ -0,0 +1,30 @@
1
+ root = exports ? window
2
+
3
+ persistable = require 'indemma/lib/record/persistable'
4
+
5
+ describe 'persistable', ->
6
+
7
+ describe 'model', ->
8
+ it 'should set the persistable key', ->
9
+ model.should.have.property 'persistable', true
10
+
11
+ describe '#find', ->
12
+ beforeEach ->
13
+ @person = model.call
14
+ resource : 'person'
15
+ has_many : 'friends'
16
+ belongs_to: 'corporation'
17
+
18
+ @arthur = @person
19
+ _id: '1'
20
+ name: 'Arthur Philip Dent'
21
+
22
+ it 'should call try to store a record after saving', (done) ->
23
+ sinon.stub(@person.storage, 'store').returns true
24
+
25
+ @arthur.save =>
26
+ expect(@person.storage.store.calledOnce).to.be.true
27
+ done()
28
+
29
+ @person.storage.store.restore()
30
+
@@ -0,0 +1,27 @@
1
+ root = exports ? window
2
+
3
+ queryable = require 'indemma/lib/record/queryable'
4
+
5
+ describe 'queryable', ->
6
+
7
+ describe 'model', ->
8
+ beforeEach ->
9
+ @person = model.call
10
+ resource : 'person'
11
+
12
+ it 'should set the queryable key', ->
13
+ model.should.have.property 'queryable', true
14
+
15
+ it 'should create a storage', ->
16
+ @person.should.have.property 'storage'
17
+
18
+ describe '#find', ->
19
+ beforeEach ->
20
+ @arthur = @person
21
+ _id: '1'
22
+ name: 'Arthur Philip Dent'
23
+
24
+ @arthur.save()
25
+
26
+ it 'should retrieve a record by key', ->
27
+ @person.find('1').should.have.property 'name', @arthur.name
@@ -0,0 +1,69 @@
1
+ require 'indemma/lib/record/restfulable'
2
+ require 'indemma/lib/record/resource'
3
+
4
+ root = exports ? window
5
+
6
+ model = root.model # TODO model = require 'indemma/model'
7
+ record = root.record # TODO model = require 'indemma/record'
8
+ jQuery = require 'component-jquery'
9
+
10
+ describe 'resource', ->
11
+
12
+ describe 'with scope option', ->
13
+ person = towel = null
14
+
15
+ beforeEach ->
16
+ person = model.call
17
+ resource: 'person'
18
+
19
+ towel = model.call
20
+ resource:
21
+ name: 'towel'
22
+ scope: 'users'
23
+
24
+
25
+ it 'should be prefixed with scope', ->
26
+ towel. route.should.be.eq '/users/towels'
27
+ towel( { } ).route.should.be.eq '/users/towels'
28
+ towel(id: 1).route.should.be.eq '/users/towels'
29
+
30
+
31
+ describe 'with singular resource', ->
32
+ towel = null
33
+
34
+ beforeEach ->
35
+ towel = model.call
36
+ resource:
37
+ name: 'towel'
38
+ singular: true
39
+
40
+ deferred = jQuery.Deferred()
41
+
42
+ context = towel(name: 'Arthur Philip Dent')
43
+ context.lock = JSON.stringify context.json()
44
+ deferred.resolveWith context, [_id: 1, name: 'Arthur Philip Dent']
45
+
46
+ sinon.stub(jQuery, "ajax").returns(deferred)
47
+
48
+ promises = towel.create {name: 'Arthur Philip Dent'}, {name: 'Ford'}
49
+
50
+ afterEach -> jQuery.ajax.restore()
51
+
52
+ it 'the route should be in singular form', ->
53
+ towel. route.should.be.eq '/towel'
54
+ towel( { } ).route.should.be.eq '/towel'
55
+ towel(id: 1).route.should.be.eq '/towel'
56
+
57
+
58
+ describe 'when included', ->
59
+ xit 'sets the resource loaded flag on model', ->
60
+ # model.resource.should.be.true
61
+
62
+ describe 'model' , ->
63
+ it 'add methods to model object'
64
+
65
+ describe '#pluralize', ->
66
+ xit 'transforms word into plural form'
67
+
68
+ describe '#singularize', ->
69
+ xit 'transforms word into singular form'
@@ -0,0 +1,22 @@
1
+ require 'indemma/lib/record/resource'
2
+
3
+ root = exports ? window
4
+
5
+ rest = require 'indemma/lib/record/rest'
6
+ jQuery = require 'component-jquery'
7
+
8
+ describe 'rest', ->
9
+ object = null
10
+
11
+ beforeEach ->
12
+ object = Object.create rest
13
+ object.route = "users"
14
+ object.resource = "user"
15
+
16
+ beforeEach -> sinon.stub(jQuery, "ajax").returns(jQuery.Deferred())
17
+ afterEach -> jQuery.ajax.restore()
18
+
19
+ describe '#delete', ->
20
+ it 'should make ajax call', ->
21
+ object.delete()
22
+ jQuery.ajax.called.should.be.true
@@ -0,0 +1,207 @@
1
+ require 'indemma/lib/record/restfulable'
2
+ require 'indemma/lib/record/validatable'
3
+ require 'indemma/lib/record/resource'
4
+
5
+ 'use strict'
6
+
7
+ root = exports ? window
8
+
9
+ model = root.model # TODO model = require 'indemma/model'
10
+ record = root.record # TODO model = require 'indemma/record'
11
+ jQuery = require 'component-jquery'
12
+
13
+
14
+ # Move to shared behaviour!
15
+ should_behave_like_errorsable = ->
16
+
17
+ describe '.errors', ->
18
+ describe 'when server responds', ->
19
+ beforeEach ->
20
+ @xhr =
21
+ status: 422
22
+
23
+ describe 'with errors', ->
24
+ it 'should add messages for each attribute on the errors object'
25
+ it 'should add messages for base attribute on the errors object', ->
26
+ base_messages = ["arthur you should bring a towel!"]
27
+ @xhr.responseText = JSON.stringify
28
+ errors:
29
+ base: base_messages
30
+
31
+ @subject.failed @xhr, 'error'
32
+ @subject.should.have.property 'errors'
33
+ @subject.errors[0].should.include 'base', 'server', server_message: base_messages[0]
34
+ @subject.errors.messages.should.have.property 'base', base_messages[0]
35
+
36
+ describe 'with invalid error messages', ->
37
+ it 'when inexistent attribute should throw exception', ->
38
+
39
+ describe 'restfulable', ->
40
+
41
+ describe 'when included', ->
42
+ it 'sets te restufulable loaded flag on model', ->
43
+ model.restfulable.should.be.true
44
+
45
+ # it 'adds save methods to records'
46
+
47
+ describe 'record', ->
48
+ # TODO Convert to @arthur
49
+ arthur = null
50
+
51
+ describe '()', ->
52
+
53
+ beforeEach ->
54
+ # TODO Convert to @arthur
55
+ @arthur = arthur = record.call
56
+ resource: 'person'
57
+ name : 'Arthur Philip Dent'
58
+
59
+ @arthur.dirty = true
60
+
61
+ describe '.save()', ->
62
+ beforeEach -> sinon.stub(jQuery, "ajax").returns(jQuery.Deferred())
63
+ afterEach -> jQuery.ajax.restore()
64
+
65
+ it 'should be able to serialize record', ->
66
+ JSON.stringify arthur.json()
67
+
68
+ it 'should ignore key in transient fields'
69
+
70
+ it 'should send paramenters accordingly'
71
+
72
+ # TODO erase this test and implement the above test (should
73
+ # send paramenters accordingly)
74
+ it 'should make ajax call', ->
75
+ arthur.save()
76
+ jQuery.ajax.called.should.be.true
77
+
78
+ describe 'model' , ->
79
+ describe '()', ->
80
+ describe '.json()', ->
81
+ friend = person = null
82
+
83
+ beforeEach ->
84
+ person = model.call
85
+ resource: 'person'
86
+ has_many: 'friends'
87
+ nested_attributes: ['friends']
88
+ name: String
89
+
90
+ friend = model.call
91
+ resource: 'friend'
92
+ belongs_to: 'person'
93
+
94
+ describe '.assign_attributes()', ->
95
+ friend = person = null
96
+
97
+ beforeEach ->
98
+ person = model.call
99
+ resource: 'person'
100
+ has_many: 'friends'
101
+ name: String
102
+
103
+ friend = model.call
104
+ resource: 'friend'
105
+ belongs_to: 'person'
106
+
107
+ # TODO implement setter on has many association and move this code to there
108
+ it 'assigns associations properly', ->
109
+ arthur = person name: 'Arthur Dent'
110
+ ford = friend name: 'Ford Perfect'
111
+ marvin = friend name: 'Marvin'
112
+ attributes = friends: [ford, marvin]
113
+
114
+ arthur.assign_attributes attributes
115
+
116
+ search_record = (association, search) ->
117
+ search = JSON.stringify search.json()
118
+ for associated in association
119
+ associated = JSON.stringify(associated.json())
120
+ return true if associated == search
121
+
122
+ false
123
+
124
+ search_record(arthur.friends, ford).should.be.eq.true
125
+ search_record(arthur.friends, arthur).should.be.eq.true
126
+
127
+
128
+ describe 'with singular resource', ->
129
+ describe '.create()', ->
130
+
131
+ it 'should return promises'
132
+ it 'should return models when promise is resolved'
133
+
134
+ describe 'with plural resource', ->
135
+
136
+ describe '.create()', ->
137
+ deferred = promise = person = null
138
+ should_behave_like_errorsable()
139
+
140
+ beforeEach ->
141
+ person = model.call resource: 'person'
142
+ deferred = jQuery.Deferred()
143
+
144
+ @subject = context = person(name: 'Arthur')
145
+ context.lock = JSON.stringify context.json()
146
+ deferred.resolveWith context, [_id: 1, name: 'Arthur']
147
+
148
+ deferred.resolveWith person(name: 'Arthur'), [_id: 1, name: 'Arthur']
149
+ sinon.stub(jQuery, "ajax").returns(deferred)
150
+ promise = person.create {name: 'Arthur'}, {name: 'Ford'}
151
+
152
+ afterEach -> jQuery.ajax.restore()
153
+
154
+ # TODO move this test to restful test
155
+ it 'should return a promise', (done) ->
156
+ promise.done.should.be.function
157
+ promise.state().should.be.eq 'resolved'
158
+ promise.done(-> done()).should.be.eq 'resolved'
159
+
160
+
161
+ it 'should return models when promise is resolved', (done) ->
162
+ # Will be called once for each saved record
163
+ created = ->
164
+ @name.should.be.eq 'Arthur'
165
+ done()
166
+
167
+ person.create {name: 'Arthur'}, {name: 'Ford'}, created
168
+
169
+ it 'should optionally accept create callback', (done) ->
170
+ promise = person.create {name: 'Arthur'}, {name: 'Ford'}
171
+ promise.done.should.be.function
172
+ promise.done -> done()
173
+ promise.state().should.be.eq 'resolved'
174
+
175
+
176
+ it 'should create record when only callback is passed', (done) ->
177
+ person.create -> done()
178
+ jQuery.ajax.callCount.should.be.eq 3 # 2 is counts is from the beforeEach
179
+
180
+ it 'should throw exception when nothing is passed', () ->
181
+ expect(person.create).to.throw TypeError
182
+
183
+ it 'should make ajax calls', ->
184
+ jQuery.ajax.callCount.should.be.eq 3
185
+
186
+
187
+ describe '.destroy()', ->
188
+ describe 'with plural resource', ->
189
+ arthur = person = deferred = null
190
+
191
+ beforeEach ->
192
+ person = model.call resource: 'person'
193
+ deferred = jQuery.Deferred()
194
+ deferred.resolveWith person(name: 'Arthur'), [id: 1]
195
+ sinon.stub(jQuery, "ajax").returns(deferred)
196
+ arthur = person name: 'Arthur', id: 1
197
+
198
+ afterEach -> jQuery.ajax.restore()
199
+
200
+ it "throw exception when record has no id", ->
201
+ delete arthur.id
202
+ expect(arthur.destroy).to.throw Error
203
+
204
+
205
+ it "should make ajax calls", ->
206
+ arthur.destroy()
207
+ jQuery.ajax.callCount.should.be.eq 1
@@ -0,0 +1,191 @@
1
+ require 'indemma/lib/record/resource'
2
+ require 'indemma/lib/record/restfulable'
3
+ require 'indemma/lib/record/scopable'
4
+
5
+ root = exports ? window
6
+
7
+ model = root.model # TODO model = require 'indemma/model'
8
+ record = root.record # TODO model = require 'indemma/record'
9
+
10
+ describe 'scopable', ->
11
+
12
+ describe 'when included', ->
13
+ it 'sets te scopable loaded flag on model', ->
14
+ model.scopable.should.be.true
15
+
16
+ # TODO check if it is better to create a queryable extension and
17
+ # move finder methods there
18
+ # it 'adds finder methods to records'
19
+
20
+ describe 'model', ->
21
+
22
+ describe '#(options)', ->
23
+ person = null
24
+
25
+ beforeEach ->
26
+
27
+ person = model.call
28
+ $hetero : true
29
+ $by_type: []
30
+ $by_name: String
31
+ resource: 'person'
32
+
33
+ it 'should add scope methods to model', ->
34
+ person.none.should.be.function
35
+
36
+ it 'should generate scope methods based on model definition', ->
37
+ person.hetero.should.be.function
38
+
39
+ describe '#none', ->
40
+ it 'should return empty response on fetch calls', (done) ->
41
+ # TODO implement getter for none property!
42
+ person.none().fetch null, (people) ->
43
+ people.length.should.be.empty
44
+ done()
45
+
46
+
47
+ describe 'scope', ->
48
+
49
+ describe '#(name, type)', ->
50
+
51
+ it 'should add scope methods to model', ->
52
+ person.scope 'bissexual', Boolean
53
+ person.bissexual.should.be.function
54
+
55
+ describe '#{generated_scope}', ->
56
+ deferred = null
57
+
58
+ beforeEach ->
59
+ deferred = jQuery.Deferred()
60
+ sinon.stub(jQuery, "ajax").returns deferred
61
+ person.scope.clear()
62
+
63
+ afterEach -> jQuery.ajax.restore()
64
+
65
+ describe '#all', ->
66
+ deferred = promises = person = null
67
+
68
+ it 'should return models when promise is resolved', (done) ->
69
+
70
+ # Will be called once for each saved record
71
+ fetched = (people) ->
72
+ people.should.be.array
73
+ people[0].name.should.be.string
74
+ done()
75
+
76
+ person.all fetched
77
+
78
+ deferred.resolveWith person, [[{name: 'Arthur'}, {name: 'Ford'}]]
79
+ jQuery.ajax.callCount.should.be.eq 1
80
+
81
+
82
+ describe 'when string', ->
83
+ it 'should acumulate data in scope object', ->
84
+ person.by_name()
85
+ person.scope.data.by_name.should.be.a 'string'
86
+
87
+ it 'should override data throught parameters', ->
88
+ person.by_name 'Ford'
89
+ person.scope.data.by_name.should.be.eq 'Ford'
90
+
91
+ describe 'when array', ->
92
+ it 'should acumulate data in scope object', ->
93
+ person.by_type()
94
+ person.scope.data.by_type.should.be.a 'array'
95
+
96
+ it 'should override data throught parameters', ->
97
+ person.by_type 1, 2, 3
98
+ person.scope.data.by_type.should.contain 1, 2, 3
99
+
100
+ it 'should use default value'
101
+ it 'should allow scope chaining'
102
+
103
+ describe 'xhr request', ->
104
+
105
+ it 'should build correct url', ->
106
+ person.by_type(1, 3, 4).fetch()
107
+
108
+ settings = jQuery.ajax.firstCall.args[0]
109
+
110
+ settings.should.have.property 'data'
111
+ settings.data.should.have.property 'by_type'
112
+ settings.data.by_type.should.include 1, 3, 4
113
+
114
+ it 'should make call', ->
115
+ person.by_type(1, 3, 4).fetch()
116
+ jQuery.ajax.callCount.should.be.eq 1
117
+
118
+
119
+ describe 'when boolean', ->
120
+
121
+ it 'should acumulate data in scope object', ->
122
+ person.hetero()
123
+ person.scope.data.hetero.should.be.eq true
124
+
125
+ it 'should override data throught parameters', ->
126
+ person.hetero false
127
+ person.scope.data.hetero.should.be.eq false
128
+
129
+ it 'should allow scope chaining'
130
+
131
+ it 'should make ajax call', ->
132
+ person.hetero().fetch()
133
+ jQuery.ajax.callCount.should.be.eq 1
134
+
135
+ describe '#{generated_association}', ->
136
+
137
+ describe 'of type belongs_to', ->
138
+ towel = null
139
+
140
+ beforeEach ->
141
+ person = model.call
142
+ $hetero: true
143
+ $by_type: []
144
+ resource: 'person'
145
+
146
+ towel = model.call
147
+ resource: 'towel'
148
+ material: 'cotton'
149
+ belongs_to: 'person'
150
+
151
+
152
+ describe '#{generated_scope}', ->
153
+
154
+ it 'can be called on association', ->
155
+ soft_towel = towel
156
+ material: 'silicon microfiber'
157
+
158
+ soft_towel.build_person()
159
+
160
+ expect(soft_towel.person).to.respondTo 'hetero'
161
+
162
+ describe 'of type has_many', ->
163
+ arthur = towel = null
164
+
165
+ beforeEach ->
166
+ person = model.call
167
+ $hetero: true
168
+ $by_type: []
169
+ resource: 'person'
170
+ has_many: 'towels'
171
+
172
+ towel = model.call
173
+ $by_material: []
174
+ resource: 'towel'
175
+ material: 'cotton'
176
+ belongs_to: 'person'
177
+
178
+ arthur = person
179
+ name: 'Arthur'
180
+
181
+
182
+
183
+ describe '#{generated_scope}', ->
184
+
185
+ it 'can be called on association', ->
186
+ expect(arthur.towels).to.respondTo 'by_material'
187
+
188
+ it 'should be serializable into paramenters', ->
189
+ arthur.towels.by_material 'cotton', 'microfiber'
190
+ query_string = decodeURIComponent(jQuery.param arthur.towels.scope.data)
191
+ query_string.should.be.eq 'by_material[]=cotton&by_material[]=microfiber'