ende 0.2.9 → 0.2.10
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.
- checksums.yaml +4 -4
- data/lib/assets/javascripts/aura/extensions/devise.js.coffee +2 -2
- data/lib/assets/javascripts/widgets/viewer/main.js.coffee +1 -1
- data/lib/ende/version.rb +1 -1
- data/vendor/assets/components/build.js +638 -133
- data/vendor/components/indefinido-indemma/.gitignore +14 -0
- data/vendor/components/indefinido-indemma/.gitignore~ +2 -0
- data/vendor/components/indefinido-indemma/.ruby-gemset +1 -0
- data/vendor/components/indefinido-indemma/.ruby-version +1 -0
- data/vendor/components/indefinido-indemma/Gemfile +13 -0
- data/vendor/components/indefinido-indemma/Guardfile +39 -0
- data/vendor/components/indefinido-indemma/History.md +0 -0
- data/vendor/components/indefinido-indemma/Readme.md +447 -0
- data/vendor/components/indefinido-indemma/build/development.js +340 -0
- data/vendor/components/indefinido-indemma/build/release.js +22039 -0
- data/vendor/components/indefinido-indemma/build/test.js +22039 -0
- data/vendor/components/indefinido-indemma/component.json +7 -3
- data/vendor/components/indefinido-indemma/components/chaijs-assertion-error/component.json +18 -0
- data/vendor/components/indefinido-indemma/components/chaijs-assertion-error/index.js +110 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/component.json +47 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/index.js +1 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/assertion.js +130 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/core/assertions.js +1270 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/interface/assert.js +1080 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/interface/expect.js +12 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/interface/should.js +76 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/addChainableMethod.js +94 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/addMethod.js +37 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/addProperty.js +40 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/eql.js +129 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/flag.js +32 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/getActual.js +19 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/getEnumerableProperties.js +25 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/getMessage.js +49 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/getName.js +20 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/getPathValue.js +102 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/getProperties.js +35 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/index.js +108 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/inspect.js +320 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/objDisplay.js +48 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/overwriteMethod.js +51 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/overwriteProperty.js +54 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/test.js +26 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/transferFlags.js +44 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai/utils/type.js +45 -0
- data/vendor/components/indefinido-indemma/components/chaijs-chai/lib/chai.js +80 -0
- data/vendor/components/indefinido-indemma/components/component-bind/component.json +14 -0
- data/vendor/components/indefinido-indemma/components/component-bind/index.js +24 -0
- data/vendor/components/indefinido-indemma/components/component-jquery/component.json +14 -0
- data/vendor/components/indefinido-indemma/components/component-jquery/index.js +9601 -0
- data/vendor/components/indefinido-indemma/components/component-type/component.json +18 -0
- data/vendor/components/indefinido-indemma/components/component-type/index.js +32 -0
- data/vendor/components/indefinido-indemma/components/indefinido-advisable/component.json +21 -0
- data/vendor/components/indefinido-indemma/components/indefinido-advisable/index.js +1 -0
- data/vendor/components/indefinido-indemma/components/indefinido-advisable/lib/advisable.js +60 -0
- data/vendor/components/indefinido-indemma/components/indefinido-observable/component.json +25 -0
- data/vendor/components/indefinido-indemma/components/indefinido-observable/components/cjohansen-sinon/sinon.js +4290 -0
- data/vendor/components/indefinido-indemma/components/indefinido-observable/index.js +1 -0
- data/vendor/components/indefinido-indemma/components/indefinido-observable/lib/adapters/rivets.js +26 -0
- data/vendor/components/indefinido-indemma/components/indefinido-observable/lib/observable.js +323 -0
- data/vendor/components/indefinido-indemma/components/indefinido-observable/vendor/shims/accessors-legacy.js +92 -0
- data/vendor/components/indefinido-indemma/components/indefinido-observable/vendor/shims/accessors.js +173 -0
- data/vendor/components/indefinido-indemma/components/indefinido-observable/vendor/shims/array.indexOf.js +8 -0
- data/vendor/components/indefinido-indemma/components/indefinido-observable/vendor/shims/object.create.js +77 -0
- data/vendor/components/indefinido-indemma/components/kapit-observe-utils/component.json +13 -0
- data/vendor/components/indefinido-indemma/components/paulmillr-es6-shim/component.json +17 -0
- data/vendor/components/indefinido-indemma/components/paulmillr-es6-shim/es6-shim.js +996 -0
- data/vendor/components/indefinido-indemma/components/pluma-assimilate/component.json +25 -0
- data/vendor/components/indefinido-indemma/components/pluma-assimilate/dist/assimilate.js +127 -0
- data/vendor/components/indefinido-indemma/karma.conf.js +86 -0
- data/vendor/components/indefinido-indemma/lib/record/associable.js +229 -82
- data/vendor/components/indefinido-indemma/lib/record/errors.js +1 -0
- data/vendor/components/indefinido-indemma/lib/record/persistable.js +32 -0
- data/vendor/components/indefinido-indemma/lib/record/queryable.js +32 -0
- data/vendor/components/indefinido-indemma/lib/record/resource.js +12 -4
- data/vendor/components/indefinido-indemma/lib/record/rest.js +1 -1
- data/vendor/components/indefinido-indemma/lib/record/restfulable.js +38 -27
- data/vendor/components/indefinido-indemma/lib/record/scopable.js +15 -2
- data/vendor/components/indefinido-indemma/lib/record/storable.js +48 -0
- data/vendor/components/indefinido-indemma/lib/record/validatable.js +10 -5
- data/vendor/components/indefinido-indemma/lib/record/validations/cpf.js +1 -1
- data/vendor/components/indefinido-indemma/lib/record.js +15 -12
- data/vendor/components/indefinido-indemma/spec/record/associable_spec.js +137 -0
- data/vendor/components/indefinido-indemma/spec/record/persistable_spec.js +36 -0
- data/vendor/components/indefinido-indemma/spec/record/queryable_spec.js +33 -0
- data/vendor/components/indefinido-indemma/spec/record/resource_spec.js +93 -0
- data/vendor/components/indefinido-indemma/spec/record/rest_spec.js +32 -0
- data/vendor/components/indefinido-indemma/spec/record/restfulable_spec.js +288 -0
- data/vendor/components/indefinido-indemma/spec/record/scopable_spec.js +212 -0
- data/vendor/components/indefinido-indemma/spec/record/storable_spec.js +53 -0
- data/vendor/components/indefinido-indemma/spec/record/translationable.js +28 -0
- data/vendor/components/indefinido-indemma/spec/record/validatable_spec.js +111 -0
- data/vendor/components/indefinido-indemma/spec/record/validations/associated_spec.js +43 -0
- data/vendor/components/indefinido-indemma/spec/record/validations/confirmation_spec.js +36 -0
- data/vendor/components/indefinido-indemma/spec/record/validations/cpf_spec.js +35 -0
- data/vendor/components/indefinido-indemma/spec/record/validations/presence_spec.js +28 -0
- data/vendor/components/indefinido-indemma/spec/record/validations/remote_spec.js +87 -0
- data/vendor/components/indefinido-indemma/spec/record/validations/type_spec.js +48 -0
- data/vendor/components/indefinido-indemma/spec/record_spec.js +37 -0
- data/vendor/components/indefinido-indemma/spec/spec_helper.js +11 -0
- data/vendor/components/indefinido-indemma/spec/support/value_objects/phone.js +45 -0
- data/vendor/components/indefinido-indemma/src/lib/extensions/rivets.coffee +17 -0
- data/vendor/components/indefinido-indemma/src/lib/record/associable.coffee +342 -0
- data/vendor/components/indefinido-indemma/src/lib/record/errors.coffee +20 -0
- data/vendor/components/indefinido-indemma/src/lib/record/maid.coffee +16 -0
- data/vendor/components/indefinido-indemma/src/lib/record/persistable.coffee +27 -0
- data/vendor/components/indefinido-indemma/src/lib/record/queryable.coffee +29 -0
- data/vendor/components/indefinido-indemma/src/lib/record/resource.coffee +106 -0
- data/vendor/components/indefinido-indemma/src/lib/record/rest.coffee +28 -0
- data/vendor/components/indefinido-indemma/src/lib/record/restfulable.coffee +348 -0
- data/vendor/components/indefinido-indemma/src/lib/record/scopable.coffee +275 -0
- data/vendor/components/indefinido-indemma/src/lib/record/storable.coffee +46 -0
- data/vendor/components/indefinido-indemma/src/lib/record/translationable.coffee +18 -0
- data/vendor/components/indefinido-indemma/src/lib/record/validatable.coffee +217 -0
- data/vendor/components/indefinido-indemma/src/lib/record/validations/associated.coffee +32 -0
- data/vendor/components/indefinido-indemma/src/lib/record/validations/confirmation.coffee +19 -0
- data/vendor/components/indefinido-indemma/src/lib/record/validations/cpf.coffee +58 -0
- data/vendor/components/indefinido-indemma/src/lib/record/validations/presence.coffee +19 -0
- data/vendor/components/indefinido-indemma/src/lib/record/validations/remote.coffee +65 -0
- data/vendor/components/indefinido-indemma/src/lib/record/validations/type.coffee +32 -0
- data/vendor/components/indefinido-indemma/src/lib/record.coffee +136 -0
- data/vendor/components/indefinido-indemma/src/spec/record/associable_spec.coffee +130 -0
- data/vendor/components/indefinido-indemma/src/spec/record/persistable_spec.coffee +30 -0
- data/vendor/components/indefinido-indemma/src/spec/record/queryable_spec.coffee +27 -0
- data/vendor/components/indefinido-indemma/src/spec/record/resource_spec.coffee +69 -0
- data/vendor/components/indefinido-indemma/src/spec/record/rest_spec.coffee +22 -0
- data/vendor/components/indefinido-indemma/src/spec/record/restfulable_spec.coffee +207 -0
- data/vendor/components/indefinido-indemma/src/spec/record/scopable_spec.coffee +191 -0
- data/vendor/components/indefinido-indemma/src/spec/record/storable_spec.coffee +40 -0
- data/vendor/components/indefinido-indemma/src/spec/record/translationable.coffee +19 -0
- data/vendor/components/indefinido-indemma/src/spec/record/validatable_spec.coffee +100 -0
- data/vendor/components/indefinido-indemma/src/spec/record/validations/associated_spec.coffee +35 -0
- data/vendor/components/indefinido-indemma/src/spec/record/validations/confirmation_spec.coffee +25 -0
- data/vendor/components/indefinido-indemma/src/spec/record/validations/cpf_spec.coffee +28 -0
- data/vendor/components/indefinido-indemma/src/spec/record/validations/presence_spec.coffee +24 -0
- data/vendor/components/indefinido-indemma/src/spec/record/validations/remote_spec.coffee +74 -0
- data/vendor/components/indefinido-indemma/src/spec/record/validations/type_spec.coffee +33 -0
- data/vendor/components/indefinido-indemma/src/spec/record_spec.coffee +23 -0
- data/vendor/components/indefinido-indemma/src/spec/spec_helper.coffee +9 -0
- data/vendor/components/indefinido-indemma/src/spec/support/value_objects/phone.coffee +30 -0
- data/vendor/components/indefinido-indemma/vendor/object/mixin.js +196 -0
- data/vendor/components/indefinido-indemma/vendor/owl/pluralize.js +190 -0
- metadata +130 -2
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
root = exports ? window
|
|
2
|
+
|
|
3
|
+
storable = require 'indemma/lib/record/storable'
|
|
4
|
+
|
|
5
|
+
describe 'storable', ->
|
|
6
|
+
it 'should set the storable key', ->
|
|
7
|
+
model.should.have.property 'storable', true
|
|
8
|
+
|
|
9
|
+
beforeEach ->
|
|
10
|
+
@storage = storable()
|
|
11
|
+
|
|
12
|
+
describe "#store", ->
|
|
13
|
+
|
|
14
|
+
describe "write", ->
|
|
15
|
+
it "should write object on deep storage"
|
|
16
|
+
# storage.store 'users.1', data
|
|
17
|
+
|
|
18
|
+
it "should write object on storage", ->
|
|
19
|
+
data = name: 'Arthur Dent'
|
|
20
|
+
@storage.store '1', data
|
|
21
|
+
@storage.writes.should.be.eq 1
|
|
22
|
+
@storage.database['1'].should.be.eq data
|
|
23
|
+
|
|
24
|
+
it "should mark an object as sustained", ->
|
|
25
|
+
data = name: 'Arthur Dent'
|
|
26
|
+
@storage.store '1', data
|
|
27
|
+
data.should.have.property 'sustained', true
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
describe "read", ->
|
|
31
|
+
data = null
|
|
32
|
+
|
|
33
|
+
beforeEach ->
|
|
34
|
+
data = name: 'Arthur Dent'
|
|
35
|
+
@storage.store '1', data
|
|
36
|
+
|
|
37
|
+
it "should save object on storage", ->
|
|
38
|
+
@storage.store('1').should.be.eq data
|
|
39
|
+
|
|
40
|
+
it "should unmark an object as sustained"
|
|
@@ -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.'
|
data/vendor/components/indefinido-indemma/src/spec/record/validations/confirmation_spec.coffee
ADDED
|
@@ -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_confirmation', 'O campo password não está de acordo com o campo 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,74 @@
|
|
|
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
|
+
|
|
35
|
+
jQuery.ajax.calledWithMatch(
|
|
36
|
+
url: '/people/validate'
|
|
37
|
+
type: 'post'
|
|
38
|
+
data:
|
|
39
|
+
person:
|
|
40
|
+
name: 'Arthur Dent'
|
|
41
|
+
).should.be.true
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
it 'should add errors to record when request responds with errors', ->
|
|
45
|
+
arthur.validate()
|
|
46
|
+
request.resolveWith arthur,
|
|
47
|
+
[name: ['The name should be Marvin!', 'The name should be in lowercase!']]
|
|
48
|
+
|
|
49
|
+
arthur.errors.length.should.be.eq 2
|
|
50
|
+
arthur.errors.messages.name.should.exist
|
|
51
|
+
|
|
52
|
+
describe 'with options usage', ->
|
|
53
|
+
|
|
54
|
+
beforeEach ->
|
|
55
|
+
person?.validators.length = 0
|
|
56
|
+
|
|
57
|
+
person = model.call
|
|
58
|
+
resource : 'person'
|
|
59
|
+
name : String
|
|
60
|
+
validates_remotely: 'name'
|
|
61
|
+
|
|
62
|
+
arthur = person name: "Arthur Dent"
|
|
63
|
+
|
|
64
|
+
describe '#validate', ->
|
|
65
|
+
|
|
66
|
+
beforeEach ->
|
|
67
|
+
request = jQuery.Deferred()
|
|
68
|
+
sinon.stub(jQuery, "ajax").returns(request)
|
|
69
|
+
|
|
70
|
+
afterEach -> jQuery.ajax.restore()
|
|
71
|
+
|
|
72
|
+
it 'should make ajax call', ->
|
|
73
|
+
arthur.validate()
|
|
74
|
+
jQuery.ajax.called.should.be.true
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
root = exports ? window
|
|
2
|
+
|
|
3
|
+
require 'indemma/lib/record/validatable'
|
|
4
|
+
|
|
5
|
+
describe 'model #() validates type 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
|
+
phone : Phone
|
|
16
|
+
validates_type_of: ['name', 'phone']
|
|
17
|
+
|
|
18
|
+
afterEach ->
|
|
19
|
+
person.validators.length = 0
|
|
20
|
+
|
|
21
|
+
describe '#validate', ->
|
|
22
|
+
|
|
23
|
+
#it 'should use Phone#valid getter to find out if object is valid'
|
|
24
|
+
it 'should use Phone#validate to find out if attribute is valid'
|
|
25
|
+
it 'should add error to record when phone typed attribute has an non valid phone value', ->
|
|
26
|
+
arthur = person phone: new Phone 'batata'
|
|
27
|
+
arthur.valid.should.be.false
|
|
28
|
+
arthur.errors.messages.should.have.property 'phone'
|
|
29
|
+
expect(arthur.errors.messages.phone).to.match /não está válido/
|
|
30
|
+
|
|
31
|
+
it 'should throw error to when phone typed attribute has an non phone value', ->
|
|
32
|
+
arthur = person phone: 'batata'
|
|
33
|
+
expect( -> arthur.valid).to.throw /invalid attribute value type/i
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
root = exports ? window
|
|
2
|
+
|
|
3
|
+
describe 'record', ->
|
|
4
|
+
record = root.record
|
|
5
|
+
|
|
6
|
+
it 'should create a record', ->
|
|
7
|
+
arthur = record.call resource: 'person'
|
|
8
|
+
arthur.should.be.object
|
|
9
|
+
|
|
10
|
+
describe 'model', ->
|
|
11
|
+
model = root.model
|
|
12
|
+
|
|
13
|
+
describe '#()', ->
|
|
14
|
+
|
|
15
|
+
xit 'should throw exception if no resource is passed'
|
|
16
|
+
|
|
17
|
+
it 'should create a record factory', ->
|
|
18
|
+
person = model.call resource: 'person'
|
|
19
|
+
person.should.be.object
|
|
20
|
+
|
|
21
|
+
john = person()
|
|
22
|
+
john.should.be.object
|
|
23
|
+
john.resource.should.have.property 'name', 'person'
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# TODO locales support
|
|
2
|
+
class @Phone
|
|
3
|
+
|
|
4
|
+
constructor: (@area_code, @number) ->
|
|
5
|
+
{@area_code, @number} = @area_code if typeof @area_code == 'object'
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
# TODO parse argument types to validate value object domain
|
|
9
|
+
# constraints
|
|
10
|
+
|
|
11
|
+
unless @number
|
|
12
|
+
@number = @area_code
|
|
13
|
+
@area_code = null
|
|
14
|
+
|
|
15
|
+
Object.defineProperty @, 'valid', get: @validate
|
|
16
|
+
|
|
17
|
+
# TODO move type validation to indemma files
|
|
18
|
+
validate: -> @area_code? && @number?
|
|
19
|
+
|
|
20
|
+
toString: ->
|
|
21
|
+
formatted_number = @number.substr(0, 4) + '-' + @number.substr(4) if @number?
|
|
22
|
+
|
|
23
|
+
if @area_code?
|
|
24
|
+
"(#{@area_code}) #{formatted_number}"
|
|
25
|
+
else
|
|
26
|
+
formatted_number
|
|
27
|
+
|
|
28
|
+
toJSON: ->
|
|
29
|
+
area_code: @area_code
|
|
30
|
+
number: @number
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/*jslint browser: true, forin: true, plusplus: true, indent: 4 */
|
|
2
|
+
(function(Object, mixin) {
|
|
3
|
+
"use strict"; // happy linter ^_____^
|
|
4
|
+
|
|
5
|
+
/* <droppable> interesting code after line 110, here
|
|
6
|
+
* ad-hoc polyfill section for this purpose only
|
|
7
|
+
* never use these functions outside this closure ... like ...
|
|
8
|
+
ne*/var
|
|
9
|
+
|
|
10
|
+
// borrowed methods for unknown Objects
|
|
11
|
+
ObjectPrototype = Object.prototype,
|
|
12
|
+
|
|
13
|
+
lookupGetter = ObjectPrototype.__lookupGetter__,
|
|
14
|
+
lookupSetter = ObjectPrototype.__lookupSetter__,
|
|
15
|
+
defineGetter = ObjectPrototype.__defineGetter__,
|
|
16
|
+
defineSetter = ObjectPrototype.__defineSetter__,
|
|
17
|
+
has = ObjectPrototype.hasOwnProperty,
|
|
18
|
+
|
|
19
|
+
emptyArray = [],
|
|
20
|
+
// slice = emptyArray.slice,
|
|
21
|
+
|
|
22
|
+
// for IE < 9 and non IE5 yet browsers
|
|
23
|
+
goNative = true,
|
|
24
|
+
defineProperty = (function(defineProperty){
|
|
25
|
+
try{
|
|
26
|
+
return defineProperty && defineProperty({},'_',{value:1})._ && defineProperty;
|
|
27
|
+
} catch(IE8) {
|
|
28
|
+
goNative = false;
|
|
29
|
+
}
|
|
30
|
+
}(Object.defineProperty)) ||
|
|
31
|
+
function (o, k, d) {
|
|
32
|
+
var
|
|
33
|
+
get = d.get, // has.call(d, 'get') would be better but
|
|
34
|
+
set = d.set; // ES5 is just like this
|
|
35
|
+
if (get && defineGetter) {
|
|
36
|
+
defineGetter.call(o, k, get);
|
|
37
|
+
}
|
|
38
|
+
if (set && defineSetter) {
|
|
39
|
+
defineSetter.call(o, k, set);
|
|
40
|
+
}
|
|
41
|
+
if (!(get || set)) {
|
|
42
|
+
o[k] = d.value;
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
// for IE < 9 and non IE5 yet browsers
|
|
46
|
+
getOwnPropertyNames = (goNative && Object.getOwnPropertyNames) ||
|
|
47
|
+
(function () {
|
|
48
|
+
var
|
|
49
|
+
addHiddenOwnProperties = function (result) {
|
|
50
|
+
return result;
|
|
51
|
+
},
|
|
52
|
+
list = [],
|
|
53
|
+
key,
|
|
54
|
+
i,
|
|
55
|
+
length;
|
|
56
|
+
|
|
57
|
+
for (key in {valueOf: key}) {
|
|
58
|
+
list.push(key);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (!list.length) {
|
|
62
|
+
length = list.push(
|
|
63
|
+
'constructor',
|
|
64
|
+
'hasOwnProperty',
|
|
65
|
+
'isPrototypeOf',
|
|
66
|
+
'propertyIsEnumerable',
|
|
67
|
+
'toLocaleString',
|
|
68
|
+
'toString',
|
|
69
|
+
'valueOf'
|
|
70
|
+
) - 1;
|
|
71
|
+
addHiddenOwnProperties = function (result, o) {
|
|
72
|
+
for (i = 0; i < length; i++) {
|
|
73
|
+
key = list[i];
|
|
74
|
+
if (has.call(o, key)) {
|
|
75
|
+
result.push(key);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return result;
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return function (o) {
|
|
83
|
+
var
|
|
84
|
+
result = [],
|
|
85
|
+
key;
|
|
86
|
+
for (key in o) {
|
|
87
|
+
if (has.call(o, key)) {
|
|
88
|
+
result.push(key);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return addHiddenOwnProperties(result, o);
|
|
92
|
+
};
|
|
93
|
+
}()),
|
|
94
|
+
// IE < 9 or other non ES5 yet browsers
|
|
95
|
+
getOwnPropertyDescriptor = (goNative && Object.getOwnPropertyDescriptor) ||
|
|
96
|
+
function (o, k) {
|
|
97
|
+
var
|
|
98
|
+
descriptor = {
|
|
99
|
+
enumerable: true,
|
|
100
|
+
configurable: true
|
|
101
|
+
},
|
|
102
|
+
get = lookupGetter && lookupGetter.call(o, k),
|
|
103
|
+
set = lookupSetter && lookupSetter.call(o, k);
|
|
104
|
+
if (get) {
|
|
105
|
+
descriptor.get = get;
|
|
106
|
+
}
|
|
107
|
+
if (set) {
|
|
108
|
+
descriptor.set = set;
|
|
109
|
+
}
|
|
110
|
+
if (!(get || set)) {
|
|
111
|
+
descriptor.writable = true;
|
|
112
|
+
descriptor.value = o[k];
|
|
113
|
+
}
|
|
114
|
+
return descriptor;
|
|
115
|
+
};
|
|
116
|
+
// </droppable>
|
|
117
|
+
|
|
118
|
+
// if already defined get out of here
|
|
119
|
+
// this should be
|
|
120
|
+
// if (mixin in Object) return;
|
|
121
|
+
// but for some reason I went for JSLint ...
|
|
122
|
+
if (Object[mixin]) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
// same descriptor as other spec'd methods
|
|
126
|
+
defineProperty(
|
|
127
|
+
Object,
|
|
128
|
+
mixin,
|
|
129
|
+
{
|
|
130
|
+
enumerable: false,
|
|
131
|
+
writable: true,
|
|
132
|
+
configurable: true,
|
|
133
|
+
value: function (
|
|
134
|
+
target, // object to enrich with
|
|
135
|
+
source, // mixin object or Trait (Function)
|
|
136
|
+
args // optional arguments for Trait
|
|
137
|
+
) {
|
|
138
|
+
var
|
|
139
|
+
i,
|
|
140
|
+
length,
|
|
141
|
+
keys,
|
|
142
|
+
key;
|
|
143
|
+
|
|
144
|
+
if (typeof source === 'function') {
|
|
145
|
+
// if the source is a function
|
|
146
|
+
// it will be invoked with object as target
|
|
147
|
+
// this let us define mixin as closures
|
|
148
|
+
// function addFunctionality() {
|
|
149
|
+
// this.functionality = function () {
|
|
150
|
+
// // do amazing stuff
|
|
151
|
+
// }
|
|
152
|
+
// }
|
|
153
|
+
// addFunctionality.call(Class.prototype);
|
|
154
|
+
// addFunctionality.call(genericObject);
|
|
155
|
+
// // or
|
|
156
|
+
// Object.mixin(Class.prototype, addFunctionality);
|
|
157
|
+
|
|
158
|
+
source.apply(target, args || emptyArray);
|
|
159
|
+
/*
|
|
160
|
+
// try to perform as fast as possible
|
|
161
|
+
if (arguments.length < 3) {
|
|
162
|
+
// so if no extra args are passed ...
|
|
163
|
+
source.call(target);
|
|
164
|
+
} else {
|
|
165
|
+
// there is no need to slice them as done here
|
|
166
|
+
source.apply(target, slice.call(arguments, 2));
|
|
167
|
+
}
|
|
168
|
+
*/
|
|
169
|
+
} else {
|
|
170
|
+
// if source is an object
|
|
171
|
+
// grab all possibe properties
|
|
172
|
+
// and per each of them ...
|
|
173
|
+
keys = getOwnPropertyNames(source);
|
|
174
|
+
length = keys.length;
|
|
175
|
+
i = 0;
|
|
176
|
+
while (i < length) {
|
|
177
|
+
key = keys[i++];
|
|
178
|
+
// ... define it ...
|
|
179
|
+
defineProperty(
|
|
180
|
+
target,
|
|
181
|
+
key,
|
|
182
|
+
// ... using the same descriptor
|
|
183
|
+
getOwnPropertyDescriptor(
|
|
184
|
+
source,
|
|
185
|
+
key
|
|
186
|
+
)
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
// always return the initial target
|
|
191
|
+
// ignoring all possible different return with functions
|
|
192
|
+
return target;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
);
|
|
196
|
+
}(Object, 'mixin'));
|