angularjs-rails-resource 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -4
- data/bower.json +1 -1
- data/lib/angularjs-rails-resource/version.rb +1 -1
- data/package.json +1 -1
- data/test/unit/angularjs/rails/rootWrappingSpec.js +5 -0
- data/test/unit/angularjs/rails/serializationSpec.js +46 -0
- data/vendor/assets/javascripts/angularjs/rails/resource/resource.js +4 -4
- data/vendor/assets/javascripts/angularjs/rails/resource/serialization.js +15 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 64bc74995e3dbdc9aad130c99d334d924338a198
|
4
|
+
data.tar.gz: 12b2abe8d96b3332d843bb6eaa07b2d917ec955e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74b693dacca56b514586bf3e6492917fad7b50fedbf791246ca1f0a82951f068e405b11c04c621ff672defdc8bcdceaa44bd69f0e56c81c1a3929dbb35d2561c
|
7
|
+
data.tar.gz: 959b6166d3056f4c851f9fde9d1116d744550988627ea3c9eb144d25cdc76e8f9bda4521e07f4dc4bd06977cfc24dcc8a25487fca931d9f28c267ba20b95179a
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,13 @@
|
|
1
|
+
<a name="1.2.1"></a>
|
2
|
+
# 1.2.2
|
3
|
+
## Bug Fixes
|
4
|
+
- Add support for adding custom attributes when serializing arrays - #143 (@shuhei)
|
5
|
+
- Force constructor to unwrap as an object - #134 (@tuvistavie)
|
6
|
+
|
1
7
|
<a name="1.2.1"></a>
|
2
8
|
# 1.2.1
|
3
9
|
## Bug Fixes
|
4
|
-
- Call beforeResponse interceptor only once - #139 (@shuhei)
|
10
|
+
- Call beforeResponse interceptor only once - #139 (@shuhei)
|
5
11
|
|
6
12
|
<a name="1.2.0"></a>
|
7
13
|
# 1.2.0
|
@@ -9,7 +15,7 @@
|
|
9
15
|
|
10
16
|
## Features
|
11
17
|
- Added <code>unsnappedChanges()</code> function to snapshots mixin to check whether or not there have been any changes since the last snapshot was taken. - #125 (@StevenClontz)
|
12
|
-
- Added <code>skipRequestProcessing</code> override configuration option to $http, $post, $put, $patch to bypass request processing (root wrapping, serialization) and request interceptor chains - #123 (@mayhewluke)
|
18
|
+
- Added <code>skipRequestProcessing</code> override configuration option to $http, $post, $put, $patch to bypass request processing (root wrapping, serialization) and request interceptor chains - #123 (@mayhewluke)
|
13
19
|
|
14
20
|
<a name="1.1.0"></a>
|
15
21
|
# 1.1.0
|
@@ -18,12 +24,12 @@
|
|
18
24
|
## Features
|
19
25
|
- Added <code>idAttribute</code> configuration option to allow customizing the unique id field on resources. - #114 (@inlineblock)
|
20
26
|
- Added <code>get</code> instance method to refresh resources from the server. - #115 (@wwilkins)
|
21
|
-
|
27
|
+
|
22
28
|
<a name="1.0.1"></a>
|
23
29
|
# 1.0.1
|
24
30
|
## Bug Fixes
|
25
31
|
- <code>response.originalData</code> was not being saved off before the root unwrapping so it didn't match the original response data as intended. @Ditchou
|
26
|
-
|
32
|
+
|
27
33
|
|
28
34
|
<a name="1.0.0"></a>
|
29
35
|
# 1.0.0
|
data/bower.json
CHANGED
data/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "angularjs-rails-resource",
|
3
3
|
"description" : "A resource factory inspired by $resource from AngularJS",
|
4
|
-
"version": "1.2.
|
4
|
+
"version": "1.2.2",
|
5
5
|
"main" : "dist/angularjs-rails-resource.min.js",
|
6
6
|
"homepage" : "https://github.com/FineLinePrototyping/angularjs-rails-resource.git",
|
7
7
|
"author" : "",
|
@@ -24,6 +24,11 @@ describe('root wrapping', function () {
|
|
24
24
|
testTransform({test: {abc: 'xyz', def: 'abc'}}, {abc: 'xyz', def: 'abc'});
|
25
25
|
});
|
26
26
|
|
27
|
+
it('should not unwrap pluralName when object is expected', function() {
|
28
|
+
var data = {tests: [1, 2, 3], id: 4};
|
29
|
+
expect(railsRootWrapper.unwrap({data: data}, Resource, true)).toEqualData({data: data});
|
30
|
+
});
|
31
|
+
|
27
32
|
function testTransform(wrappedData, unwrappedData) {
|
28
33
|
expect(railsRootWrapper.wrap(unwrappedData, Resource)).toEqualData(wrappedData);
|
29
34
|
expect(railsRootWrapper.unwrap({data: wrappedData}, Resource)).toEqualData({data: unwrappedData});
|
@@ -343,6 +343,52 @@ describe('railsSerializer', function () {
|
|
343
343
|
expect(result['num_books']).toBe(2);
|
344
344
|
});
|
345
345
|
|
346
|
+
it('should add custom attribute to collection from function', function() {
|
347
|
+
var result, authorWithPublisher, serializedBooks,
|
348
|
+
serializer = createSerializer(function () {
|
349
|
+
this.serializeWith('books', factory(function() {
|
350
|
+
this.add('publisherId', function(book) {
|
351
|
+
return book.publisher.id;
|
352
|
+
});
|
353
|
+
}));
|
354
|
+
});
|
355
|
+
authorWithPublisher = {
|
356
|
+
books: [
|
357
|
+
{id: 1, publisher: {id: 3}},
|
358
|
+
{id: 2, publisher: {id: 4}}
|
359
|
+
]
|
360
|
+
};
|
361
|
+
serializedBooks = [
|
362
|
+
{id: 1, publisher_id: 3, publisher: {id:3}},
|
363
|
+
{id: 2, publisher_id: 4, publisher: {id:4}}
|
364
|
+
];
|
365
|
+
|
366
|
+
result = serializer.serialize(authorWithPublisher);
|
367
|
+
expect(result['books']).toEqual(serializedBooks);
|
368
|
+
});
|
369
|
+
|
370
|
+
it('should add custom attribute to collection from constant value', function() {
|
371
|
+
var result, authorWithPublisher, serializedBooks,
|
372
|
+
serializer = createSerializer(function () {
|
373
|
+
this.serializeWith('books', factory(function() {
|
374
|
+
this.add('publisherId', 3);
|
375
|
+
}));
|
376
|
+
});
|
377
|
+
authorWithPublisher = {
|
378
|
+
books: [
|
379
|
+
{id: 1, publisher: {id: 3}},
|
380
|
+
{id: 2, publisher: {id: 4}}
|
381
|
+
]
|
382
|
+
};
|
383
|
+
serializedBooks = [
|
384
|
+
{id: 1, publisher_id: 3, publisher: {id:3}},
|
385
|
+
{id: 2, publisher_id: 3, publisher: {id:4}}
|
386
|
+
];
|
387
|
+
|
388
|
+
result = serializer.serialize(authorWithPublisher);
|
389
|
+
expect(result['books']).toEqual(serializedBooks);
|
390
|
+
});
|
391
|
+
|
346
392
|
it('should use custom serializer for books', function () {
|
347
393
|
var result, serializedBooks, underscored,
|
348
394
|
serializer = createSerializer(function () {
|
@@ -6,10 +6,10 @@
|
|
6
6
|
result[angular.isArray(data) ? resource.config.pluralName : resource.config.name] = data;
|
7
7
|
return result;
|
8
8
|
},
|
9
|
-
unwrap: function (response, resource) {
|
9
|
+
unwrap: function (response, resource, isObject) {
|
10
10
|
if (response.data && response.data.hasOwnProperty(resource.config.name)) {
|
11
11
|
response.data = response.data[resource.config.name];
|
12
|
-
} else if (response.data && response.data.hasOwnProperty(resource.config.pluralName)) {
|
12
|
+
} else if (response.data && response.data.hasOwnProperty(resource.config.pluralName) && !isObject) {
|
13
13
|
response.data = response.data[resource.config.pluralName];
|
14
14
|
}
|
15
15
|
|
@@ -114,7 +114,7 @@
|
|
114
114
|
if (value) {
|
115
115
|
var response = this.constructor.deserialize({data: value});
|
116
116
|
if (this.constructor.config.rootWrapping) {
|
117
|
-
response = railsRootWrapper.unwrap(response, this.constructor);
|
117
|
+
response = railsRootWrapper.unwrap(response, this.constructor, true);
|
118
118
|
}
|
119
119
|
angular.extend(this, response.data);
|
120
120
|
}
|
@@ -582,7 +582,7 @@
|
|
582
582
|
|
583
583
|
if (config.rootWrapping) {
|
584
584
|
promise = promise.then(function (response) {
|
585
|
-
return railsRootWrapper.unwrap(response, config.resourceConstructor);
|
585
|
+
return railsRootWrapper.unwrap(response, config.resourceConstructor, false);
|
586
586
|
});
|
587
587
|
}
|
588
588
|
|
@@ -416,11 +416,22 @@
|
|
416
416
|
|
417
417
|
if (angular.isObject(result)) {
|
418
418
|
angular.forEach(this.customSerializedAttributes, function (value, key) {
|
419
|
-
if (angular.
|
420
|
-
|
421
|
-
|
419
|
+
if (angular.isArray(result)) {
|
420
|
+
angular.forEach(result, function (item, index) {
|
421
|
+
var itemValue = value;
|
422
|
+
if (angular.isFunction(value)) {
|
423
|
+
itemValue = itemValue.call(item, item);
|
424
|
+
}
|
425
|
+
|
426
|
+
self.serializeAttribute(item, key, itemValue);
|
427
|
+
});
|
428
|
+
} else {
|
429
|
+
if (angular.isFunction(value)) {
|
430
|
+
value = value.call(data, data);
|
431
|
+
}
|
422
432
|
|
423
|
-
|
433
|
+
self.serializeAttribute(result, key, value);
|
434
|
+
}
|
424
435
|
});
|
425
436
|
}
|
426
437
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: angularjs-rails-resource
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tommy Odom
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2015-02-07 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: A small AngularJS add-on for integrating with Rails via JSON more easily.
|
15
15
|
email:
|