ende 0.5.20 → 0.5.21

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.
Files changed (203) hide show
  1. checksums.yaml +4 -4
  2. data/component.json +1 -1
  3. data/components/indefinido/indemma/master/.gitignore +17 -0
  4. data/components/indefinido/indemma/master/.ruby-gemset +1 -0
  5. data/components/indefinido/indemma/master/.ruby-version +1 -0
  6. data/components/indefinido/indemma/master/Gemfile +12 -0
  7. data/components/indefinido/indemma/master/Guardfile +39 -0
  8. data/components/indefinido/indemma/master/History.md +0 -0
  9. data/components/indefinido/indemma/master/Readme.md +445 -0
  10. data/components/indefinido/indemma/master/build/development.js +26123 -0
  11. data/components/indefinido/indemma/master/build/release.js +16741 -0
  12. data/components/indefinido/indemma/master/build/test.js +26123 -0
  13. data/components/indefinido/indemma/master/component.json +1 -1
  14. data/components/indefinido/indemma/master/components/chaijs/assertion-error/1.0.0/component.json +18 -0
  15. data/components/indefinido/indemma/master/components/chaijs/assertion-error/1.0.0/index.js +110 -0
  16. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/.gitignore +22 -0
  17. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/.mailmap +1 -0
  18. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/.npmignore +14 -0
  19. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/.travis.yml +14 -0
  20. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/CONTRIBUTING.md +173 -0
  21. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/History.md +895 -0
  22. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/Makefile +93 -0
  23. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/README.md +99 -0
  24. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/ReleaseNotes.md +482 -0
  25. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/bower.json +27 -0
  26. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/chai.js +4782 -0
  27. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/component.json +50 -0
  28. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/index.js +1 -0
  29. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/karma.conf.js +28 -0
  30. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/karma.sauce.js +41 -0
  31. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/lib/chai/assertion.js +130 -0
  32. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/lib/chai/config.js +50 -0
  33. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/lib/chai/core/assertions.js +1314 -0
  34. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/lib/chai/interface/assert.js +1056 -0
  35. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/lib/chai/interface/expect.js +12 -0
  36. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/lib/chai/interface/should.js +78 -0
  37. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/lib/chai/utils/addChainableMethod.js +111 -0
  38. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/lib/chai/utils/addMethod.js +43 -0
  39. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/lib/chai/utils/addProperty.js +40 -0
  40. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/lib/chai/utils/flag.js +32 -0
  41. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/lib/chai/utils/getActual.js +18 -0
  42. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/lib/chai/utils/getEnumerableProperties.js +25 -0
  43. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/lib/chai/utils/getMessage.js +49 -0
  44. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/lib/chai/utils/getName.js +20 -0
  45. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/lib/chai/utils/getPathValue.js +102 -0
  46. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/lib/chai/utils/getProperties.js +35 -0
  47. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/lib/chai/utils/index.js +114 -0
  48. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/lib/chai/utils/inspect.js +320 -0
  49. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/lib/chai/utils/objDisplay.js +49 -0
  50. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/lib/chai/utils/overwriteChainableMethod.js +53 -0
  51. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/lib/chai/utils/overwriteMethod.js +51 -0
  52. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/lib/chai/utils/overwriteProperty.js +54 -0
  53. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/lib/chai/utils/test.js +26 -0
  54. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/lib/chai/utils/transferFlags.js +44 -0
  55. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/lib/chai/utils/type.js +45 -0
  56. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/lib/chai.js +87 -0
  57. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/package.json +42 -0
  58. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/sauce.browsers.js +128 -0
  59. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/support/sauce/sauce_connect_block.sh +7 -0
  60. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/support/sauce/sauce_connect_setup.sh +53 -0
  61. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/test/assert.js +638 -0
  62. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/test/auth/.gitkeep +0 -0
  63. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/test/bootstrap/index.js +22 -0
  64. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/test/bootstrap/karma.js +22 -0
  65. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/test/configuration.js +133 -0
  66. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/test/display/errors.js +14 -0
  67. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/test/display/message.js +47 -0
  68. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/test/expect.js +814 -0
  69. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/test/globalShould.js +15 -0
  70. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/test/plugins.js +24 -0
  71. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/test/should.js +744 -0
  72. data/components/indefinido/indemma/master/components/chaijs/chai/1.9.1/test/utilities.js +309 -0
  73. data/components/indefinido/indemma/master/components/chaijs/deep-eql/0.1.3/component.json +20 -0
  74. data/components/indefinido/indemma/master/components/chaijs/deep-eql/0.1.3/lib/eql.js +257 -0
  75. data/components/indefinido/indemma/master/components/chaijs/type-detect/0.1.1/component.json +18 -0
  76. data/components/indefinido/indemma/master/components/chaijs/type-detect/0.1.1/lib/type.js +142 -0
  77. data/components/indefinido/indemma/master/components/component/bind/1.0.0/component.json +14 -0
  78. data/components/indefinido/indemma/master/components/component/bind/1.0.0/index.js +23 -0
  79. data/components/indefinido/indemma/master/components/component/jquery/1.0.0/component.json +10 -0
  80. data/components/indefinido/indemma/master/components/component/jquery/1.0.0/index.js +10308 -0
  81. data/components/indefinido/indemma/master/components/component/type/1.0.0/component.json +20 -0
  82. data/components/indefinido/indemma/master/components/component/type/1.0.0/index.js +32 -0
  83. data/components/indefinido/indemma/master/components/indefinido/advisable/master/component.json +21 -0
  84. data/components/indefinido/indemma/master/components/indefinido/advisable/master/index.js +1 -0
  85. data/components/indefinido/indemma/master/components/indefinido/advisable/master/lib/advisable.js +60 -0
  86. data/components/indefinido/indemma/master/components/indefinido/observable/es6-modules/component.json +39 -0
  87. data/components/indefinido/indemma/master/components/indefinido/observable/es6-modules/index.js +1 -0
  88. data/components/indefinido/indemma/master/components/indefinido/observable/es6-modules/lib/adapters/rivets.js +40 -0
  89. data/components/indefinido/indemma/master/components/indefinido/observable/es6-modules/lib/legacy/notifierable.js +145 -0
  90. data/components/indefinido/indemma/master/components/indefinido/observable/es6-modules/lib/legacy/schedulerable.js +147 -0
  91. data/components/indefinido/indemma/master/components/indefinido/observable/es6-modules/lib/lookup.js +38 -0
  92. data/components/indefinido/indemma/master/components/indefinido/observable/es6-modules/lib/observable/keypath_observer.js +38 -0
  93. data/components/indefinido/indemma/master/components/indefinido/observable/es6-modules/lib/observable/observation.js +45 -0
  94. data/components/indefinido/indemma/master/components/indefinido/observable/es6-modules/lib/observable/selection.js +57 -0
  95. data/components/indefinido/indemma/master/components/indefinido/observable/es6-modules/lib/observable/self_observer.js +38 -0
  96. data/components/indefinido/indemma/master/components/indefinido/observable/es6-modules/lib/observable.js +97 -0
  97. data/components/indefinido/indemma/master/components/indefinido/observable/es6-modules/lib/platform.js +12 -0
  98. data/components/indefinido/indemma/master/components/indefinido/observable/es6-modules/vendor/observe-js/observe.js +1631 -0
  99. data/components/indefinido/indemma/master/components/indefinido/observable/es6-modules/vendor/shims/accessors-legacy.js +92 -0
  100. data/components/indefinido/indemma/master/components/indefinido/observable/es6-modules/vendor/shims/accessors.js +248 -0
  101. data/components/indefinido/indemma/master/components/indefinido/observable/es6-modules/vendor/shims/array.indexOf.js +8 -0
  102. data/components/indefinido/indemma/master/components/indefinido/observable/es6-modules/vendor/shims/object.create.js +77 -0
  103. data/components/indefinido/indemma/master/components/pluma/assimilate/0.4.0/component.json +25 -0
  104. data/components/indefinido/indemma/master/components/pluma/assimilate/0.4.0/dist/assimilate.js +127 -0
  105. data/components/indefinido/indemma/master/karma.conf.js +75 -0
  106. data/components/indefinido/indemma/master/lib/record/associable.js +4 -2
  107. data/components/indefinido/indemma/master/lib/record/dirtyable.js +1 -1
  108. data/components/indefinido/indemma/master/package.json +9 -0
  109. data/components/indefinido/indemma/master/spec/record/associable_spec.js +211 -0
  110. data/components/indefinido/indemma/master/spec/record/dirtyable_spec.js +57 -0
  111. data/components/indefinido/indemma/master/spec/record/maid_spec.js +40 -0
  112. data/components/indefinido/indemma/master/spec/record/persistable_spec.js +46 -0
  113. data/components/indefinido/indemma/master/spec/record/queryable_spec.js +39 -0
  114. data/components/indefinido/indemma/master/spec/record/resource_spec.js +93 -0
  115. data/components/indefinido/indemma/master/spec/record/rest_spec.js +32 -0
  116. data/components/indefinido/indemma/master/spec/record/restfulable_spec.js +346 -0
  117. data/components/indefinido/indemma/master/spec/record/scopable_spec.js +242 -0
  118. data/components/indefinido/indemma/master/spec/record/storable_spec.js +44 -0
  119. data/components/indefinido/indemma/master/spec/record/translationable.js +28 -0
  120. data/components/indefinido/indemma/master/spec/record/validatable_spec.js +142 -0
  121. data/components/indefinido/indemma/master/spec/record/validations/associated_spec.js +43 -0
  122. data/components/indefinido/indemma/master/spec/record/validations/confirmation_spec.js +36 -0
  123. data/components/indefinido/indemma/master/spec/record/validations/cpf_spec.js +34 -0
  124. data/components/indefinido/indemma/master/spec/record/validations/presence_spec.js +28 -0
  125. data/components/indefinido/indemma/master/spec/record/validations/remote_spec.js +87 -0
  126. data/components/indefinido/indemma/master/spec/record/validations/type_spec.js +48 -0
  127. data/components/indefinido/indemma/master/spec/record_spec.js +49 -0
  128. data/components/indefinido/indemma/master/spec/spec_helper.js +15 -0
  129. data/components/indefinido/indemma/master/spec/support/value_objects/phone.js +45 -0
  130. data/components/indefinido/indemma/master/src/lib/extensions/rivets.coffee +17 -0
  131. data/components/indefinido/indemma/master/src/lib/record/associable.coffee +419 -0
  132. data/components/indefinido/indemma/master/src/lib/record/dirtyable.coffee +47 -0
  133. data/components/indefinido/indemma/master/src/lib/record/errors.coffee +20 -0
  134. data/components/indefinido/indemma/master/src/lib/record/maid.coffee +16 -0
  135. data/components/indefinido/indemma/master/src/lib/record/persistable.coffee +34 -0
  136. data/components/indefinido/indemma/master/src/lib/record/queryable.coffee +29 -0
  137. data/components/indefinido/indemma/master/src/lib/record/resource.coffee +107 -0
  138. data/components/indefinido/indemma/master/src/lib/record/rest.coffee +34 -0
  139. data/components/indefinido/indemma/master/src/lib/record/restfulable.coffee +487 -0
  140. data/components/indefinido/indemma/master/src/lib/record/scopable.coffee +279 -0
  141. data/components/indefinido/indemma/master/src/lib/record/storable.coffee +49 -0
  142. data/components/indefinido/indemma/master/src/lib/record/translationable.coffee +18 -0
  143. data/components/indefinido/indemma/master/src/lib/record/validatable.coffee +241 -0
  144. data/components/indefinido/indemma/master/src/lib/record/validations/associated.coffee +34 -0
  145. data/components/indefinido/indemma/master/src/lib/record/validations/confirmation.coffee +17 -0
  146. data/components/indefinido/indemma/master/src/lib/record/validations/cpf.coffee +57 -0
  147. data/components/indefinido/indemma/master/src/lib/record/validations/presence.coffee +16 -0
  148. data/components/indefinido/indemma/master/src/lib/record/validations/remote.coffee +61 -0
  149. data/components/indefinido/indemma/master/src/lib/record/validations/type.coffee +31 -0
  150. data/components/indefinido/indemma/master/src/lib/record/validations/validatorable.coffee +5 -0
  151. data/components/indefinido/indemma/master/src/lib/record.coffee +143 -0
  152. data/components/indefinido/indemma/master/src/spec/record/associable_spec.coffee +205 -0
  153. data/components/indefinido/indemma/master/src/spec/record/dirtyable_spec.coffee +47 -0
  154. data/components/indefinido/indemma/master/src/spec/record/maid_spec.coffee +34 -0
  155. data/components/indefinido/indemma/master/src/spec/record/persistable_spec.coffee +39 -0
  156. data/components/indefinido/indemma/master/src/spec/record/queryable_spec.coffee +33 -0
  157. data/components/indefinido/indemma/master/src/spec/record/resource_spec.coffee +69 -0
  158. data/components/indefinido/indemma/master/src/spec/record/rest_spec.coffee +22 -0
  159. data/components/indefinido/indemma/master/src/spec/record/restfulable_spec.coffee +257 -0
  160. data/components/indefinido/indemma/master/src/spec/record/scopable_spec.coffee +227 -0
  161. data/components/indefinido/indemma/master/src/spec/record/storable_spec.coffee +39 -0
  162. data/components/indefinido/indemma/master/src/spec/record/translationable.coffee +19 -0
  163. data/components/indefinido/indemma/master/src/spec/record/validatable_spec.coffee +127 -0
  164. data/components/indefinido/indemma/master/src/spec/record/validations/associated_spec.coffee +35 -0
  165. data/components/indefinido/indemma/master/src/spec/record/validations/confirmation_spec.coffee +25 -0
  166. data/components/indefinido/indemma/master/src/spec/record/validations/cpf_spec.coffee +27 -0
  167. data/components/indefinido/indemma/master/src/spec/record/validations/presence_spec.coffee +24 -0
  168. data/components/indefinido/indemma/master/src/spec/record/validations/remote_spec.coffee +74 -0
  169. data/components/indefinido/indemma/master/src/spec/record/validations/type_spec.coffee +33 -0
  170. data/components/indefinido/indemma/master/src/spec/record_spec.coffee +29 -0
  171. data/components/indefinido/indemma/master/src/spec/spec_helper.coffee +11 -0
  172. data/components/indefinido/indemma/master/src/spec/support/value_objects/phone.coffee +30 -0
  173. data/components/indefinido/indemma/master/vendor/object/mixin.js +196 -0
  174. data/components/indefinido/indemma/master/vendor/spec/sinon/assert.js +199 -0
  175. data/components/indefinido/indemma/master/vendor/spec/sinon/behavior.js +334 -0
  176. data/components/indefinido/indemma/master/vendor/spec/sinon/call.js +205 -0
  177. data/components/indefinido/indemma/master/vendor/spec/sinon/collection.js +155 -0
  178. data/components/indefinido/indemma/master/vendor/spec/sinon/match.js +245 -0
  179. data/components/indefinido/indemma/master/vendor/spec/sinon/mock.js +451 -0
  180. data/components/indefinido/indemma/master/vendor/spec/sinon/sandbox.js +144 -0
  181. data/components/indefinido/indemma/master/vendor/spec/sinon/spy.js +413 -0
  182. data/components/indefinido/indemma/master/vendor/spec/sinon/stub.js +161 -0
  183. data/components/indefinido/indemma/master/vendor/spec/sinon/test.js +77 -0
  184. data/components/indefinido/indemma/master/vendor/spec/sinon/test_case.js +99 -0
  185. data/components/indefinido/indemma/master/vendor/spec/sinon/util/event.js +94 -0
  186. data/components/indefinido/indemma/master/vendor/spec/sinon/util/fake_server.js +212 -0
  187. data/components/indefinido/indemma/master/vendor/spec/sinon/util/fake_server_with_clock.js +83 -0
  188. data/components/indefinido/indemma/master/vendor/spec/sinon/util/fake_timers.js +405 -0
  189. data/components/indefinido/indemma/master/vendor/spec/sinon/util/fake_xdomain_request.js +206 -0
  190. data/components/indefinido/indemma/master/vendor/spec/sinon/util/fake_xml_http_request.js +575 -0
  191. data/components/indefinido/indemma/master/vendor/spec/sinon/util/timers_ie.js +31 -0
  192. data/components/indefinido/indemma/master/vendor/spec/sinon/util/xdr_ie.js +14 -0
  193. data/components/indefinido/indemma/master/vendor/spec/sinon/util/xhr_ie.js +19 -0
  194. data/components/indefinido/indemma/master/vendor/spec/sinon.js +383 -0
  195. data/lib/assets/javascripts/value_objects/phone.js.coffee +3 -1
  196. data/lib/assets/javascripts/widgets/viewer/plugins/scopable.js.coffee +5 -5
  197. data/lib/ende/version.rb +1 -1
  198. data/vendor/assets/components/ende_build.css +4 -4
  199. data/vendor/assets/components/ende_build.js +7974 -7889
  200. metadata +191 -5
  201. data/vendor/assets/component/build.css +0 -112
  202. data/vendor/assets/components/build.css +0 -112
  203. data/vendor/assets/components/indemma_with_none.js +0 -30553
