File tree 2 files changed +22
-2
lines changed
2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -52,6 +52,10 @@ export default class Model extends StaticModel {
52
52
return this [ this . primaryKey ( ) ]
53
53
}
54
54
55
+ updateMethod ( ) {
56
+ return 'PUT'
57
+ }
58
+
55
59
custom ( ...args ) {
56
60
57
61
if ( args . length === 0 ) {
@@ -403,7 +407,7 @@ export default class Model extends StaticModel {
403
407
_update ( ) {
404
408
return this . request (
405
409
this . _reqConfig ( {
406
- method : 'PUT' ,
410
+ method : this . updateMethod ( ) ,
407
411
url : this . endpoint ( ) ,
408
412
data : this
409
413
} )
@@ -429,7 +433,7 @@ export default class Model extends StaticModel {
429
433
sync ( params ) {
430
434
return this . request (
431
435
this . _reqConfig ( {
432
- method : 'PUT' ,
436
+ method : this . updateMethod ( ) ,
433
437
url : this . endpoint ( ) ,
434
438
data : params
435
439
} )
Original file line number Diff line number Diff line change @@ -383,6 +383,22 @@ describe('Model methods', () => {
383
383
comment . save ( )
384
384
} )
385
385
386
+ test ( 'save() method makes a PATCH request when method is set using `updateMethod`' , async ( ) => {
387
+ let post
388
+
389
+ axiosMock . onAny ( ) . reply ( ( config ) => {
390
+ expect ( config . method ) . toEqual ( 'patch' )
391
+ expect ( config . data ) . toEqual ( JSON . stringify ( post ) )
392
+ expect ( config . url ) . toEqual ( 'http://localhost/posts/1' )
393
+
394
+ return [ 200 , { } ]
395
+ } )
396
+
397
+ post = new Post ( { id : 1 , title : 'Cool!' } )
398
+ post . updateMethod = ( ) => 'PATCH'
399
+ await post . save ( )
400
+ } )
401
+
386
402
test ( 'save() method makes a PATCH request when method is set using `config`' , async ( ) => {
387
403
let post
388
404
You can’t perform that action at this time.
0 commit comments