ende 0.1.14 → 0.2.0

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 (138) hide show
  1. checksums.yaml +4 -4
  2. data/component.json +1 -1
  3. data/lib/assets/javascripts/aura/extensions/devise.js.coffee +5 -2
  4. data/lib/assets/javascripts/aura/extensions/models.js.coffee.erb +4 -3
  5. data/lib/assets/javascripts/value_objects/phone.js.coffee +8 -2
  6. data/lib/assets/javascripts/widgets/viewer/main.js.coffee +18 -21
  7. data/lib/ende/version.rb +1 -1
  8. data/lib/ende.rb +2 -2
  9. data/vendor/assets/javascripts/ende/build.js +485 -4879
  10. data/vendor/components/component-querystring/component.json +18 -0
  11. data/vendor/components/component-querystring/index.js +49 -0
  12. data/vendor/components/component-trim/component.json +13 -0
  13. data/vendor/components/component-trim/index.js +17 -0
  14. data/vendor/components/indefinido-indemma/.gitignore +14 -0
  15. data/vendor/components/indefinido-indemma/.ruby-gemset +1 -0
  16. data/vendor/components/indefinido-indemma/.ruby-version +1 -0
  17. data/vendor/components/indefinido-indemma/Gemfile +13 -0
  18. data/vendor/components/indefinido-indemma/Guardfile +39 -0
  19. data/vendor/components/indefinido-indemma/History.md +0 -0
  20. data/vendor/components/indefinido-indemma/Readme.md +443 -0
  21. data/vendor/components/indefinido-indemma/build/development.js +331 -0
  22. data/vendor/components/indefinido-indemma/build/release.js +21693 -0
  23. data/vendor/components/indefinido-indemma/build/test.js +331 -0
  24. data/vendor/components/indefinido-indemma/component.json +8 -9
  25. data/vendor/components/indefinido-indemma/components/chaijs-assertion-error/component.json +18 -0
  26. data/vendor/components/indefinido-indemma/components/chaijs-assertion-error/index.js +110 -0
  27. data/vendor/components/indefinido-indemma/components/chaijs-chai/component.json +47 -0
  28. data/vendor/components/indefinido-indemma/components/chaijs-chai/index.js +1 -0
  29. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/assertion.js +130 -0
  30. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/core/assertions.js +1270 -0
  31. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/interface/assert.js +1080 -0
  32. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/interface/expect.js +12 -0
  33. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/interface/should.js +76 -0
  34. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/addChainableMethod.js +94 -0
  35. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/addMethod.js +37 -0
  36. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/addProperty.js +40 -0
  37. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/eql.js +129 -0
  38. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/flag.js +32 -0
  39. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/getActual.js +19 -0
  40. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/getEnumerableProperties.js +25 -0
  41. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/getMessage.js +49 -0
  42. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/getName.js +20 -0
  43. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/getPathValue.js +102 -0
  44. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/getProperties.js +35 -0
  45. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/index.js +108 -0
  46. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/inspect.js +320 -0
  47. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/objDisplay.js +48 -0
  48. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/overwriteMethod.js +51 -0
  49. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/overwriteProperty.js +54 -0
  50. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/test.js +26 -0
  51. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/transferFlags.js +44 -0
  52. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/type.js +45 -0
  53. data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai.js +80 -0
  54. data/vendor/components/indefinido-indemma/components/component-bind/component.json +14 -0
  55. data/vendor/components/indefinido-indemma/components/component-bind/index.js +24 -0
  56. data/vendor/components/indefinido-indemma/components/component-jquery/component.json +14 -0
  57. data/vendor/components/indefinido-indemma/components/component-jquery/index.js +9601 -0
  58. data/vendor/components/indefinido-indemma/components/component-type/component.json +18 -0
  59. data/vendor/components/indefinido-indemma/components/component-type/index.js +32 -0
  60. data/vendor/components/indefinido-indemma/components/indefinido-advisable/component.json +21 -0
  61. data/vendor/components/indefinido-indemma/components/indefinido-advisable/index.js +1 -0
  62. data/vendor/components/indefinido-indemma/components/indefinido-advisable/lib/advisable.js +60 -0
  63. data/vendor/components/indefinido-indemma/components/indefinido-observable/component.json +25 -0
  64. data/vendor/components/indefinido-indemma/components/indefinido-observable/components/cjohansen-sinon/sinon.js +4290 -0
  65. data/vendor/components/indefinido-indemma/components/indefinido-observable/index.js +1 -0
  66. data/vendor/components/indefinido-indemma/components/indefinido-observable/lib/adapters/rivets.js +26 -0
  67. data/vendor/components/indefinido-indemma/components/indefinido-observable/lib/observable.js +323 -0
  68. data/vendor/components/indefinido-indemma/components/indefinido-observable/vendor/shims/accessors-legacy.js +92 -0
  69. data/vendor/components/indefinido-indemma/components/indefinido-observable/vendor/shims/accessors.js +173 -0
  70. data/vendor/components/indefinido-indemma/components/indefinido-observable/vendor/shims/array.indexOf.js +8 -0
  71. data/vendor/components/indefinido-indemma/components/indefinido-observable/vendor/shims/object.create.js +77 -0
  72. data/vendor/components/indefinido-indemma/components/kapit-observe-utils/component.json +13 -0
  73. data/vendor/components/indefinido-indemma/components/pluma-assimilate/component.json +25 -0
  74. data/vendor/components/indefinido-indemma/components/pluma-assimilate/dist/assimilate.js +87 -0
  75. data/vendor/components/indefinido-indemma/karma.conf.js +86 -0
  76. data/vendor/components/indefinido-indemma/lib/record/associable.js +6 -6
  77. data/vendor/components/indefinido-indemma/lib/record/errors.js +1 -0
  78. data/vendor/components/indefinido-indemma/lib/record/resource.js +14 -3
  79. data/vendor/components/indefinido-indemma/lib/record/rest.js +7 -4
  80. data/vendor/components/indefinido-indemma/lib/record/restfulable.js +45 -15
  81. data/vendor/components/indefinido-indemma/lib/record/scopable.js +13 -3
  82. data/vendor/components/indefinido-indemma/lib/record/validatable.js +20 -9
  83. data/vendor/components/indefinido-indemma/lib/record/validations/confirmation.js +1 -1
  84. data/vendor/components/indefinido-indemma/lib/record/validations/remote.js +6 -5
  85. data/vendor/components/indefinido-indemma/lib/record/validations/type.js +29 -0
  86. data/vendor/components/indefinido-indemma/lib/record.js +1 -11
  87. data/vendor/components/indefinido-indemma/spec/record/associable_spec.js +76 -0
  88. data/vendor/components/indefinido-indemma/spec/record/resource_spec.js +90 -0
  89. data/vendor/components/indefinido-indemma/spec/record/rest_spec.js +32 -0
  90. data/vendor/components/indefinido-indemma/spec/record/restfulable_spec.js +232 -0
  91. data/vendor/components/indefinido-indemma/spec/record/scopable_spec.js +201 -0
  92. data/vendor/components/indefinido-indemma/spec/record/translationable.js +28 -0
  93. data/vendor/components/indefinido-indemma/spec/record/validatable_spec.js +111 -0
  94. data/vendor/components/indefinido-indemma/spec/record/validations/associated_spec.js +43 -0
  95. data/vendor/components/indefinido-indemma/spec/record/validations/confirmation_spec.js +36 -0
  96. data/vendor/components/indefinido-indemma/spec/record/validations/cpf_spec.js +35 -0
  97. data/vendor/components/indefinido-indemma/spec/record/validations/presence_spec.js +28 -0
  98. data/vendor/components/indefinido-indemma/spec/record/validations/remote_spec.js +86 -0
  99. data/vendor/components/indefinido-indemma/spec/record/validations/type_spec.js +48 -0
  100. data/vendor/components/indefinido-indemma/spec/record_spec.js +37 -0
  101. data/vendor/components/indefinido-indemma/spec/spec_helper.js +11 -0
  102. data/vendor/components/indefinido-indemma/spec/support/value_objects/phone.js +45 -0
  103. data/vendor/components/indefinido-indemma/src/lib/extensions/rivets.coffee +17 -0
  104. data/vendor/components/indefinido-indemma/src/lib/record/associable.coffee +173 -0
  105. data/vendor/components/indefinido-indemma/src/lib/record/errors.coffee +20 -0
  106. data/vendor/components/indefinido-indemma/src/lib/record/maid.coffee +16 -0
  107. data/vendor/components/indefinido-indemma/src/lib/record/resource.coffee +103 -0
  108. data/vendor/components/indefinido-indemma/src/lib/record/rest.coffee +28 -0
  109. data/vendor/components/indefinido-indemma/src/lib/record/restfulable.coffee +314 -0
  110. data/vendor/components/indefinido-indemma/src/lib/record/scopable.coffee +266 -0
  111. data/vendor/components/indefinido-indemma/src/lib/record/translationable.coffee +18 -0
  112. data/vendor/components/indefinido-indemma/src/lib/record/validatable.coffee +209 -0
  113. data/vendor/components/indefinido-indemma/src/lib/record/validations/associated.coffee +32 -0
  114. data/vendor/components/indefinido-indemma/src/lib/record/validations/confirmation.coffee +19 -0
  115. data/vendor/components/indefinido-indemma/src/lib/record/validations/cpf.coffee +58 -0
  116. data/vendor/components/indefinido-indemma/src/lib/record/validations/presence.coffee +19 -0
  117. data/vendor/components/indefinido-indemma/src/lib/record/validations/remote.coffee +65 -0
  118. data/vendor/components/indefinido-indemma/src/lib/record/validations/type.coffee +32 -0
  119. data/vendor/components/indefinido-indemma/src/lib/record.coffee +123 -0
  120. data/vendor/components/indefinido-indemma/src/spec/record/associable_spec.coffee +63 -0
  121. data/vendor/components/indefinido-indemma/src/spec/record/resource_spec.coffee +64 -0
  122. data/vendor/components/indefinido-indemma/src/spec/record/rest_spec.coffee +22 -0
  123. data/vendor/components/indefinido-indemma/src/spec/record/restfulable_spec.coffee +164 -0
  124. data/vendor/components/indefinido-indemma/src/spec/record/scopable_spec.coffee +181 -0
  125. data/vendor/components/indefinido-indemma/src/spec/record/translationable.coffee +19 -0
  126. data/vendor/components/indefinido-indemma/src/spec/record/validatable_spec.coffee +100 -0
  127. data/vendor/components/indefinido-indemma/src/spec/record/validations/associated_spec.coffee +35 -0
  128. data/vendor/components/indefinido-indemma/src/spec/record/validations/confirmation_spec.coffee +25 -0
  129. data/vendor/components/indefinido-indemma/src/spec/record/validations/cpf_spec.coffee +28 -0
  130. data/vendor/components/indefinido-indemma/src/spec/record/validations/presence_spec.coffee +24 -0
  131. data/vendor/components/indefinido-indemma/src/spec/record/validations/remote_spec.coffee +72 -0
  132. data/vendor/components/indefinido-indemma/src/spec/record/validations/type_spec.coffee +33 -0
  133. data/vendor/components/indefinido-indemma/src/spec/record_spec.coffee +23 -0
  134. data/vendor/components/indefinido-indemma/src/spec/spec_helper.coffee +9 -0
  135. data/vendor/components/indefinido-indemma/src/spec/support/value_objects/phone.coffee +30 -0
  136. data/vendor/components/indefinido-indemma/vendor/owl/pluralize.js +190 -0
  137. data/vendor/components/indefinido-observable/lib/observable.js +3 -0
  138. metadata +119 -2