@@ -0,0 +1,346 @@
1
+ var model, record, root, should_behave_like_errorsable;
2
+
3
+ require('indemma/lib/record/restfulable.js');
4
+
5
+ require('indemma/lib/record/validatable.js');
6
+
7
+ require('indemma/lib/record/resource.js');
8
+
9
+ 'use strict';
10
+
11
+ root = typeof exports !== "undefined" && exports !== null ? exports : window;
12
+
13
+ model = root.model;
14
+
15
+ record = root.record;
16
+
17
+ should_behave_like_errorsable = function() {
18
+ return describe('.errors', function() {
19
+ return describe('when server responds', function() {
20
+ beforeEach(function() {
21
+ return this.xhr = {
22
+ status: 422
23
+ };
24
+ });
25
+ describe('with errors', function() {
26
+ it('should add messages for each attribute on the errors object');
27
+ return it('should add messages for base attribute on the errors object', function() {
28
+ var base_messages;
29
+
30
+ base_messages = ["arthur you should bring a towel!"];
31
+ this.xhr.responseText = JSON.stringify({
32
+ errors: {
33
+ base: base_messages
34
+ }
35
+ });
36
+ this.subject.failed(this.xhr, 'error');
37
+ this.subject.should.have.property('errors');
38
+ this.subject.errors[0].should.include('base', 'server', {
39
+ server_message: base_messages[0]
40
+ });
41
+ return this.subject.errors.messages.should.have.property('base', base_messages[0]);
42
+ });
43
+ });
44
+ return describe('with invalid error messages', function() {
45
+ return it('when inexistent attribute should throw exception', function() {});
46
+ });
47
+ });
48
+ });
49
+ };
50
+
51
+ describe('restfulable', function() {
52
+ describe('when included', function() {
53
+ return it('sets te restufulable loaded flag on model', function() {
54
+ return model.restfulable.should.be["true"];
55
+ });
56
+ });
57
+ describe('record', function() {
58
+ var arthur;
59
+
60
+ arthur = null;
61
+ return describe('()', function() {
62
+ beforeEach(function() {
63
+ this.person = model.call({
64
+ resource: 'person'
65
+ });
66
+ this.arthur = this.person({
67
+ name: 'Arthur Philip Dent'
68
+ });
69
+ return this.arthur.dirty = true;
70
+ });
71
+ describe('.json()', function() {
72
+ return it('should remove all non data properties', function() {
73
+ return this.arthur.json().should.not.have.property('before_initialize');
74
+ });
75
+ });
76
+ return describe('.save()', function() {
77
+ beforeEach(function() {
78
+ return sinon.stub(jQuery, "ajax").returns(jQuery.Deferred());
79
+ });
80
+ afterEach(function() {
81
+ return jQuery.ajax.restore();
82
+ });
83
+ it('should be able to serialize record', function() {
84
+ return JSON.stringify(this.arthur.json());
85
+ });
86
+ it('should ignore key in transient fields');
87
+ it('should send paramenters accordingly');
88
+ return it('should make ajax call', function() {
89
+ this.arthur.save();
90
+ return jQuery.ajax.called.should.be["true"];
91
+ });
92
+ });
93
+ });
94
+ });
95
+ return describe('model', function() {
96
+ return describe('()', function() {
97
+ describe('.json()', function() {
98
+ return beforeEach(function() {
99
+ this.personable = model.call({
100
+ resource: 'person',
101
+ has_many: 'friends',
102
+ nested_attributes: ['friends'],
103
+ name: String
104
+ });
105
+ return this.friendable = model.call({
106
+ resource: 'friend',
107
+ belongs_to: 'person'
108
+ });
109
+ });
110
+ });
111
+ describe('.assign_attributes()', function() {
112
+ beforeEach(function() {
113
+ this.personable = model.call({
114
+ resource: 'person',
115
+ has_many: 'friends',
116
+ belongs_to: 'company',
117
+ has_one: 'towel',
118
+ name: String
119
+ });
120
+ this.friendable = model.call({
121
+ resource: 'friend',
122
+ belongs_to: 'person',
123
+ name: String
124
+ });
125
+ this.companyable = model.call({
126
+ resource: 'company',
127
+ has_many: 'people',
128
+ name: String
129
+ });
130
+ this.towelable = model.call({
131
+ resource: 'towel',
132
+ belongs_to: 'person',
133
+ material: String
134
+ });
135
+ this.arthur = this.personable({
136
+ name: 'Arthur Dent'
137
+ });
138
+ this.ford = this.friendable({
139
+ name: 'Ford Perfect'
140
+ });
141
+ this.marvin = this.friendable({
142
+ name: 'Marvin'
143
+ });
144
+ this.megadodo = this.companyable({
145
+ name: 'Megadodo Publications'
146
+ });
147
+ return this.towel = this.towelable({
148
+ material: 'Microfiber'
149
+ });
150
+ });
151
+ it('should not assign attribute with the same value twice', function() {
152
+ var object;
153
+
154
+ object = {};
155
+ this.arthur = this.personable({
156
+ name: object
157
+ });
158
+ this.arthur.assign_attributes({
159
+ name: {
160
+ wearing: 'robe'
161
+ }
162
+ });
163
+ return this.arthur.name.should.not.be.eq(object);
164
+ });
165
+ it('assigns associations properly', function() {
166
+ var attributes, search_record;
167
+
168
+ attributes = {
169
+ friends: [this.ford, this.marvin]
170
+ };
171
+ this.arthur.assign_attributes(attributes);
172
+ search_record = function(association, search) {
173
+ var associated, _i, _len;
174
+
175
+ search = JSON.stringify(search.json());
176
+ for (_i = 0, _len = association.length; _i < _len; _i++) {
177
+ associated = association[_i];
178
+ associated = JSON.stringify(associated.json());
179
+ if (associated === search) {
180
+ return true;
181
+ }
182
+ }
183
+ return false;
184
+ };
185
+ search_record(this.arthur.friends, this.ford).should.be.eq["true"];
186
+ return search_record(this.arthur.friends, this.arthur).should.be.eq["true"];
187
+ });
188
+ describe('when assigning has one', function() {
189
+ it('should build new objects when associated not defined', function() {
190
+ this.arthur.assign_attributes({
191
+ towel: {
192
+ material: 'Copper'
193
+ }
194
+ });
195
+ this.arthur.should.have.property('towel');
196
+ return this.arthur.towel.should.have.property('material', 'Copper');
197
+ });
198
+ return it('should not build new objects when associated already defined', function() {
199
+ this.arthur.towel = this.towel;
200
+ this.arthur.assign_attributes({
201
+ towel: {
202
+ name: 'Copper'
203
+ }
204
+ });
205
+ this.arthur.should.have.property('towel', this.towel);
206
+ this.arthur.towel.should.have.property('name', 'Copper');
207
+ return this.towel.should.have.property('name', 'Copper');
208
+ });
209
+ });
210
+ return describe('when assigning belongs to', function() {
211
+ it('should build new objects when associated not defined', function() {
212
+ this.arthur.assign_attributes({
213
+ company: {
214
+ name: 'Megado'
215
+ }
216
+ });
217
+ this.arthur.should.have.property('company');
218
+ return this.arthur.company.should.have.property('name', 'Megado');
219
+ });
220
+ return it('should not build new objects when associated already defined', function() {
221
+ this.arthur.company = this.megadodo;
222
+ this.arthur.assign_attributes({
223
+ company: {
224
+ name: 'Megado'
225
+ }
226
+ });
227
+ this.arthur.should.have.property('company', this.megadodo);
228
+ this.arthur.company.should.have.property('name', 'Megado');
229
+ return this.megadodo.should.have.property('name', 'Megado');
230
+ });
231
+ });
232
+ });
233
+ describe('with singular resource', function() {
234
+ return describe('.create()', function() {
235
+ it('should return promises');
236
+ return it('should return models when promise is resolved');
237
+ });
238
+ });
239
+ describe('with plural resource', function() {
240
+ return describe('.create()', function() {
241
+ beforeEach(function() {
242
+ this.personable = model.call({
243
+ resource: 'person'
244
+ });
245
+ this.deferred = jQuery.Deferred();
246
+ this.deferred.resolveWith(this.personable({
247
+ _id: 1,
248
+ name: 'Arthur'
249
+ }), [
250
+ {
251
+ _id: 1,
252
+ name: 'Arthur'
253
+ }
254
+ ]);
255
+ sinon.stub(jQuery, "ajax").returns(this.deferred);
256
+ return this.promise = this.personable.create({
257
+ name: 'Arthur'
258
+ }, {
259
+ name: 'Ford'
260
+ });
261
+ });
262
+ afterEach(function() {
263
+ return jQuery.ajax.restore();
264
+ });
265
+ it('should return a promise', function() {
266
+ this.promise.done.should.be["function"];
267
+ return this.promise.state().should.be.eq('resolved');
268
+ });
269
+ it('should return models when promise is resolved', function(done) {
270
+ var created;
271
+
272
+ created = function() {
273
+ this.name.should.be.eq('Arthur');
274
+ return done();
275
+ };
276
+ return this.personable.create({
277
+ name: 'Arthur'
278
+ }, {
279
+ name: 'Ford'
280
+ }, created);
281
+ });
282
+ it('should optionally accept create callback', function(done) {
283
+ this.promise = this.personable.create({
284
+ name: 'Arthur'
285
+ }, {
286
+ name: 'Ford'
287
+ });
288
+ this.promise.done.should.be["function"];
289
+ this.promise.done(function() {
290
+ return done();
291
+ });
292
+ return this.promise.state().should.be.eq('resolved');
293
+ });
294
+ it('should create record when only callback is passed', function(done) {
295
+ this.personable.create(function() {
296
+ return done();
297
+ });
298
+ return jQuery.ajax.callCount.should.be.eq(3);
299
+ });
300
+ it('should throw exception when nothing is passed', function() {
301
+ return expect(this.personable.create).to["throw"](TypeError);
302
+ });
303
+ return it('should make ajax calls', function() {
304
+ return jQuery.ajax.callCount.should.be.eq(2);
305
+ });
306
+ });
307
+ });
308
+ return describe('.destroy()', function() {
309
+ return describe('with plural resource', function() {
310
+ var arthur, deferred, person;
311
+
312
+ arthur = person = deferred = null;
313
+ beforeEach(function() {
314
+ person = model.call({
315
+ resource: 'person'
316
+ });
317
+ deferred = jQuery.Deferred();
318
+ deferred.resolveWith(person({
319
+ name: 'Arthur'
320
+ }), [
321
+ {
322
+ id: 1
323
+ }
324
+ ]);
325
+ sinon.stub(jQuery, "ajax").returns(deferred);
326
+ return arthur = person({
327
+ name: 'Arthur',
328
+ id: 1
329
+ });
330
+ });
331
+ afterEach(function() {
332
+ return jQuery.ajax.restore();
333
+ });
334
+ it("throw exception when record has no id", function() {
335
+ delete arthur.id;
336
+ return expect(arthur.destroy).to["throw"](Error);
337
+ });
338
+ return it("should make ajax calls", function() {
339
+ arthur.destroy();
340
+ return jQuery.ajax.callCount.should.be.eq(1);
341
+ });
342
+ });
343
+ });
344
+ });
345
+ });
346
+ });
@@ -0,0 +1,242 @@
1
+ var model, record, root;
2
+
3
+ require('indemma/lib/record/resource.js');
4
+
5
+ require('indemma/lib/record/restfulable.js');
6
+
7
+ require('indemma/lib/record/scopable.js');
8
+
9
+ root = typeof exports !== "undefined" && exports !== null ? exports : window;
10
+
11
+ model = root.model;
12
+
13
+ record = root.record;
14
+
15
+ describe('scopable', function() {
16
+ describe('when included', function() {
17
+ return it('sets te scopable loaded flag on model', function() {
18
+ return model.scopable.should.be["true"];
19
+ });
20
+ });
21
+ return describe('model', function() {
22
+ return describe('#(options)', function() {
23
+ beforeEach(function() {
24
+ return this.person = model.call({
25
+ $hetero: true,
26
+ $by_type: [],
27
+ $by_name: String,
28
+ resource: 'person'
29
+ });
30
+ });
31
+ it('should add scope methods to model', function() {
32
+ return this.person.none.should.be["function"];
33
+ });
34
+ it('should generate scope methods based on model definition', function() {
35
+ return this.person.hetero.should.be["function"];
36
+ });
37
+ describe('#none', function() {
38
+ return it('should return empty response on fetch calls', function(done) {
39
+ return this.person.none().fetch(null, function(people) {
40
+ people.length.should.be.empty;
41
+ return done();
42
+ });
43
+ });
44
+ });
45
+ describe('scope', function() {
46
+ return describe('#(name, type)', function() {
47
+ return it('should add scope methods to model', function() {
48
+ this.person.scope('bissexual', Boolean);
49
+ return this.person.bissexual.should.be["function"];
50
+ });
51
+ });
52
+ });
53
+ return describe('#{generated_scope}', function() {
54
+ beforeEach(function() {
55
+ this.request = jQuery.Deferred();
56
+ sinon.stub(jQuery, "ajax").returns(this.request);
57
+ return this.person.scope.clear();
58
+ });
59
+ afterEach(function() {
60
+ return jQuery.ajax.restore();
61
+ });
62
+ describe('#every', function() {
63
+ return it('should fetch models from the server', function(done) {
64
+ var fetched;
65
+
66
+ fetched = function(people) {
67
+ people.should.be.array;
68
+ people[0].name.should.be.string;
69
+ return done();
70
+ };
71
+ this.person.every(fetched);
72
+ return this.request.resolveWith(this.person, [
73
+ [
74
+ {
75
+ name: 'Arthur'
76
+ }, {
77
+ name: 'Ford'
78
+ }
79
+ ]
80
+ ]);
81
+ });
82
+ });
83
+ describe('when string', function() {
84
+ it('should acumulate data in scope object', function() {
85
+ this.person.by_name();
86
+ return this.person.scope.data.by_name.should.be.a('string');
87
+ });
88
+ return it('should override data throught parameters', function() {
89
+ this.person.by_name('Ford');
90
+ return this.person.scope.data.by_name.should.be.eq('Ford');
91
+ });
92
+ });
93
+ describe('when array', function() {
94
+ it('should acumulate data in scope object', function() {
95
+ this.person.by_type();
96
+ return this.person.scope.data.by_type.should.be.a('array');
97
+ });
98
+ it('should override data throught parameters', function() {
99
+ this.person.by_type(1, 2, 3);
100
+ return this.person.scope.data.by_type.should.contain(1, 2, 3);
101
+ });
102
+ it('should use default value');
103
+ it('should allow scope chaining');
104
+ return describe('xhr request', function() {
105
+ it('should build correct url', function() {
106
+ var settings;
107
+
108
+ this.person.by_type(1, 3, 4).fetch();
109
+ settings = jQuery.ajax.firstCall.args[0];
110
+ settings.should.have.property('data');
111
+ settings.data.should.have.property('by_type');
112
+ return settings.data.by_type.should.include(1, 3, 4);
113
+ });
114
+ return it('should make call', function() {
115
+ this.person.by_type(1, 3, 4).fetch();
116
+ return jQuery.ajax.callCount.should.be.eq(1);
117
+ });
118
+ });
119
+ });
120
+ describe('when boolean', function() {
121
+ it('should acumulate data in scope object', function() {
122
+ this.person.hetero();
123
+ return this.person.scope.data.hetero.should.be.eq(true);
124
+ });
125
+ it('should override data throught parameters', function() {
126
+ this.person.hetero(false);
127
+ return this.person.scope.data.hetero.should.be.eq(false);
128
+ });
129
+ it('should allow scope chaining');
130
+ return it('should make ajax call', function() {
131
+ this.person.hetero().fetch();
132
+ return jQuery.ajax.callCount.should.be.eq(1);
133
+ });
134
+ });
135
+ return describe('#{generated_association}', function() {
136
+ describe('of type belongs_to', function() {
137
+ beforeEach(function() {
138
+ this.person = model.call({
139
+ $hetero: true,
140
+ $by_type: [],
141
+ resource: 'person'
142
+ });
143
+ return this.towel = model.call({
144
+ resource: 'towel',
145
+ material: 'cotton',
146
+ belongs_to: 'person'
147
+ });
148
+ });
149
+ return describe('#{generated_scope}', function() {
150
+ return xit('can be called on association', function() {
151
+ var soft_towel;
152
+
153
+ soft_towel = this.towel({
154
+ material: 'silicon microfiber'
155
+ });
156
+ soft_towel.build_person();
157
+ return expect(soft_towel.person).to.respondTo('hetero');
158
+ });
159
+ });
160
+ });
161
+ return describe('of type has_many', function() {
162
+ beforeEach(function() {
163
+ this.personable = model.call({
164
+ $hetero: true,
165
+ $by_type: [],
166
+ resource: 'person',
167
+ has_many: 'towels',
168
+ nested_attributes: ['towels']
169
+ });
170
+ this.towelable = model.call({
171
+ $by_material: [],
172
+ resource: 'towel',
173
+ material: 'cotton',
174
+ belongs_to: 'person'
175
+ });
176
+ this.arthur = this.personable({
177
+ name: 'Arthur'
178
+ });
179
+ return this.personable.scope.clear();
180
+ });
181
+ return describe('#{generated_scope}', function() {
182
+ it('can be called on association', function() {
183
+ return expect(this.arthur.towels).to.respondTo('by_material');
184
+ });
185
+ it('should be serializable into paramenters', function() {
186
+ var query_string;
187
+
188
+ this.arthur.towels.by_material('cotton', 'microfiber');
189
+ query_string = decodeURIComponent(jQuery.param(this.arthur.towels.scope.data));
190
+ return query_string.should.be.eq('by_material[]=cotton&by_material[]=microfiber');
191
+ });
192
+ return describe('#every', function() {
193
+ it('should empty association when no models are returned', function(done) {
194
+ var fetched,
195
+ _this = this;
196
+
197
+ fetched = function(towels) {
198
+ towels.should.be.array;
199
+ towels.should.be.empty;
200
+ _this.arthur.towels.should.have.length(0);
201
+ this.should.have.length(0) ;
202
+ return done();
203
+ };
204
+ this.arthur.towels.every(fetched);
205
+ this.request.resolveWith(this.arthur.towels, [[]]);
206
+ return jQuery.ajax.callCount.should.be.eq(1);
207
+ });
208
+ return it('should update resources when already exists in association', function(done) {
209
+ var additions, fetched,
210
+ _this = this;
211
+
212
+ additions = this.arthur.towels.add({
213
+ _id: 1,
214
+ material: 'colan'
215
+ });
216
+ fetched = function(towels) {
217
+ towels.should.be.array;
218
+ towels.should.have.length(1);
219
+ towels[0].material.should.be.eq('cotton');
220
+ additions[0].material.should.be.eq('cotton');
221
+ _this.arthur.towels[0].material.should.be.eq('cotton');
222
+ return done();
223
+ };
224
+ this.arthur.towels.every(fetched);
225
+ this.request.resolveWith(this.arthur.towels, [
226
+ [
227
+ {
228
+ _id: 1,
229
+ material: 'cotton'
230
+ }
231
+ ]
232
+ ]);
233
+ return jQuery.ajax.callCount.should.be.eq(1);
234
+ });
235
+ });
236
+ });
237
+ });
238
+ });
239
+ });
240
+ });
241
+ });
242
+ });
@@ -0,0 +1,44 @@
1
+ 'use strict';
2
+ var storable;
3
+
4
+ storable = require('indemma/lib/record/storable.js');
5
+
6
+ describe('storable', function() {
7
+ it('should set the storable key', function() {
8
+ return model.should.have.property('storable', true);
9
+ });
10
+ beforeEach(function() {
11
+ return this.storage = storable();
12
+ });
13
+ return describe("#store", function() {
14
+ beforeEach(function() {
15
+ return this.data = {
16
+ name: 'Arthur Dent'
17
+ };
18
+ });
19
+ describe("write", function() {
20
+ it("should write object on deep storage");
21
+ it("should write object on storage", function() {
22
+ this.storage.store('1', this.data);
23
+ this.storage.writes.should.be.eq(1);
24
+ return this.storage.database['1'].should.be.eq(this.data);
25
+ });
26
+ return it("should mark an object as sustained", function() {
27
+ this.storage.store('1', this.data);
28
+ return this.data.should.have.property('sustained', true);
29
+ });
30
+ });
31
+ return describe("read", function() {
32
+ beforeEach(function() {
33
+ this.data = {
34
+ name: 'Arthur Dent'
35
+ };
36
+ return this.storage.store('1', this.data);
37
+ });
38
+ it("should save object on storage", function() {
39
+ return this.storage.store('1').should.be.eq(this.data);
40
+ });
41
+ return it("should unmark an object as sustained");
42
+ });
43
+ });
44
+ });
@@ -0,0 +1,28 @@
1
+ var root;
2
+
3
+ root = typeof exports !== "undefined" && exports !== null ? exports : window;
4
+
5
+ require('indemma/lib/record/translationable.js');
6
+
7
+ describe('model', function() {
8
+ var model, person;
9
+
10
+ model = root.model;
11
+ person = null;
12
+ beforeEach(function() {
13
+ return person = model.call({
14
+ resource: 'person',
15
+ name: String,
16
+ translation: {
17
+ attributes: {
18
+ name: 'Batata'
19
+ }
20
+ }
21
+ });
22
+ });
23
+ return describe('#human_attribute_name', function() {
24
+ return it('should return the translated attribute name', function() {
25
+ return person.human_attribute_name('name').should.be.eq('Batata');
26
+ });
27
+ });
28
+ });