ende 0.1.14 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
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,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,164 @@
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 'restfulable', ->
11
+
12
+ describe 'when included', ->
13
+ it 'sets te restufulable loaded flag on model', ->
14
+ model.restfulable.should.be.true
15
+
16
+ # it 'adds save methods to records'
17
+
18
+ describe 'record', ->
19
+ arthur = null
20
+
21
+ describe '#()', ->
22
+
23
+ beforeEach ->
24
+ arthur = record.call
25
+ resource: 'person'
26
+ name : 'Arthur Philip Dent'
27
+
28
+ arthur.dirty = true
29
+
30
+ describe '#save', ->
31
+ beforeEach -> sinon.stub(jQuery, "ajax").returns(jQuery.Deferred())
32
+ afterEach -> jQuery.ajax.restore()
33
+
34
+ it 'should send paramenters accordingly'
35
+
36
+ # TODO erase this test and implement the above test (should
37
+ # send paramenters accordingly)
38
+ it 'should make ajax call', ->
39
+ arthur.save()
40
+ jQuery.ajax.called.should.be.true
41
+
42
+ describe 'model' , ->
43
+ describe '#()', ->
44
+ describe '#json', ->
45
+ friend = person = null
46
+
47
+ beforeEach ->
48
+ person = model.call
49
+ resource: 'person'
50
+ has_many: 'friends'
51
+ nested_attributes: ['friends']
52
+ name: String
53
+
54
+ friend = model.call
55
+ resource: 'friend'
56
+ belongs_to: 'person'
57
+
58
+ describe '#assign_attributes', ->
59
+ friend = person = null
60
+
61
+ beforeEach ->
62
+ person = model.call
63
+ resource: 'person'
64
+ has_many: 'friends'
65
+ name: String
66
+
67
+ friend = model.call
68
+ resource: 'friend'
69
+ belongs_to: 'person'
70
+
71
+ # TODO implement setter on has many association and move this code to there
72
+ it 'assigns associations properly', ->
73
+ arthur = person name: 'Arthur Dent'
74
+ ford = friend name: 'Ford Perfect'
75
+ marvin = friend name: 'Marvin'
76
+ attributes = friends: [ford, marvin]
77
+
78
+ arthur.assign_attributes attributes
79
+
80
+ search_record = (association, search) ->
81
+ search = JSON.stringify search.json()
82
+ for associated in association
83
+ associated = JSON.stringify(associated.json())
84
+ return true if associated == search
85
+
86
+ false
87
+
88
+ search_record(arthur.friends, ford).should.be.eq.true
89
+ search_record(arthur.friends, arthur).should.be.eq.true
90
+
91
+
92
+ describe 'with singular resource', ->
93
+ describe '#create', ->
94
+
95
+ it 'should return promises'
96
+ it 'should return models when promise is resolved'
97
+
98
+ describe 'with plural resource', ->
99
+
100
+ describe '#create', ->
101
+ deferred = promise = person = null
102
+
103
+ beforeEach ->
104
+ person = model.call resource: 'person'
105
+ deferred = jQuery.Deferred()
106
+ deferred.resolveWith person(name: 'Arthur'), [_id: 1]
107
+ sinon.stub(jQuery, "ajax").returns(deferred)
108
+ promise = person.create {name: 'Arthur'}, {name: 'Ford'}
109
+
110
+ afterEach -> jQuery.ajax.restore()
111
+
112
+ # TODO move this test to restful test
113
+ it 'should return a promise', (done) ->
114
+ promise.done.should.be.function
115
+ promise.state().should.be.eq 'resolved'
116
+ promise.done(-> done()).should.be.eq 'resolved'
117
+
118
+
119
+ it 'should return models when promise is resolved', (done) ->
120
+ # Will be called once for each saved record
121
+ created = ->
122
+ @name.should.be.eq 'Arthur'
123
+ done()
124
+
125
+ person.create {name: 'Arthur'}, {name: 'Ford'}, created
126
+
127
+ it 'should optionally accept create callback', (done) ->
128
+ promise = person.create {name: 'Arthur'}, {name: 'Ford'}
129
+ promise.done.should.be.function
130
+ promise.done -> done()
131
+ promise.state().should.be.eq 'resolved'
132
+
133
+
134
+ it 'should create record when only callback is passed', (done) ->
135
+ person.create -> done()
136
+ jQuery.ajax.callCount.should.be.eq 3 # 2 is counts is from the beforeEach
137
+
138
+ it 'should throw exception when nothing is passed', () ->
139
+ expect(person.create).to.throw TypeError
140
+
141
+ it 'should make ajax calls', ->
142
+ jQuery.ajax.callCount.should.be.eq 2
143
+
144
+ describe '#destroy', ->
145
+ describe 'with plural resource', ->
146
+ arthur = person = deferred = null
147
+
148
+ beforeEach ->
149
+ person = model.call resource: 'person'
150
+ deferred = jQuery.Deferred()
151
+ deferred.resolveWith person(name: 'Arthur'), [id: 1]
152
+ sinon.stub(jQuery, "ajax").returns(deferred)
153
+ arthur = person name: 'Arthur', id: 1
154
+
155
+ afterEach -> jQuery.ajax.restore()
156
+
157
+ it "throw exception when record has no id", ->
158
+ delete arthur.id
159
+ expect(arthur.destroy).to.throw Error
160
+
161
+
162
+ it "should make ajax calls", ->
163
+ arthur.destroy()
164
+ jQuery.ajax.callCount.should.be.eq 1
@@ -0,0 +1,181 @@
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
+ resource: 'person'
31
+
32
+ it 'should add scope methods to model', ->
33
+ person.none.should.be.function
34
+
35
+ it 'should generate scope methods based on model definition', ->
36
+ person.hetero.should.be.function
37
+
38
+ describe '#none', ->
39
+ it 'should return empty response on fetch calls', (done) ->
40
+ # TODO implement getter for none property!
41
+ person.none().fetch null, (people) ->
42
+ people.length.should.be.empty
43
+ done()
44
+
45
+
46
+ describe 'scope', ->
47
+
48
+ describe '#(name, type)', ->
49
+
50
+ it 'should add scope methods to model', ->
51
+ person.scope 'bissexual', Boolean
52
+ person.bissexual.should.be.function
53
+
54
+ describe '#{generated_scope}', ->
55
+ deferred = null
56
+
57
+ beforeEach ->
58
+ deferred = jQuery.Deferred()
59
+ sinon.stub(jQuery, "ajax").returns deferred
60
+ person.scope.clear()
61
+
62
+ afterEach -> jQuery.ajax.restore()
63
+
64
+ describe '#all', ->
65
+ deferred = promises = person = null
66
+
67
+ it 'should return models when promise is resolved', (done) ->
68
+
69
+ # Will be called once for each saved record
70
+ fetched = (people) ->
71
+ people.should.be.array
72
+ people[0].name.should.be.string
73
+ done()
74
+
75
+ person.all fetched
76
+
77
+ deferred.resolveWith person, [[{name: 'Arthur'}, {name: 'Ford'}]]
78
+ jQuery.ajax.callCount.should.be.eq 1
79
+
80
+
81
+ describe 'when array', ->
82
+ it 'should acumulate data in scope object', ->
83
+ person.by_type()
84
+ person.scope.data.by_type.should.be.a 'array'
85
+
86
+ it 'should override data throught parameters', ->
87
+ person.by_type 1, 2, 3
88
+ person.scope.data.by_type.should.contain 1, 2, 3
89
+
90
+ it 'should use default value'
91
+ it 'should allow scope chaining'
92
+
93
+ describe 'xhr request', ->
94
+
95
+ it 'should build correct url', ->
96
+ person.by_type(1, 3, 4).fetch()
97
+
98
+ settings = jQuery.ajax.firstCall.args[0]
99
+
100
+ settings.should.have.property 'data'
101
+ settings.data.should.have.property 'by_type'
102
+ settings.data.by_type.should.include 1, 3, 4
103
+
104
+ it 'should make call', ->
105
+ person.by_type(1, 3, 4).fetch()
106
+ jQuery.ajax.callCount.should.be.eq 1
107
+
108
+
109
+ describe 'when boolean', ->
110
+
111
+ it 'should acumulate data in scope object', ->
112
+ person.hetero()
113
+ person.scope.data.hetero.should.be.eq true
114
+
115
+ it 'should override data throught parameters', ->
116
+ person.hetero false
117
+ person.scope.data.hetero.should.be.eq false
118
+
119
+ it 'should allow scope chaining'
120
+
121
+ it 'should make ajax call', ->
122
+ person.hetero().fetch()
123
+ jQuery.ajax.callCount.should.be.eq 1
124
+
125
+ describe '#{generated_association}', ->
126
+
127
+ describe 'of type belongs_to', ->
128
+ towel = null
129
+
130
+ beforeEach ->
131
+ person = model.call
132
+ $hetero: true
133
+ $by_type: []
134
+ resource: 'person'
135
+
136
+ towel = model.call
137
+ resource: 'towel'
138
+ material: 'cotton'
139
+ belongs_to: 'person'
140
+
141
+
142
+ describe '#{generated_scope}', ->
143
+
144
+ it 'can be called on association', ->
145
+ soft_towel = towel
146
+ material: 'silicon microfiber'
147
+
148
+ soft_towel.build_person()
149
+
150
+ expect(soft_towel.person).to.respondTo 'hetero'
151
+
152
+ describe 'of type has_many', ->
153
+ arthur = towel = null
154
+
155
+ beforeEach ->
156
+ person = model.call
157
+ $hetero: true
158
+ $by_type: []
159
+ resource: 'person'
160
+ has_many: 'towels'
161
+
162
+ towel = model.call
163
+ $by_material: []
164
+ resource: 'towel'
165
+ material: 'cotton'
166
+ belongs_to: 'person'
167
+
168
+ arthur = person
169
+ name: 'Arthur'
170
+
171
+
172
+
173
+ describe '#{generated_scope}', ->
174
+
175
+ it 'can be called on association', ->
176
+ expect(arthur.towels).to.respondTo 'by_material'
177
+
178
+ it 'should be serializable into paramenters', ->
179
+ arthur.towels.by_material 'cotton', 'microfiber'
180
+ query_string = decodeURIComponent(jQuery.param arthur.towels.scope.data)
181
+ query_string.should.be.eq 'by_material[]=cotton&by_material[]=microfiber'
@@ -0,0 +1,19 @@
1
+ root = exports ? window
2
+
3
+ require 'indemma/lib/record/translationable'
4
+
5
+ describe 'model', ->
6
+ model = root.model
7
+ person = null
8
+
9
+ beforeEach ->
10
+ person = model.call
11
+ resource : 'person'
12
+ name: String
13
+ translation:
14
+ attributes:
15
+ name: 'Batata'
16
+
17
+ describe '#human_attribute_name', ->
18
+ it 'should return the translated attribute name', ->
19
+ person.human_attribute_name('name').should.be.eq 'Batata'
@@ -0,0 +1,100 @@
1
+ root = exports ? window
2
+
3
+ require 'indemma/lib/record/validatable'
4
+
5
+ describe 'model', ->
6
+ model = root.model
7
+ person = corporation = null
8
+
9
+ beforeEach ->
10
+ person = model.call resource : 'person'
11
+
12
+ it 'should store validators', ->
13
+ person.should.have.property 'validators'
14
+ person.validators.should.be.an 'array'
15
+
16
+ describe '#()', ->
17
+
18
+ describe 'validators instatiation', ->
19
+
20
+ it 'should instantiate validators with prefix validates_', ->
21
+ person = model.call
22
+ resource : 'person'
23
+ name : String
24
+ validates_presence_of: 'name'
25
+
26
+ person.validators.should.not.be.empty
27
+ validator = person.validators[0]
28
+ validator.should.have.property 'attribute_name', 'name'
29
+
30
+ it 'should instantiate validators with in the key validates'
31
+ #person = model.call
32
+ # resource : 'person'
33
+ # name : String
34
+ # validates : {name: {presence: true} }
35
+
36
+ #person.validators.should.have.key 'name'
37
+
38
+ describe '#validate_attribute', ->
39
+
40
+ beforeEach ->
41
+ # TODO implement better model redefinition pattern
42
+ person.validators.length = 0
43
+
44
+ person = model.call
45
+ resource : 'person'
46
+ name : String
47
+ validates_presence_of: 'name'
48
+
49
+ it 'should add error messages for the validated attribute', ->
50
+ arthur = person name: null
51
+
52
+ arthur.validate_attribute 'name'
53
+
54
+ arthur.errors.length.should.be.eq 1
55
+ arthur.errors.messages.should.have.property 'name'
56
+
57
+ describe '.valid', ->
58
+ person = null
59
+
60
+ beforeEach ->
61
+ # TODO implement better model redefinition pattern
62
+ person.validators.length = 0
63
+
64
+ person = model.call
65
+ resource : 'person'
66
+ name : String
67
+ validates_presence_of: 'name'
68
+
69
+ # TODO more specific .valid test functionality
70
+ it 'should be true when valid', ->
71
+ arthur = person name: "Arthur"
72
+
73
+ arthur.should.have.property 'valid'
74
+ arthur.valid.should.be.true
75
+ arthur.errors.length.should.be.eq 0
76
+
77
+
78
+ it 'should exist as read only property', ->
79
+ arthur = person name: "Arthur"
80
+ expect(-> arthur.valid = false).to.throw Error
81
+
82
+ it 'should validate record', ->
83
+ anonymous = person name: null
84
+ anonymous.valid.should.be.false
85
+ anonymous.errors.length.should.be.eq 1
86
+
87
+ it 'should not validate record util it changes', ->
88
+ anonymous = person name: null
89
+
90
+ anonymous.valid.should.be.false
91
+ anonymous.errors.length.should.be.eq 1
92
+
93
+ validation = anonymous.validation
94
+ # We expect it to not instanitante new validation deferred
95
+ anonymous.validate().should.be.eq validation
96
+
97
+ # Record for some reason changed
98
+ anonymous.dirty = true
99
+ # We expect it to instanitante new validation deferred
100
+ anonymous.validate().should.not.be.eq validation
@@ -0,0 +1,35 @@
1
+ root = exports ? window
2
+
3
+ require 'indemma/lib/record/validatable'
4
+
5
+ describe 'model #() validates_associated', ->
6
+
7
+ describe 'basic usage', ->
8
+ model = root.model
9
+ person = address = null
10
+
11
+ beforeEach ->
12
+ address = model.call
13
+ resource : 'address'
14
+ street : String
15
+ validates_presence_of: 'street'
16
+
17
+ person = model.call
18
+ resource : 'person'
19
+ has_one : 'address'
20
+ validates_associated: 'address'
21
+
22
+ afterEach ->
23
+ person.validators.length = 0
24
+ address.validators.length = 0
25
+
26
+ describe '#validate', ->
27
+
28
+ it 'should add error to record when fields does not match', ->
29
+ arthur = person {}
30
+ arthur.build_address street: null
31
+
32
+ arthur.valid
33
+
34
+ arthur.errors.messages.should.have.deep.property 'address', 'O registro associado address não é válido.'
35
+ arthur.address.errors.messages.should.have.deep.property 'street', 'O campo street não pode ficar em branco.'
@@ -0,0 +1,25 @@
1
+ root = exports ? window
2
+
3
+ require 'indemma/lib/record/validatable'
4
+
5
+ describe 'model #() validates_confirmation_of', ->
6
+
7
+ describe 'basic usage', ->
8
+ model = root.model
9
+ person = null
10
+
11
+ beforeEach ->
12
+ person = model.call
13
+ resource : 'person'
14
+ password : String
15
+ validates_confirmation_of: 'password'
16
+
17
+ afterEach ->
18
+ person.validators.length = 0
19
+
20
+ describe '#validate', ->
21
+
22
+ it 'should add error to record when fields does not match', ->
23
+ arthur = person password: "domo", password_confirmation: "kun"
24
+ arthur.valid
25
+ arthur.errors.messages.should.have.deep.property 'password', "O campo password não está diacordo com a confirmação password_confirmation."
@@ -0,0 +1,28 @@
1
+ root = exports ? window
2
+
3
+ require 'indemma/lib/record/validatable'
4
+
5
+ describe 'model #() validates_cpf_format', ->
6
+
7
+ describe 'basic usage', ->
8
+ model = root.model
9
+ person = null
10
+
11
+ beforeEach ->
12
+ person = model.call
13
+ resource : 'person'
14
+ cpf : String
15
+ validates_cpf_format: 'cpf'
16
+
17
+ afterEach ->
18
+ # Clear validators from resource
19
+ person?.validators.length = 0
20
+
21
+ describe '#validate', ->
22
+
23
+ it 'should add error to record when fields is in invalid format', ->
24
+ arthur = person cpf: '871.943.417-00'
25
+ arthur.valid
26
+
27
+ # TODO figure out why the heck the validators aren't being reset
28
+ arthur.errors.messages.should.have.deep.property 'cpf', "O campo cpf não está válido."
@@ -0,0 +1,24 @@
1
+ root = exports ? window
2
+
3
+ require 'indemma/lib/record/validatable'
4
+
5
+ describe 'model #() validates presence of', ->
6
+
7
+ describe 'basic usage', ->
8
+ model = root.model
9
+ person = null
10
+
11
+ beforeEach ->
12
+ person = model.call
13
+ resource : 'person'
14
+ name : String
15
+ belongs_to: 'corporation'
16
+ validates_presence_of: 'name'
17
+
18
+ afterEach ->
19
+ person.validators.length = 0
20
+
21
+ describe '#validate', ->
22
+
23
+ it 'should add error to record when required field is empty (null, undefined or \'\')'
24
+
@@ -0,0 +1,72 @@
1
+ root = exports ? window
2
+
3
+ require 'indemma/lib/record/validatable'
4
+
5
+ describe 'model #() validates_remotely', ->
6
+ model = root.model
7
+ request = arthur = person = null
8
+
9
+ describe 'basic usage', ->
10
+
11
+ beforeEach ->
12
+ person = model.call
13
+ resource : 'person'
14
+ name : String
15
+ validates_remotely: 'name'
16
+
17
+ arthur = person name: "Arthur Dent"
18
+
19
+ afterEach ->
20
+ person?.validators.length = 0
21
+
22
+ describe '#validate', ->
23
+
24
+ beforeEach ->
25
+ request = jQuery.Deferred()
26
+ sinon.stub(jQuery, "ajax").returns(request)
27
+
28
+ afterEach -> jQuery.ajax.restore()
29
+
30
+ it 'should send paramenters accordingly', ->
31
+ arthur.validate()
32
+
33
+ jQuery.ajax.called.should.be.true
34
+ jQuery.ajax.calledWithMatch(
35
+ url: '/persons/validate'
36
+ data:
37
+ person:
38
+ name: 'Arthur Dent'
39
+ ).should.be.true
40
+
41
+
42
+ it 'should add errors to record when request responds with errors', ->
43
+ arthur.validate()
44
+ request.resolveWith arthur,
45
+ [name: ['The name should be Marvin!', 'The name should be in lowercase!']]
46
+
47
+ arthur.errors.length.should.be.eq 2
48
+ arthur.errors.messages.name.should.exist
49
+
50
+ describe 'with options usage', ->
51
+
52
+ beforeEach ->
53
+ person?.validators.length = 0
54
+
55
+ person = model.call
56
+ resource : 'person'
57
+ name : String
58
+ validates_remotely: 'name'
59
+
60
+ arthur = person name: "Arthur Dent"
61
+
62
+ describe '#validate', ->
63
+
64
+ beforeEach ->
65
+ request = jQuery.Deferred()
66
+ sinon.stub(jQuery, "ajax").returns(request)
67
+
68
+ afterEach -> jQuery.ajax.restore()
69
+
70
+ it 'should make ajax call', ->
71
+ arthur.validate()
72
+ jQuery.ajax.called.should.be.true