@@ -0,0 +1,201 @@
1
+ var model, record, root;
2
+
3
+ require('indemma/lib/record/resource');
4
+
5
+ require('indemma/lib/record/restfulable');
6
+
7
+ require('indemma/lib/record/scopable');
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
+ var person;
24
+
25
+ person = null;
26
+ beforeEach(function() {
27
+ return person = model.call({
28
+ $hetero: true,
29
+ $by_type: [],
30
+ resource: 'person'
31
+ });
32
+ });
33
+ it('should add scope methods to model', function() {
34
+ return person.none.should.be["function"];
35
+ });
36
+ it('should generate scope methods based on model definition', function() {
37
+ return person.hetero.should.be["function"];
38
+ });
39
+ describe('#none', function() {
40
+ return it('should return empty response on fetch calls', function(done) {
41
+ return person.none().fetch(null, function(people) {
42
+ people.length.should.be.empty;
43
+ return done();
44
+ });
45
+ });
46
+ });
47
+ describe('scope', function() {
48
+ return describe('#(name, type)', function() {
49
+ return it('should add scope methods to model', function() {
50
+ person.scope('bissexual', Boolean);
51
+ return person.bissexual.should.be["function"];
52
+ });
53
+ });
54
+ });
55
+ return describe('#{generated_scope}', function() {
56
+ var deferred;
57
+
58
+ deferred = null;
59
+ beforeEach(function() {
60
+ deferred = jQuery.Deferred();
61
+ sinon.stub(jQuery, "ajax").returns(deferred);
62
+ return person.scope.clear();
63
+ });
64
+ afterEach(function() {
65
+ return jQuery.ajax.restore();
66
+ });
67
+ describe('#all', function() {
68
+ var promises;
69
+
70
+ deferred = promises = person = null;
71
+ return it('should return models when promise is resolved', function(done) {
72
+ var fetched;
73
+
74
+ fetched = function(people) {
75
+ people.should.be.array;
76
+ people[0].name.should.be.string;
77
+ return done();
78
+ };
79
+ person.all(fetched);
80
+ deferred.resolveWith(person, [
81
+ [
82
+ {
83
+ name: 'Arthur'
84
+ }, {
85
+ name: 'Ford'
86
+ }
87
+ ]
88
+ ]);
89
+ return jQuery.ajax.callCount.should.be.eq(1);
90
+ });
91
+ });
92
+ describe('when array', function() {
93
+ it('should acumulate data in scope object', function() {
94
+ person.by_type();
95
+ return person.scope.data.by_type.should.be.a('array');
96
+ });
97
+ it('should override data throught parameters', function() {
98
+ person.by_type(1, 2, 3);
99
+ return person.scope.data.by_type.should.contain(1, 2, 3);
100
+ });
101
+ it('should use default value');
102
+ it('should allow scope chaining');
103
+ return describe('xhr request', function() {
104
+ it('should build correct url', function() {
105
+ var settings;
106
+
107
+ person.by_type(1, 3, 4).fetch();
108
+ settings = jQuery.ajax.firstCall.args[0];
109
+ settings.should.have.property('data');
110
+ settings.data.should.have.property('by_type');
111
+ return settings.data.by_type.should.include(1, 3, 4);
112
+ });
113
+ return it('should make call', function() {
114
+ person.by_type(1, 3, 4).fetch();
115
+ return jQuery.ajax.callCount.should.be.eq(1);
116
+ });
117
+ });
118
+ });
119
+ describe('when boolean', function() {
120
+ it('should acumulate data in scope object', function() {
121
+ person.hetero();
122
+ return person.scope.data.hetero.should.be.eq(true);
123
+ });
124
+ it('should override data throught parameters', function() {
125
+ person.hetero(false);
126
+ return person.scope.data.hetero.should.be.eq(false);
127
+ });
128
+ it('should allow scope chaining');
129
+ return it('should make ajax call', function() {
130
+ person.hetero().fetch();
131
+ return jQuery.ajax.callCount.should.be.eq(1);
132
+ });
133
+ });
134
+ return describe('#{generated_association}', function() {
135
+ describe('of type belongs_to', function() {
136
+ var towel;
137
+
138
+ towel = null;
139
+ beforeEach(function() {
140
+ person = model.call({
141
+ $hetero: true,
142
+ $by_type: [],
143
+ resource: 'person'
144
+ });
145
+ return towel = model.call({
146
+ resource: 'towel',
147
+ material: 'cotton',
148
+ belongs_to: 'person'
149
+ });
150
+ });
151
+ return describe('#{generated_scope}', function() {
152
+ return it('can be called on association', function() {
153
+ var soft_towel;
154
+
155
+ soft_towel = towel({
156
+ material: 'silicon microfiber'
157
+ });
158
+ soft_towel.build_person();
159
+ return expect(soft_towel.person).to.respondTo('hetero');
160
+ });
161
+ });
162
+ });
163
+ return describe('of type has_many', function() {
164
+ var arthur, towel;
165
+
166
+ arthur = towel = null;
167
+ beforeEach(function() {
168
+ person = model.call({
169
+ $hetero: true,
170
+ $by_type: [],
171
+ resource: 'person',
172
+ has_many: 'towels'
173
+ });
174
+ towel = model.call({
175
+ $by_material: [],
176
+ resource: 'towel',
177
+ material: 'cotton',
178
+ belongs_to: 'person'
179
+ });
180
+ return arthur = person({
181
+ name: 'Arthur'
182
+ });
183
+ });
184
+ return describe('#{generated_scope}', function() {
185
+ it('can be called on association', function() {
186
+ return expect(arthur.towels).to.respondTo('by_material');
187
+ });
188
+ return it('should be serializable into paramenters', function() {
189
+ var query_string;
190
+
191
+ arthur.towels.by_material('cotton', 'microfiber');
192
+ query_string = decodeURIComponent(jQuery.param(arthur.towels.scope.data));
193
+ return query_string.should.be.eq('by_material[]=cotton&by_material[]=microfiber');
194
+ });
195
+ });
196
+ });
197
+ });
198
+ });
199
+ });
200
+ });
201
+ });
@@ -0,0 +1,28 @@
1
+ var root;
2
+
3
+ root = typeof exports !== "undefined" && exports !== null ? exports : window;
4
+
5
+ require('indemma/lib/record/translationable');
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
+ });
@@ -0,0 +1,111 @@
1
+ var root;
2
+
3
+ root = typeof exports !== "undefined" && exports !== null ? exports : window;
4
+
5
+ require('indemma/lib/record/validatable');
6
+
7
+ describe('model', function() {
8
+ var corporation, model, person;
9
+
10
+ model = root.model;
11
+ person = corporation = null;
12
+ beforeEach(function() {
13
+ return person = model.call({
14
+ resource: 'person'
15
+ });
16
+ });
17
+ it('should store validators', function() {
18
+ person.should.have.property('validators');
19
+ return person.validators.should.be.an('array');
20
+ });
21
+ return describe('#()', function() {
22
+ describe('validators instatiation', function() {
23
+ it('should instantiate validators with prefix validates_', function() {
24
+ var validator;
25
+
26
+ person = model.call({
27
+ resource: 'person',
28
+ name: String,
29
+ validates_presence_of: 'name'
30
+ });
31
+ person.validators.should.not.be.empty;
32
+ validator = person.validators[0];
33
+ return validator.should.have.property('attribute_name', 'name');
34
+ });
35
+ return it('should instantiate validators with in the key validates');
36
+ });
37
+ describe('#validate_attribute', function() {
38
+ beforeEach(function() {
39
+ person.validators.length = 0;
40
+ return person = model.call({
41
+ resource: 'person',
42
+ name: String,
43
+ validates_presence_of: 'name'
44
+ });
45
+ });
46
+ return it('should add error messages for the validated attribute', function() {
47
+ var arthur;
48
+
49
+ arthur = person({
50
+ name: null
51
+ });
52
+ arthur.validate_attribute('name');
53
+ arthur.errors.length.should.be.eq(1);
54
+ return arthur.errors.messages.should.have.property('name');
55
+ });
56
+ });
57
+ return describe('.valid', function() {
58
+ person = null;
59
+ beforeEach(function() {
60
+ person.validators.length = 0;
61
+ return person = model.call({
62
+ resource: 'person',
63
+ name: String,
64
+ validates_presence_of: 'name'
65
+ });
66
+ });
67
+ it('should be true when valid', function() {
68
+ var arthur;
69
+
70
+ arthur = person({
71
+ name: "Arthur"
72
+ });
73
+ arthur.should.have.property('valid');
74
+ arthur.valid.should.be["true"];
75
+ return arthur.errors.length.should.be.eq(0);
76
+ });
77
+ it('should exist as read only property', function() {
78
+ var arthur;
79
+
80
+ arthur = person({
81
+ name: "Arthur"
82
+ });
83
+ return expect(function() {
84
+ return arthur.valid = false;
85
+ }).to["throw"](Error);
86
+ });
87
+ it('should validate record', function() {
88
+ var anonymous;
89
+
90
+ anonymous = person({
91
+ name: null
92
+ });
93
+ anonymous.valid.should.be["false"];
94
+ return anonymous.errors.length.should.be.eq(1);
95
+ });
96
+ return it('should not validate record util it changes', function() {
97
+ var anonymous, validation;
98
+
99
+ anonymous = person({
100
+ name: null
101
+ });
102
+ anonymous.valid.should.be["false"];
103
+ anonymous.errors.length.should.be.eq(1);
104
+ validation = anonymous.validation;
105
+ anonymous.validate().should.be.eq(validation);
106
+ anonymous.dirty = true;
107
+ return anonymous.validate().should.not.be.eq(validation);
108
+ });
109
+ });
110
+ });
111
+ });
@@ -0,0 +1,43 @@
1
+ var root;
2
+
3
+ root = typeof exports !== "undefined" && exports !== null ? exports : window;
4
+
5
+ require('indemma/lib/record/validatable');
6
+
7
+ describe('model #() validates_associated', function() {
8
+ return describe('basic usage', function() {
9
+ var address, model, person;
10
+
11
+ model = root.model;
12
+ person = address = null;
13
+ beforeEach(function() {
14
+ address = model.call({
15
+ resource: 'address',
16
+ street: String,
17
+ validates_presence_of: 'street'
18
+ });
19
+ return person = model.call({
20
+ resource: 'person',
21
+ has_one: 'address',
22
+ validates_associated: 'address'
23
+ });
24
+ });
25
+ afterEach(function() {
26
+ person.validators.length = 0;
27
+ return address.validators.length = 0;
28
+ });
29
+ return describe('#validate', function() {
30
+ return it('should add error to record when fields does not match', function() {
31
+ var arthur;
32
+
33
+ arthur = person({});
34
+ arthur.build_address({
35
+ street: null
36
+ });
37
+ arthur.valid;
38
+ arthur.errors.messages.should.have.deep.property('address', 'O registro associado address não é válido.');
39
+ return arthur.address.errors.messages.should.have.deep.property('street', 'O campo street não pode ficar em branco.');
40
+ });
41
+ });
42
+ });
43
+ });
@@ -0,0 +1,36 @@
1
+ var root;
2
+
3
+ root = typeof exports !== "undefined" && exports !== null ? exports : window;
4
+
5
+ require('indemma/lib/record/validatable');
6
+
7
+ describe('model #() validates_confirmation_of', function() {
8
+ return describe('basic usage', function() {
9
+ var model, person;
10
+
11
+ model = root.model;
12
+ person = null;
13
+ beforeEach(function() {
14
+ return person = model.call({
15
+ resource: 'person',
16
+ password: String,
17
+ validates_confirmation_of: 'password'
18
+ });
19
+ });
20
+ afterEach(function() {
21
+ return person.validators.length = 0;
22
+ });
23
+ return describe('#validate', function() {
24
+ return it('should add error to record when fields does not match', function() {
25
+ var arthur;
26
+
27
+ arthur = person({
28
+ password: "domo",
29
+ password_confirmation: "kun"
30
+ });
31
+ arthur.valid;
32
+ return arthur.errors.messages.should.have.deep.property('password', "O campo password não está diacordo com a confirmação password_confirmation.");
33
+ });
34
+ });
35
+ });
36
+ });
@@ -0,0 +1,35 @@
1
+ var root;
2
+
3
+ root = typeof exports !== "undefined" && exports !== null ? exports : window;
4
+
5
+ require('indemma/lib/record/validatable');
6
+
7
+ describe('model #() validates_cpf_format', function() {
8
+ return describe('basic usage', function() {
9
+ var model, person;
10
+
11
+ model = root.model;
12
+ person = null;
13
+ beforeEach(function() {
14
+ return person = model.call({
15
+ resource: 'person',
16
+ cpf: String,
17
+ validates_cpf_format: 'cpf'
18
+ });
19
+ });
20
+ afterEach(function() {
21
+ return person != null ? person.validators.length = 0 : void 0;
22
+ });
23
+ return describe('#validate', function() {
24
+ return it('should add error to record when fields is in invalid format', function() {
25
+ var arthur;
26
+
27
+ arthur = person({
28
+ cpf: '871.943.417-00'
29
+ });
30
+ arthur.valid;
31
+ return arthur.errors.messages.should.have.deep.property('cpf', "O campo cpf não está válido.");
32
+ });
33
+ });
34
+ });
35
+ });
@@ -0,0 +1,28 @@
1
+ var root;
2
+
3
+ root = typeof exports !== "undefined" && exports !== null ? exports : window;
4
+
5
+ require('indemma/lib/record/validatable');
6
+
7
+ describe('model #() validates presence of', function() {
8
+ return describe('basic usage', function() {
9
+ var model, person;
10
+
11
+ model = root.model;
12
+ person = null;
13
+ beforeEach(function() {
14
+ return person = model.call({
15
+ resource: 'person',
16
+ name: String,
17
+ belongs_to: 'corporation',
18
+ validates_presence_of: 'name'
19
+ });
20
+ });
21
+ afterEach(function() {
22
+ return person.validators.length = 0;
23
+ });
24
+ return describe('#validate', function() {
25
+ return it('should add error to record when required field is empty (null, undefined or \'\')');
26
+ });
27
+ });
28
+ });
@@ -0,0 +1,86 @@
1
+ var root;
2
+
3
+ root = typeof exports !== "undefined" && exports !== null ? exports : window;
4
+
5
+ require('indemma/lib/record/validatable');
6
+
7
+ describe('model #() validates_remotely', function() {
8
+ var arthur, model, person, request;
9
+
10
+ model = root.model;
11
+ request = arthur = person = null;
12
+ describe('basic usage', function() {
13
+ beforeEach(function() {
14
+ person = model.call({
15
+ resource: 'person',
16
+ name: String,
17
+ validates_remotely: 'name'
18
+ });
19
+ return arthur = person({
20
+ name: "Arthur Dent"
21
+ });
22
+ });
23
+ afterEach(function() {
24
+ return person != null ? person.validators.length = 0 : void 0;
25
+ });
26
+ return describe('#validate', function() {
27
+ beforeEach(function() {
28
+ request = jQuery.Deferred();
29
+ return sinon.stub(jQuery, "ajax").returns(request);
30
+ });
31
+ afterEach(function() {
32
+ return jQuery.ajax.restore();
33
+ });
34
+ it('should send paramenters accordingly', function() {
35
+ arthur.validate();
36
+ jQuery.ajax.called.should.be["true"];
37
+ return jQuery.ajax.calledWithMatch({
38
+ url: '/persons/validate',
39
+ data: {
40
+ person: {
41
+ name: 'Arthur Dent'
42
+ }
43
+ }
44
+ }).should.be["true"];
45
+ });
46
+ return it('should add errors to record when request responds with errors', function() {
47
+ arthur.validate();
48
+ request.resolveWith(arthur, [
49
+ {
50
+ name: ['The name should be Marvin!', 'The name should be in lowercase!']
51
+ }
52
+ ]);
53
+ arthur.errors.length.should.be.eq(2);
54
+ return arthur.errors.messages.name.should.exist;
55
+ });
56
+ });
57
+ });
58
+ return describe('with options usage', function() {
59
+ beforeEach(function() {
60
+ if (person != null) {
61
+ person.validators.length = 0;
62
+ }
63
+ person = model.call({
64
+ resource: 'person',
65
+ name: String,
66
+ validates_remotely: 'name'
67
+ });
68
+ return arthur = person({
69
+ name: "Arthur Dent"
70
+ });
71
+ });
72
+ return describe('#validate', function() {
73
+ beforeEach(function() {
74
+ request = jQuery.Deferred();
75
+ return sinon.stub(jQuery, "ajax").returns(request);
76
+ });
77
+ afterEach(function() {
78
+ return jQuery.ajax.restore();
79
+ });
80
+ return it('should make ajax call', function() {
81
+ arthur.validate();
82
+ return jQuery.ajax.called.should.be["true"];
83
+ });
84
+ });
85
+ });
86
+ });
@@ -0,0 +1,48 @@
1
+ var root;
2
+
3
+ root = typeof exports !== "undefined" && exports !== null ? exports : window;
4
+
5
+ require('indemma/lib/record/validatable');
6
+
7
+ describe('model #() validates type of', function() {
8
+ return describe('basic usage', function() {
9
+ var model, person;
10
+
11
+ model = root.model;
12
+ person = null;
13
+ beforeEach(function() {
14
+ return person = model.call({
15
+ resource: 'person',
16
+ name: String,
17
+ phone: Phone,
18
+ validates_type_of: ['name', 'phone']
19
+ });
20
+ });
21
+ afterEach(function() {
22
+ return person.validators.length = 0;
23
+ });
24
+ return describe('#validate', function() {
25
+ it('should use Phone#validate to find out if attribute is valid');
26
+ it('should add error to record when phone typed attribute has an non valid phone value', function() {
27
+ var arthur;
28
+
29
+ arthur = person({
30
+ phone: new Phone('batata')
31
+ });
32
+ arthur.valid.should.be["false"];
33
+ arthur.errors.messages.should.have.property('phone');
34
+ return expect(arthur.errors.messages.phone).to.match(/não está válido/);
35
+ });
36
+ return it('should throw error to when phone typed attribute has an non phone value', function() {
37
+ var arthur;
38
+
39
+ arthur = person({
40
+ phone: 'batata'
41
+ });
42
+ return expect(function() {
43
+ return arthur.valid;
44
+ }).to["throw"](/invalid attribute value type/i);
45
+ });
46
+ });
47
+ });
48
+ });
@@ -0,0 +1,37 @@
1
+ var root;
2
+
3
+ root = typeof exports !== "undefined" && exports !== null ? exports : window;
4
+
5
+ describe('record', function() {
6
+ var record;
7
+
8
+ record = root.record;
9
+ return it('should create a record', function() {
10
+ var arthur;
11
+
12
+ arthur = record.call({
13
+ resource: 'person'
14
+ });
15
+ return arthur.should.be.object;
16
+ });
17
+ });
18
+
19
+ describe('model', function() {
20
+ var model;
21
+
22
+ model = root.model;
23
+ return describe('#()', function() {
24
+ xit('should throw exception if no resource is passed');
25
+ return it('should create a record factory', function() {
26
+ var john, person;
27
+
28
+ person = model.call({
29
+ resource: 'person'
30
+ });
31
+ person.should.be.object;
32
+ john = person();
33
+ john.should.be.object;
34
+ return john.resource.should.have.property('name', 'person');
35
+ });
36
+ });
37
+ });
@@ -0,0 +1,11 @@
1
+ var chai, indemma, root;
2
+
3
+ root = typeof exports !== "undefined" && exports !== null ? exports : window;
4
+
5
+ indemma = require('indemma');
6
+
7
+ chai = require('chaijs-chai');
8
+
9
+ root.expect = chai.expect;
10
+
11
+ root.should = chai.should();