ende 0.1.14 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/component.json +1 -1
- data/lib/assets/javascripts/aura/extensions/devise.js.coffee +5 -2
- data/lib/assets/javascripts/aura/extensions/models.js.coffee.erb +4 -3
- data/lib/assets/javascripts/value_objects/phone.js.coffee +8 -2
- data/lib/assets/javascripts/widgets/viewer/main.js.coffee +18 -21
- data/lib/ende/version.rb +1 -1
- data/lib/ende.rb +2 -2
- data/vendor/assets/javascripts/ende/build.js +485 -4879
- data/vendor/components/component-querystring/component.json +18 -0
- data/vendor/components/component-querystring/index.js +49 -0
- data/vendor/components/component-trim/component.json +13 -0
- data/vendor/components/component-trim/index.js +17 -0
- data/vendor/components/indefinido-indemma/.gitignore +14 -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 +443 -0
- data/vendor/components/indefinido-indemma/build/development.js +331 -0
- data/vendor/components/indefinido-indemma/build/release.js +21693 -0
- data/vendor/components/indefinido-indemma/build/test.js +331 -0
- data/vendor/components/indefinido-indemma/component.json +8 -9
- 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/pluma-assimilate/component.json +25 -0
- data/vendor/components/indefinido-indemma/components/pluma-assimilate/dist/assimilate.js +87 -0
- data/vendor/components/indefinido-indemma/karma.conf.js +86 -0
- data/vendor/components/indefinido-indemma/lib/record/associable.js +6 -6
- data/vendor/components/indefinido-indemma/lib/record/errors.js +1 -0
- data/vendor/components/indefinido-indemma/lib/record/resource.js +14 -3
- data/vendor/components/indefinido-indemma/lib/record/rest.js +7 -4
- data/vendor/components/indefinido-indemma/lib/record/restfulable.js +45 -15
- data/vendor/components/indefinido-indemma/lib/record/scopable.js +13 -3
- data/vendor/components/indefinido-indemma/lib/record/validatable.js +20 -9
- data/vendor/components/indefinido-indemma/lib/record/validations/confirmation.js +1 -1
- data/vendor/components/indefinido-indemma/lib/record/validations/remote.js +6 -5
- data/vendor/components/indefinido-indemma/lib/record/validations/type.js +29 -0
- data/vendor/components/indefinido-indemma/lib/record.js +1 -11
- data/vendor/components/indefinido-indemma/spec/record/associable_spec.js +76 -0
- data/vendor/components/indefinido-indemma/spec/record/resource_spec.js +90 -0
- data/vendor/components/indefinido-indemma/spec/record/rest_spec.js +32 -0
- data/vendor/components/indefinido-indemma/spec/record/restfulable_spec.js +232 -0
- data/vendor/components/indefinido-indemma/spec/record/scopable_spec.js +201 -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 +86 -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 +173 -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/resource.coffee +103 -0
- data/vendor/components/indefinido-indemma/src/lib/record/rest.coffee +28 -0
- data/vendor/components/indefinido-indemma/src/lib/record/restfulable.coffee +314 -0
- data/vendor/components/indefinido-indemma/src/lib/record/scopable.coffee +266 -0
- data/vendor/components/indefinido-indemma/src/lib/record/translationable.coffee +18 -0
- data/vendor/components/indefinido-indemma/src/lib/record/validatable.coffee +209 -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 +123 -0
- data/vendor/components/indefinido-indemma/src/spec/record/associable_spec.coffee +63 -0
- data/vendor/components/indefinido-indemma/src/spec/record/resource_spec.coffee +64 -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 +164 -0
- data/vendor/components/indefinido-indemma/src/spec/record/scopable_spec.coffee +181 -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 +72 -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/owl/pluralize.js +190 -0
- data/vendor/components/indefinido-observable/lib/observable.js +3 -0
- metadata +119 -2
@@ -19,12 +19,13 @@ remoteable = stampit({
|
|
19
19
|
});
|
20
20
|
},
|
21
21
|
json: function(record) {
|
22
|
-
var data, _base;
|
22
|
+
var data, param, _base;
|
23
23
|
|
24
|
+
param = this.resource.param_name || this.resource.toString();
|
24
25
|
data = {};
|
25
|
-
data[
|
26
|
-
(_base = data[
|
27
|
-
delete data[
|
26
|
+
data[param] = record.json();
|
27
|
+
(_base = data[param]).id || (_base.id = data[param]._id);
|
28
|
+
delete data[param]._id;
|
28
29
|
return data;
|
29
30
|
},
|
30
31
|
post: function(data) {
|
@@ -58,7 +59,7 @@ remoteable = stampit({
|
|
58
59
|
}, function() {
|
59
60
|
var pluralized_resource;
|
60
61
|
|
61
|
-
pluralized_resource = model.pluralize(this.model.resource);
|
62
|
+
pluralized_resource = model.pluralize(this.model.resource.toString());
|
62
63
|
this.resource = this.model.resource;
|
63
64
|
this.route || (this.route = "/" + pluralized_resource + "/validate");
|
64
65
|
return this;
|
@@ -0,0 +1,29 @@
|
|
1
|
+
var composed, stampit, typeable, validations;
|
2
|
+
|
3
|
+
validations = require('../validatable');
|
4
|
+
|
5
|
+
stampit = require('../../../vendor/stampit');
|
6
|
+
|
7
|
+
typeable = stampit({
|
8
|
+
validate_each: function(record, attribute, value) {
|
9
|
+
this.type || (this.type = model[record.resource.toString()][attribute]);
|
10
|
+
if (value) {
|
11
|
+
if (value instanceof this.type) {
|
12
|
+
this.type_name || (this.type_name = this.type.name);
|
13
|
+
if (!value.valid) {
|
14
|
+
return record.errors.add(attribute, 'type', {
|
15
|
+
type_name: this.type_name != null
|
16
|
+
});
|
17
|
+
}
|
18
|
+
} else {
|
19
|
+
throw new Error("Invalid attribute value type! Found " + (typeof value) + " expected " + this.type.name);
|
20
|
+
}
|
21
|
+
}
|
22
|
+
}
|
23
|
+
});
|
24
|
+
|
25
|
+
composed = stampit.compose(validations.validatable, typeable);
|
26
|
+
|
27
|
+
composed.definition_key = 'validates_type_of';
|
28
|
+
|
29
|
+
validations.manager.validators.type = composed;
|
@@ -128,17 +128,7 @@ this.record = (function() {
|
|
128
128
|
var callbacks, recordable, that;
|
129
129
|
|
130
130
|
callbacks = {
|
131
|
-
dirtify: function() {
|
132
|
-
return this.subscribe(function(prop, value, old) {
|
133
|
-
if (prop !== 'dirty' && !this.dirty && value !== old) {
|
134
|
-
console.groupCollapsed("◉ Property '" + prop + "' dirtied a " + this.resource);
|
135
|
-
console.log(old, "→", value);
|
136
|
-
console.log(this);
|
137
|
-
console.groupEnd();
|
138
|
-
return this.dirty = true;
|
139
|
-
}
|
140
|
-
});
|
141
|
-
}
|
131
|
+
dirtify: function() {}
|
142
132
|
};
|
143
133
|
recordable = {
|
144
134
|
dirty: false,
|
@@ -0,0 +1,76 @@
|
|
1
|
+
var root;
|
2
|
+
|
3
|
+
root = typeof exports !== "undefined" && exports !== null ? exports : window;
|
4
|
+
|
5
|
+
require('indemma/lib/record/associable');
|
6
|
+
|
7
|
+
describe('record', function() {
|
8
|
+
var record;
|
9
|
+
|
10
|
+
record = root.record;
|
11
|
+
return it('should create a record');
|
12
|
+
});
|
13
|
+
|
14
|
+
describe('model', function() {
|
15
|
+
var corporation, model, person;
|
16
|
+
|
17
|
+
model = root.model;
|
18
|
+
person = corporation = null;
|
19
|
+
beforeEach(function() {
|
20
|
+
var friend;
|
21
|
+
|
22
|
+
corporation = model.call({
|
23
|
+
resource: 'corporation'
|
24
|
+
});
|
25
|
+
friend = model.call({
|
26
|
+
resource: 'friends'
|
27
|
+
});
|
28
|
+
return person = model.call({
|
29
|
+
resource: 'person',
|
30
|
+
has_many: 'friends',
|
31
|
+
belongs_to: 'corporation'
|
32
|
+
});
|
33
|
+
});
|
34
|
+
describe('belongs_to', function() {
|
35
|
+
return it('should add builded object to association named attribute', function() {
|
36
|
+
var arthur;
|
37
|
+
|
38
|
+
arthur = person({
|
39
|
+
name: 'Arthur Dent'
|
40
|
+
});
|
41
|
+
corporation = arthur.build_corporation();
|
42
|
+
arthur.should.have.property('corporation');
|
43
|
+
return expect(corporation).to.be.ok;
|
44
|
+
});
|
45
|
+
});
|
46
|
+
return describe('has_many', function() {
|
47
|
+
it('should return a record factory with associations stored', function() {
|
48
|
+
var has_many;
|
49
|
+
|
50
|
+
person.has_many.should.be.array;
|
51
|
+
has_many = Array.prototype.splice.call(person.has_many, 0);
|
52
|
+
return has_many.should.contain('friends');
|
53
|
+
});
|
54
|
+
return describe('#()', function() {
|
55
|
+
it('should return a record with an association object', function() {
|
56
|
+
return person().should.have.property('friends');
|
57
|
+
});
|
58
|
+
return describe('{generated_association}', function() {
|
59
|
+
var association;
|
60
|
+
|
61
|
+
association = null;
|
62
|
+
beforeEach(function() {
|
63
|
+
return association = person().friends;
|
64
|
+
});
|
65
|
+
it('should have query methods', function() {
|
66
|
+
association.should.have.property('all');
|
67
|
+
association.should.have.property('each');
|
68
|
+
return association.should.have.property('reload');
|
69
|
+
});
|
70
|
+
return describe('#all', function() {
|
71
|
+
return it('should auto observe nested associations attributes');
|
72
|
+
});
|
73
|
+
});
|
74
|
+
});
|
75
|
+
});
|
76
|
+
});
|
@@ -0,0 +1,90 @@
|
|
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 deferred, promises;
|
45
|
+
|
46
|
+
towel = model.call({
|
47
|
+
resource: {
|
48
|
+
name: 'towel',
|
49
|
+
singular: true
|
50
|
+
}
|
51
|
+
});
|
52
|
+
deferred = jQuery.Deferred();
|
53
|
+
deferred.resolveWith(towel({
|
54
|
+
name: 'Arthur'
|
55
|
+
}), [
|
56
|
+
{
|
57
|
+
_id: 1
|
58
|
+
}
|
59
|
+
]);
|
60
|
+
sinon.stub(jQuery, "ajax").returns(deferred);
|
61
|
+
return promises = towel.create({
|
62
|
+
name: 'Arthur'
|
63
|
+
}, {
|
64
|
+
name: 'Ford'
|
65
|
+
});
|
66
|
+
});
|
67
|
+
afterEach(function() {
|
68
|
+
return jQuery.ajax.restore();
|
69
|
+
});
|
70
|
+
return it('the route should be in singular form', function() {
|
71
|
+
towel.route.should.be.eq('/towel');
|
72
|
+
towel({}).route.should.be.eq('/towel');
|
73
|
+
return towel({
|
74
|
+
id: 1
|
75
|
+
}).route.should.be.eq('/towel');
|
76
|
+
});
|
77
|
+
});
|
78
|
+
describe('when included', function() {
|
79
|
+
return xit('sets the resource loaded flag on model', function() {});
|
80
|
+
});
|
81
|
+
return describe('model', function() {
|
82
|
+
it('add methods to model object');
|
83
|
+
describe('#pluralize', function() {
|
84
|
+
return xit('transforms word into plural form');
|
85
|
+
});
|
86
|
+
return describe('#singularize', function() {
|
87
|
+
return xit('transforms word into singular form');
|
88
|
+
});
|
89
|
+
});
|
90
|
+
});
|
@@ -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,232 @@
|
|
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('restfulable', function() {
|
16
|
+
describe('when included', function() {
|
17
|
+
return it('sets te restufulable loaded flag on model', function() {
|
18
|
+
return model.restfulable.should.be["true"];
|
19
|
+
});
|
20
|
+
});
|
21
|
+
describe('record', function() {
|
22
|
+
var arthur;
|
23
|
+
|
24
|
+
arthur = null;
|
25
|
+
return describe('#()', function() {
|
26
|
+
beforeEach(function() {
|
27
|
+
arthur = record.call({
|
28
|
+
resource: 'person',
|
29
|
+
name: 'Arthur Philip Dent'
|
30
|
+
});
|
31
|
+
return arthur.dirty = true;
|
32
|
+
});
|
33
|
+
return describe('#save', function() {
|
34
|
+
beforeEach(function() {
|
35
|
+
return sinon.stub(jQuery, "ajax").returns(jQuery.Deferred());
|
36
|
+
});
|
37
|
+
afterEach(function() {
|
38
|
+
return jQuery.ajax.restore();
|
39
|
+
});
|
40
|
+
it('should send paramenters accordingly');
|
41
|
+
return it('should make ajax call', function() {
|
42
|
+
arthur.save();
|
43
|
+
return jQuery.ajax.called.should.be["true"];
|
44
|
+
});
|
45
|
+
});
|
46
|
+
});
|
47
|
+
});
|
48
|
+
return describe('model', function() {
|
49
|
+
return describe('#()', function() {
|
50
|
+
describe('#json', function() {
|
51
|
+
var friend, person;
|
52
|
+
|
53
|
+
friend = person = null;
|
54
|
+
return beforeEach(function() {
|
55
|
+
person = model.call({
|
56
|
+
resource: 'person',
|
57
|
+
has_many: 'friends',
|
58
|
+
nested_attributes: ['friends'],
|
59
|
+
name: String
|
60
|
+
});
|
61
|
+
return friend = model.call({
|
62
|
+
resource: 'friend',
|
63
|
+
belongs_to: 'person'
|
64
|
+
});
|
65
|
+
});
|
66
|
+
});
|
67
|
+
describe('#assign_attributes', function() {
|
68
|
+
var friend, person;
|
69
|
+
|
70
|
+
friend = person = null;
|
71
|
+
beforeEach(function() {
|
72
|
+
person = model.call({
|
73
|
+
resource: 'person',
|
74
|
+
has_many: 'friends',
|
75
|
+
name: String
|
76
|
+
});
|
77
|
+
return friend = model.call({
|
78
|
+
resource: 'friend',
|
79
|
+
belongs_to: 'person'
|
80
|
+
});
|
81
|
+
});
|
82
|
+
return it('assigns associations properly', function() {
|
83
|
+
var arthur, attributes, ford, marvin, search_record;
|
84
|
+
|
85
|
+
arthur = person({
|
86
|
+
name: 'Arthur Dent'
|
87
|
+
});
|
88
|
+
ford = friend({
|
89
|
+
name: 'Ford Perfect'
|
90
|
+
});
|
91
|
+
marvin = friend({
|
92
|
+
name: 'Marvin'
|
93
|
+
});
|
94
|
+
attributes = {
|
95
|
+
friends: [ford, marvin]
|
96
|
+
};
|
97
|
+
arthur.assign_attributes(attributes);
|
98
|
+
search_record = function(association, search) {
|
99
|
+
var associated, _i, _len;
|
100
|
+
|
101
|
+
search = JSON.stringify(search.json());
|
102
|
+
for (_i = 0, _len = association.length; _i < _len; _i++) {
|
103
|
+
associated = association[_i];
|
104
|
+
associated = JSON.stringify(associated.json());
|
105
|
+
if (associated === search) {
|
106
|
+
return true;
|
107
|
+
}
|
108
|
+
}
|
109
|
+
return false;
|
110
|
+
};
|
111
|
+
search_record(arthur.friends, ford).should.be.eq["true"];
|
112
|
+
return search_record(arthur.friends, arthur).should.be.eq["true"];
|
113
|
+
});
|
114
|
+
});
|
115
|
+
describe('with singular resource', function() {
|
116
|
+
return describe('#create', function() {
|
117
|
+
it('should return promises');
|
118
|
+
return it('should return models when promise is resolved');
|
119
|
+
});
|
120
|
+
});
|
121
|
+
describe('with plural resource', function() {
|
122
|
+
return describe('#create', function() {
|
123
|
+
var deferred, person, promise;
|
124
|
+
|
125
|
+
deferred = promise = person = null;
|
126
|
+
beforeEach(function() {
|
127
|
+
person = model.call({
|
128
|
+
resource: 'person'
|
129
|
+
});
|
130
|
+
deferred = jQuery.Deferred();
|
131
|
+
deferred.resolveWith(person({
|
132
|
+
name: 'Arthur'
|
133
|
+
}), [
|
134
|
+
{
|
135
|
+
_id: 1
|
136
|
+
}
|
137
|
+
]);
|
138
|
+
sinon.stub(jQuery, "ajax").returns(deferred);
|
139
|
+
return promise = person.create({
|
140
|
+
name: 'Arthur'
|
141
|
+
}, {
|
142
|
+
name: 'Ford'
|
143
|
+
});
|
144
|
+
});
|
145
|
+
afterEach(function() {
|
146
|
+
return jQuery.ajax.restore();
|
147
|
+
});
|
148
|
+
it('should return a promise', function(done) {
|
149
|
+
promise.done.should.be["function"];
|
150
|
+
promise.state().should.be.eq('resolved');
|
151
|
+
return promise.done(function() {
|
152
|
+
return done();
|
153
|
+
}).should.be.eq('resolved');
|
154
|
+
});
|
155
|
+
it('should return models when promise is resolved', function(done) {
|
156
|
+
var created;
|
157
|
+
|
158
|
+
created = function() {
|
159
|
+
this.name.should.be.eq('Arthur');
|
160
|
+
return done();
|
161
|
+
};
|
162
|
+
return person.create({
|
163
|
+
name: 'Arthur'
|
164
|
+
}, {
|
165
|
+
name: 'Ford'
|
166
|
+
}, created);
|
167
|
+
});
|
168
|
+
it('should optionally accept create callback', function(done) {
|
169
|
+
promise = person.create({
|
170
|
+
name: 'Arthur'
|
171
|
+
}, {
|
172
|
+
name: 'Ford'
|
173
|
+
});
|
174
|
+
promise.done.should.be["function"];
|
175
|
+
promise.done(function() {
|
176
|
+
return done();
|
177
|
+
});
|
178
|
+
return promise.state().should.be.eq('resolved');
|
179
|
+
});
|
180
|
+
it('should create record when only callback is passed', function(done) {
|
181
|
+
person.create(function() {
|
182
|
+
return done();
|
183
|
+
});
|
184
|
+
return jQuery.ajax.callCount.should.be.eq(3);
|
185
|
+
});
|
186
|
+
it('should throw exception when nothing is passed', function() {
|
187
|
+
return expect(person.create).to["throw"](TypeError);
|
188
|
+
});
|
189
|
+
return it('should make ajax calls', function() {
|
190
|
+
return jQuery.ajax.callCount.should.be.eq(2);
|
191
|
+
});
|
192
|
+
});
|
193
|
+
});
|
194
|
+
return describe('#destroy', function() {
|
195
|
+
return describe('with plural resource', function() {
|
196
|
+
var arthur, deferred, person;
|
197
|
+
|
198
|
+
arthur = person = deferred = null;
|
199
|
+
beforeEach(function() {
|
200
|
+
person = model.call({
|
201
|
+
resource: 'person'
|
202
|
+
});
|
203
|
+
deferred = jQuery.Deferred();
|
204
|
+
deferred.resolveWith(person({
|
205
|
+
name: 'Arthur'
|
206
|
+
}), [
|
207
|
+
{
|
208
|
+
id: 1
|
209
|
+
}
|
210
|
+
]);
|
211
|
+
sinon.stub(jQuery, "ajax").returns(deferred);
|
212
|
+
return arthur = person({
|
213
|
+
name: 'Arthur',
|
214
|
+
id: 1
|
215
|
+
});
|
216
|
+
});
|
217
|
+
afterEach(function() {
|
218
|
+
return jQuery.ajax.restore();
|
219
|
+
});
|
220
|
+
it("throw exception when record has no id", function() {
|
221
|
+
delete arthur.id;
|
222
|
+
return expect(arthur.destroy).to["throw"](Error);
|
223
|
+
});
|
224
|
+
return it("should make ajax calls", function() {
|
225
|
+
arthur.destroy();
|
226
|
+
return jQuery.ajax.callCount.should.be.eq(1);
|
227
|
+
});
|
228
|
+
});
|
229
|
+
});
|
230
|
+
});
|
231
|
+
});
|
232
|
+
});
|