ende 0.2.9 → 0.2.10
Sign up to get free protection for your applications and to get access to all the features.
- 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,93 @@
|
|
1
|
+
var jQuery, model, record, root;
|
2
|
+
|
3
|
+
require('indemma/lib/record/restfulable');
|
4
|
+
|
5
|
+
require('indemma/lib/record/resource');
|
6
|
+
|
7
|
+
root = typeof exports !== "undefined" && exports !== null ? exports : window;
|
8
|
+
|
9
|
+
model = root.model;
|
10
|
+
|
11
|
+
record = root.record;
|
12
|
+
|
13
|
+
jQuery = require('component-jquery');
|
14
|
+
|
15
|
+
describe('resource', function() {
|
16
|
+
describe('with scope option', function() {
|
17
|
+
var person, towel;
|
18
|
+
|
19
|
+
person = towel = null;
|
20
|
+
beforeEach(function() {
|
21
|
+
person = model.call({
|
22
|
+
resource: 'person'
|
23
|
+
});
|
24
|
+
return towel = model.call({
|
25
|
+
resource: {
|
26
|
+
name: 'towel',
|
27
|
+
scope: 'users'
|
28
|
+
}
|
29
|
+
});
|
30
|
+
});
|
31
|
+
return it('should be prefixed with scope', function() {
|
32
|
+
towel.route.should.be.eq('/users/towels');
|
33
|
+
towel({}).route.should.be.eq('/users/towels');
|
34
|
+
return towel({
|
35
|
+
id: 1
|
36
|
+
}).route.should.be.eq('/users/towels');
|
37
|
+
});
|
38
|
+
});
|
39
|
+
describe('with singular resource', function() {
|
40
|
+
var towel;
|
41
|
+
|
42
|
+
towel = null;
|
43
|
+
beforeEach(function() {
|
44
|
+
var context, deferred, promises;
|
45
|
+
|
46
|
+
towel = model.call({
|
47
|
+
resource: {
|
48
|
+
name: 'towel',
|
49
|
+
singular: true
|
50
|
+
}
|
51
|
+
});
|
52
|
+
deferred = jQuery.Deferred();
|
53
|
+
context = towel({
|
54
|
+
name: 'Arthur Philip Dent'
|
55
|
+
});
|
56
|
+
context.lock = JSON.stringify(context.json());
|
57
|
+
deferred.resolveWith(context, [
|
58
|
+
{
|
59
|
+
_id: 1,
|
60
|
+
name: 'Arthur Philip Dent'
|
61
|
+
}
|
62
|
+
]);
|
63
|
+
sinon.stub(jQuery, "ajax").returns(deferred);
|
64
|
+
return promises = towel.create({
|
65
|
+
name: 'Arthur Philip Dent'
|
66
|
+
}, {
|
67
|
+
name: 'Ford'
|
68
|
+
});
|
69
|
+
});
|
70
|
+
afterEach(function() {
|
71
|
+
return jQuery.ajax.restore();
|
72
|
+
});
|
73
|
+
return it('the route should be in singular form', function() {
|
74
|
+
towel.route.should.be.eq('/towel');
|
75
|
+
towel({}).route.should.be.eq('/towel');
|
76
|
+
return towel({
|
77
|
+
id: 1
|
78
|
+
}).route.should.be.eq('/towel');
|
79
|
+
});
|
80
|
+
});
|
81
|
+
describe('when included', function() {
|
82
|
+
return xit('sets the resource loaded flag on model', function() {});
|
83
|
+
});
|
84
|
+
return describe('model', function() {
|
85
|
+
it('add methods to model object');
|
86
|
+
describe('#pluralize', function() {
|
87
|
+
return xit('transforms word into plural form');
|
88
|
+
});
|
89
|
+
return describe('#singularize', function() {
|
90
|
+
return xit('transforms word into singular form');
|
91
|
+
});
|
92
|
+
});
|
93
|
+
});
|
@@ -0,0 +1,32 @@
|
|
1
|
+
var jQuery, rest, root;
|
2
|
+
|
3
|
+
require('indemma/lib/record/resource');
|
4
|
+
|
5
|
+
root = typeof exports !== "undefined" && exports !== null ? exports : window;
|
6
|
+
|
7
|
+
rest = require('indemma/lib/record/rest');
|
8
|
+
|
9
|
+
jQuery = require('component-jquery');
|
10
|
+
|
11
|
+
describe('rest', function() {
|
12
|
+
var object;
|
13
|
+
|
14
|
+
object = null;
|
15
|
+
beforeEach(function() {
|
16
|
+
object = Object.create(rest);
|
17
|
+
object.route = "users";
|
18
|
+
return object.resource = "user";
|
19
|
+
});
|
20
|
+
beforeEach(function() {
|
21
|
+
return sinon.stub(jQuery, "ajax").returns(jQuery.Deferred());
|
22
|
+
});
|
23
|
+
afterEach(function() {
|
24
|
+
return jQuery.ajax.restore();
|
25
|
+
});
|
26
|
+
return describe('#delete', function() {
|
27
|
+
return it('should make ajax call', function() {
|
28
|
+
object["delete"]();
|
29
|
+
return jQuery.ajax.called.should.be["true"];
|
30
|
+
});
|
31
|
+
});
|
32
|
+
});
|
@@ -0,0 +1,288 @@
|
|
1
|
+
var jQuery, model, record, root, should_behave_like_errorsable;
|
2
|
+
|
3
|
+
require('indemma/lib/record/restfulable');
|
4
|
+
|
5
|
+
require('indemma/lib/record/validatable');
|
6
|
+
|
7
|
+
require('indemma/lib/record/resource');
|
8
|
+
|
9
|
+
'use strict';
|
10
|
+
|
11
|
+
root = typeof exports !== "undefined" && exports !== null ? exports : window;
|
12
|
+
|
13
|
+
model = root.model;
|
14
|
+
|
15
|
+
record = root.record;
|
16
|
+
|
17
|
+
jQuery = require('component-jquery');
|
18
|
+
|
19
|
+
should_behave_like_errorsable = function() {
|
20
|
+
return describe('.errors', function() {
|
21
|
+
return describe('when server responds', function() {
|
22
|
+
beforeEach(function() {
|
23
|
+
return this.xhr = {
|
24
|
+
status: 422
|
25
|
+
};
|
26
|
+
});
|
27
|
+
describe('with errors', function() {
|
28
|
+
it('should add messages for each attribute on the errors object');
|
29
|
+
return it('should add messages for base attribute on the errors object', function() {
|
30
|
+
var base_messages;
|
31
|
+
|
32
|
+
base_messages = ["arthur you should bring a towel!"];
|
33
|
+
this.xhr.responseText = JSON.stringify({
|
34
|
+
errors: {
|
35
|
+
base: base_messages
|
36
|
+
}
|
37
|
+
});
|
38
|
+
this.subject.failed(this.xhr, 'error');
|
39
|
+
this.subject.should.have.property('errors');
|
40
|
+
this.subject.errors[0].should.include('base', 'server', {
|
41
|
+
server_message: base_messages[0]
|
42
|
+
});
|
43
|
+
return this.subject.errors.messages.should.have.property('base', base_messages[0]);
|
44
|
+
});
|
45
|
+
});
|
46
|
+
return describe('with invalid error messages', function() {
|
47
|
+
return it('when inexistent attribute should throw exception', function() {});
|
48
|
+
});
|
49
|
+
});
|
50
|
+
});
|
51
|
+
};
|
52
|
+
|
53
|
+
describe('restfulable', function() {
|
54
|
+
describe('when included', function() {
|
55
|
+
return it('sets te restufulable loaded flag on model', function() {
|
56
|
+
return model.restfulable.should.be["true"];
|
57
|
+
});
|
58
|
+
});
|
59
|
+
describe('record', function() {
|
60
|
+
var arthur;
|
61
|
+
|
62
|
+
arthur = null;
|
63
|
+
return describe('()', function() {
|
64
|
+
beforeEach(function() {
|
65
|
+
this.arthur = arthur = record.call({
|
66
|
+
resource: 'person',
|
67
|
+
name: 'Arthur Philip Dent'
|
68
|
+
});
|
69
|
+
return this.arthur.dirty = true;
|
70
|
+
});
|
71
|
+
return describe('.save()', function() {
|
72
|
+
beforeEach(function() {
|
73
|
+
return sinon.stub(jQuery, "ajax").returns(jQuery.Deferred());
|
74
|
+
});
|
75
|
+
afterEach(function() {
|
76
|
+
return jQuery.ajax.restore();
|
77
|
+
});
|
78
|
+
it('should be able to serialize record', function() {
|
79
|
+
return JSON.stringify(arthur.json());
|
80
|
+
});
|
81
|
+
it('should ignore key in transient fields');
|
82
|
+
it('should send paramenters accordingly');
|
83
|
+
return it('should make ajax call', function() {
|
84
|
+
arthur.save();
|
85
|
+
return jQuery.ajax.called.should.be["true"];
|
86
|
+
});
|
87
|
+
});
|
88
|
+
});
|
89
|
+
});
|
90
|
+
return describe('model', function() {
|
91
|
+
return describe('()', function() {
|
92
|
+
describe('.json()', function() {
|
93
|
+
var friend, person;
|
94
|
+
|
95
|
+
friend = person = null;
|
96
|
+
return beforeEach(function() {
|
97
|
+
person = model.call({
|
98
|
+
resource: 'person',
|
99
|
+
has_many: 'friends',
|
100
|
+
nested_attributes: ['friends'],
|
101
|
+
name: String
|
102
|
+
});
|
103
|
+
return friend = model.call({
|
104
|
+
resource: 'friend',
|
105
|
+
belongs_to: 'person'
|
106
|
+
});
|
107
|
+
});
|
108
|
+
});
|
109
|
+
describe('.assign_attributes()', function() {
|
110
|
+
var friend, person;
|
111
|
+
|
112
|
+
friend = person = null;
|
113
|
+
beforeEach(function() {
|
114
|
+
person = model.call({
|
115
|
+
resource: 'person',
|
116
|
+
has_many: 'friends',
|
117
|
+
name: String
|
118
|
+
});
|
119
|
+
return friend = model.call({
|
120
|
+
resource: 'friend',
|
121
|
+
belongs_to: 'person'
|
122
|
+
});
|
123
|
+
});
|
124
|
+
return it('assigns associations properly', function() {
|
125
|
+
var arthur, attributes, ford, marvin, search_record;
|
126
|
+
|
127
|
+
arthur = person({
|
128
|
+
name: 'Arthur Dent'
|
129
|
+
});
|
130
|
+
ford = friend({
|
131
|
+
name: 'Ford Perfect'
|
132
|
+
});
|
133
|
+
marvin = friend({
|
134
|
+
name: 'Marvin'
|
135
|
+
});
|
136
|
+
attributes = {
|
137
|
+
friends: [ford, marvin]
|
138
|
+
};
|
139
|
+
arthur.assign_attributes(attributes);
|
140
|
+
search_record = function(association, search) {
|
141
|
+
var associated, _i, _len;
|
142
|
+
|
143
|
+
search = JSON.stringify(search.json());
|
144
|
+
for (_i = 0, _len = association.length; _i < _len; _i++) {
|
145
|
+
associated = association[_i];
|
146
|
+
associated = JSON.stringify(associated.json());
|
147
|
+
if (associated === search) {
|
148
|
+
return true;
|
149
|
+
}
|
150
|
+
}
|
151
|
+
return false;
|
152
|
+
};
|
153
|
+
search_record(arthur.friends, ford).should.be.eq["true"];
|
154
|
+
return search_record(arthur.friends, arthur).should.be.eq["true"];
|
155
|
+
});
|
156
|
+
});
|
157
|
+
describe('with singular resource', function() {
|
158
|
+
return describe('.create()', function() {
|
159
|
+
it('should return promises');
|
160
|
+
return it('should return models when promise is resolved');
|
161
|
+
});
|
162
|
+
});
|
163
|
+
describe('with plural resource', function() {
|
164
|
+
return describe('.create()', function() {
|
165
|
+
var deferred, person, promise;
|
166
|
+
|
167
|
+
deferred = promise = person = null;
|
168
|
+
should_behave_like_errorsable();
|
169
|
+
beforeEach(function() {
|
170
|
+
var context;
|
171
|
+
|
172
|
+
person = model.call({
|
173
|
+
resource: 'person'
|
174
|
+
});
|
175
|
+
deferred = jQuery.Deferred();
|
176
|
+
this.subject = context = person({
|
177
|
+
name: 'Arthur'
|
178
|
+
});
|
179
|
+
context.lock = JSON.stringify(context.json());
|
180
|
+
deferred.resolveWith(context, [
|
181
|
+
{
|
182
|
+
_id: 1,
|
183
|
+
name: 'Arthur'
|
184
|
+
}
|
185
|
+
]);
|
186
|
+
deferred.resolveWith(person({
|
187
|
+
name: 'Arthur'
|
188
|
+
}), [
|
189
|
+
{
|
190
|
+
_id: 1,
|
191
|
+
name: 'Arthur'
|
192
|
+
}
|
193
|
+
]);
|
194
|
+
sinon.stub(jQuery, "ajax").returns(deferred);
|
195
|
+
return promise = person.create({
|
196
|
+
name: 'Arthur'
|
197
|
+
}, {
|
198
|
+
name: 'Ford'
|
199
|
+
});
|
200
|
+
});
|
201
|
+
afterEach(function() {
|
202
|
+
return jQuery.ajax.restore();
|
203
|
+
});
|
204
|
+
it('should return a promise', function(done) {
|
205
|
+
promise.done.should.be["function"];
|
206
|
+
promise.state().should.be.eq('resolved');
|
207
|
+
return promise.done(function() {
|
208
|
+
return done();
|
209
|
+
}).should.be.eq('resolved');
|
210
|
+
});
|
211
|
+
it('should return models when promise is resolved', function(done) {
|
212
|
+
var created;
|
213
|
+
|
214
|
+
created = function() {
|
215
|
+
this.name.should.be.eq('Arthur');
|
216
|
+
return done();
|
217
|
+
};
|
218
|
+
return person.create({
|
219
|
+
name: 'Arthur'
|
220
|
+
}, {
|
221
|
+
name: 'Ford'
|
222
|
+
}, created);
|
223
|
+
});
|
224
|
+
it('should optionally accept create callback', function(done) {
|
225
|
+
promise = person.create({
|
226
|
+
name: 'Arthur'
|
227
|
+
}, {
|
228
|
+
name: 'Ford'
|
229
|
+
});
|
230
|
+
promise.done.should.be["function"];
|
231
|
+
promise.done(function() {
|
232
|
+
return done();
|
233
|
+
});
|
234
|
+
return promise.state().should.be.eq('resolved');
|
235
|
+
});
|
236
|
+
it('should create record when only callback is passed', function(done) {
|
237
|
+
person.create(function() {
|
238
|
+
return done();
|
239
|
+
});
|
240
|
+
return jQuery.ajax.callCount.should.be.eq(3);
|
241
|
+
});
|
242
|
+
it('should throw exception when nothing is passed', function() {
|
243
|
+
return expect(person.create).to["throw"](TypeError);
|
244
|
+
});
|
245
|
+
return it('should make ajax calls', function() {
|
246
|
+
return jQuery.ajax.callCount.should.be.eq(3);
|
247
|
+
});
|
248
|
+
});
|
249
|
+
});
|
250
|
+
return describe('.destroy()', function() {
|
251
|
+
return describe('with plural resource', function() {
|
252
|
+
var arthur, deferred, person;
|
253
|
+
|
254
|
+
arthur = person = deferred = null;
|
255
|
+
beforeEach(function() {
|
256
|
+
person = model.call({
|
257
|
+
resource: 'person'
|
258
|
+
});
|
259
|
+
deferred = jQuery.Deferred();
|
260
|
+
deferred.resolveWith(person({
|
261
|
+
name: 'Arthur'
|
262
|
+
}), [
|
263
|
+
{
|
264
|
+
id: 1
|
265
|
+
}
|
266
|
+
]);
|
267
|
+
sinon.stub(jQuery, "ajax").returns(deferred);
|
268
|
+
return arthur = person({
|
269
|
+
name: 'Arthur',
|
270
|
+
id: 1
|
271
|
+
});
|
272
|
+
});
|
273
|
+
afterEach(function() {
|
274
|
+
return jQuery.ajax.restore();
|
275
|
+
});
|
276
|
+
it("throw exception when record has no id", function() {
|
277
|
+
delete arthur.id;
|
278
|
+
return expect(arthur.destroy).to["throw"](Error);
|
279
|
+
});
|
280
|
+
return it("should make ajax calls", function() {
|
281
|
+
arthur.destroy();
|
282
|
+
return jQuery.ajax.callCount.should.be.eq(1);
|
283
|
+
});
|
284
|
+
});
|
285
|
+
});
|
286
|
+
});
|
287
|
+
});
|
288
|
+
});
|
@@ -0,0 +1,212 @@
|
|
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
|
+
$by_name: String,
|
31
|
+
resource: 'person'
|
32
|
+
});
|
33
|
+
});
|
34
|
+
it('should add scope methods to model', function() {
|
35
|
+
return person.none.should.be["function"];
|
36
|
+
});
|
37
|
+
it('should generate scope methods based on model definition', function() {
|
38
|
+
return person.hetero.should.be["function"];
|
39
|
+
});
|
40
|
+
describe('#none', function() {
|
41
|
+
return it('should return empty response on fetch calls', function(done) {
|
42
|
+
return person.none().fetch(null, function(people) {
|
43
|
+
people.length.should.be.empty;
|
44
|
+
return done();
|
45
|
+
});
|
46
|
+
});
|
47
|
+
});
|
48
|
+
describe('scope', function() {
|
49
|
+
return describe('#(name, type)', function() {
|
50
|
+
return it('should add scope methods to model', function() {
|
51
|
+
person.scope('bissexual', Boolean);
|
52
|
+
return person.bissexual.should.be["function"];
|
53
|
+
});
|
54
|
+
});
|
55
|
+
});
|
56
|
+
return describe('#{generated_scope}', function() {
|
57
|
+
var deferred;
|
58
|
+
|
59
|
+
deferred = null;
|
60
|
+
beforeEach(function() {
|
61
|
+
deferred = jQuery.Deferred();
|
62
|
+
sinon.stub(jQuery, "ajax").returns(deferred);
|
63
|
+
return person.scope.clear();
|
64
|
+
});
|
65
|
+
afterEach(function() {
|
66
|
+
return jQuery.ajax.restore();
|
67
|
+
});
|
68
|
+
describe('#all', function() {
|
69
|
+
var promises;
|
70
|
+
|
71
|
+
deferred = promises = person = null;
|
72
|
+
return it('should return models when promise is resolved', function(done) {
|
73
|
+
var fetched;
|
74
|
+
|
75
|
+
fetched = function(people) {
|
76
|
+
people.should.be.array;
|
77
|
+
people[0].name.should.be.string;
|
78
|
+
return done();
|
79
|
+
};
|
80
|
+
person.all(fetched);
|
81
|
+
deferred.resolveWith(person, [
|
82
|
+
[
|
83
|
+
{
|
84
|
+
name: 'Arthur'
|
85
|
+
}, {
|
86
|
+
name: 'Ford'
|
87
|
+
}
|
88
|
+
]
|
89
|
+
]);
|
90
|
+
return jQuery.ajax.callCount.should.be.eq(1);
|
91
|
+
});
|
92
|
+
});
|
93
|
+
describe('when string', function() {
|
94
|
+
it('should acumulate data in scope object', function() {
|
95
|
+
person.by_name();
|
96
|
+
return person.scope.data.by_name.should.be.a('string');
|
97
|
+
});
|
98
|
+
return it('should override data throught parameters', function() {
|
99
|
+
person.by_name('Ford');
|
100
|
+
return person.scope.data.by_name.should.be.eq('Ford');
|
101
|
+
});
|
102
|
+
});
|
103
|
+
describe('when array', function() {
|
104
|
+
it('should acumulate data in scope object', function() {
|
105
|
+
person.by_type();
|
106
|
+
return person.scope.data.by_type.should.be.a('array');
|
107
|
+
});
|
108
|
+
it('should override data throught parameters', function() {
|
109
|
+
person.by_type(1, 2, 3);
|
110
|
+
return person.scope.data.by_type.should.contain(1, 2, 3);
|
111
|
+
});
|
112
|
+
it('should use default value');
|
113
|
+
it('should allow scope chaining');
|
114
|
+
return describe('xhr request', function() {
|
115
|
+
it('should build correct url', function() {
|
116
|
+
var settings;
|
117
|
+
|
118
|
+
person.by_type(1, 3, 4).fetch();
|
119
|
+
settings = jQuery.ajax.firstCall.args[0];
|
120
|
+
settings.should.have.property('data');
|
121
|
+
settings.data.should.have.property('by_type');
|
122
|
+
return settings.data.by_type.should.include(1, 3, 4);
|
123
|
+
});
|
124
|
+
return it('should make call', function() {
|
125
|
+
person.by_type(1, 3, 4).fetch();
|
126
|
+
return jQuery.ajax.callCount.should.be.eq(1);
|
127
|
+
});
|
128
|
+
});
|
129
|
+
});
|
130
|
+
describe('when boolean', function() {
|
131
|
+
it('should acumulate data in scope object', function() {
|
132
|
+
person.hetero();
|
133
|
+
return person.scope.data.hetero.should.be.eq(true);
|
134
|
+
});
|
135
|
+
it('should override data throught parameters', function() {
|
136
|
+
person.hetero(false);
|
137
|
+
return person.scope.data.hetero.should.be.eq(false);
|
138
|
+
});
|
139
|
+
it('should allow scope chaining');
|
140
|
+
return it('should make ajax call', function() {
|
141
|
+
person.hetero().fetch();
|
142
|
+
return jQuery.ajax.callCount.should.be.eq(1);
|
143
|
+
});
|
144
|
+
});
|
145
|
+
return describe('#{generated_association}', function() {
|
146
|
+
describe('of type belongs_to', function() {
|
147
|
+
var towel;
|
148
|
+
|
149
|
+
towel = null;
|
150
|
+
beforeEach(function() {
|
151
|
+
person = model.call({
|
152
|
+
$hetero: true,
|
153
|
+
$by_type: [],
|
154
|
+
resource: 'person'
|
155
|
+
});
|
156
|
+
return towel = model.call({
|
157
|
+
resource: 'towel',
|
158
|
+
material: 'cotton',
|
159
|
+
belongs_to: 'person'
|
160
|
+
});
|
161
|
+
});
|
162
|
+
return describe('#{generated_scope}', function() {
|
163
|
+
return it('can be called on association', function() {
|
164
|
+
var soft_towel;
|
165
|
+
|
166
|
+
soft_towel = towel({
|
167
|
+
material: 'silicon microfiber'
|
168
|
+
});
|
169
|
+
soft_towel.build_person();
|
170
|
+
return expect(soft_towel.person).to.respondTo('hetero');
|
171
|
+
});
|
172
|
+
});
|
173
|
+
});
|
174
|
+
return describe('of type has_many', function() {
|
175
|
+
var arthur, towel;
|
176
|
+
|
177
|
+
arthur = towel = null;
|
178
|
+
beforeEach(function() {
|
179
|
+
person = model.call({
|
180
|
+
$hetero: true,
|
181
|
+
$by_type: [],
|
182
|
+
resource: 'person',
|
183
|
+
has_many: 'towels'
|
184
|
+
});
|
185
|
+
towel = model.call({
|
186
|
+
$by_material: [],
|
187
|
+
resource: 'towel',
|
188
|
+
material: 'cotton',
|
189
|
+
belongs_to: 'person'
|
190
|
+
});
|
191
|
+
return arthur = person({
|
192
|
+
name: 'Arthur'
|
193
|
+
});
|
194
|
+
});
|
195
|
+
return describe('#{generated_scope}', function() {
|
196
|
+
it('can be called on association', function() {
|
197
|
+
return expect(arthur.towels).to.respondTo('by_material');
|
198
|
+
});
|
199
|
+
return it('should be serializable into paramenters', function() {
|
200
|
+
var query_string;
|
201
|
+
|
202
|
+
arthur.towels.by_material('cotton', 'microfiber');
|
203
|
+
query_string = decodeURIComponent(jQuery.param(arthur.towels.scope.data));
|
204
|
+
return query_string.should.be.eq('by_material[]=cotton&by_material[]=microfiber');
|
205
|
+
});
|
206
|
+
});
|
207
|
+
});
|
208
|
+
});
|
209
|
+
});
|
210
|
+
});
|
211
|
+
});
|
212
|
+
});
|
@@ -0,0 +1,53 @@
|
|
1
|
+
var root, storable;
|
2
|
+
|
3
|
+
root = typeof exports !== "undefined" && exports !== null ? exports : window;
|
4
|
+
|
5
|
+
storable = require('indemma/lib/record/storable');
|
6
|
+
|
7
|
+
describe('storable', function() {
|
8
|
+
it('should set the storable key', function() {
|
9
|
+
return model.should.have.property('storable', true);
|
10
|
+
});
|
11
|
+
beforeEach(function() {
|
12
|
+
return this.storage = storable();
|
13
|
+
});
|
14
|
+
return describe("#store", function() {
|
15
|
+
describe("write", function() {
|
16
|
+
it("should write object on deep storage");
|
17
|
+
it("should write object on storage", function() {
|
18
|
+
var data;
|
19
|
+
|
20
|
+
data = {
|
21
|
+
name: 'Arthur Dent'
|
22
|
+
};
|
23
|
+
this.storage.store('1', data);
|
24
|
+
this.storage.writes.should.be.eq(1);
|
25
|
+
return this.storage.database['1'].should.be.eq(data);
|
26
|
+
});
|
27
|
+
return it("should mark an object as sustained", function() {
|
28
|
+
var data;
|
29
|
+
|
30
|
+
data = {
|
31
|
+
name: 'Arthur Dent'
|
32
|
+
};
|
33
|
+
this.storage.store('1', data);
|
34
|
+
return data.should.have.property('sustained', true);
|
35
|
+
});
|
36
|
+
});
|
37
|
+
return describe("read", function() {
|
38
|
+
var data;
|
39
|
+
|
40
|
+
data = null;
|
41
|
+
beforeEach(function() {
|
42
|
+
data = {
|
43
|
+
name: 'Arthur Dent'
|
44
|
+
};
|
45
|
+
return this.storage.store('1', data);
|
46
|
+
});
|
47
|
+
it("should save object on storage", function() {
|
48
|
+
return this.storage.store('1').should.be.eq(data);
|
49
|
+
});
|
50
|
+
return it("should unmark an object as sustained");
|
51
|
+
});
|
52
|
+
});
|
53
|
+
});
|
@@ -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
|
+
});
|