Skip to content

Commit 61665fa

Browse files
committed
fix(record): Adds support for array properties on patch mask
Fixes #217
1 parent 472d8c7 commit 61665fa

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/module/api/record-api.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ RMModule.factory('RMRecordApi', ['RMUtils', function(Utils) {
293293
url: url,
294294
// Use special mask for patches, mask everything that is not in the patch list.
295295
data: this.$wrap(function(_name) {
296+
_name = _name.replace('[]', '');
296297
for(var i = 0, l = _patch.length; i < l; i++) {
297298
if(_name === _patch[i] ||
298299
_name.indexOf(_patch[i] + '.') === 0 ||

test/model-spec.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,13 @@ describe('Restmod model class:', function() {
163163
var bike;
164164

165165
beforeEach(function() {
166-
bike = Bike.$new(1).$extend({ brand: 'Santa Cruz', model: 'Bronson', wheelSz: 27.5, dim: { height: 10, width: 10 } });
166+
bike = Bike.$new(1).$extend({
167+
brand: 'Santa Cruz',
168+
model: 'Bronson',
169+
wheelSz: 27.5,
170+
dim: { height: 10, width: 10 },
171+
parts: [ { name: 'i25', brand: 'WTB' }, { name: 'MTX', brand: 'Sunn' } ]
172+
});
167173
});
168174

169175
it('should begin a PATCH action', function() {
@@ -197,6 +203,18 @@ describe('Restmod model class:', function() {
197203
$httpBackend.flush();
198204
});
199205

206+
it('should include a complete array of objects if array property name is given', function() {
207+
bike.$save(['parts']);
208+
$httpBackend.expectPATCH('/api/bikes/1', { parts: [ { name: 'i25', brand: 'WTB' }, { name: 'MTX', brand: 'Sunn' } ] }).respond(200, {});
209+
$httpBackend.flush();
210+
});
211+
212+
it('should include every arrays object property if a nested property is given', function() {
213+
bike.$save(['parts.name']);
214+
$httpBackend.expectPATCH('/api/bikes/1', { parts: [ { name: 'i25' }, { name: 'MTX' } ] }).respond(200, {});
215+
$httpBackend.flush();
216+
});
217+
200218
});
201219

202220
it('should call callbacks in proper order when creating', function() {

0 commit comments

Comments
 (0)