This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 2 files changed +21
-0
lines changed
2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -493,6 +493,13 @@ angular.module('ngResource', ['ng']).
493
493
shallowClearAndCopy ( value || { } , this ) ;
494
494
}
495
495
496
+ Resource . prototype . toJSON = function ( ) {
497
+ var data = extend ( { } , this ) ;
498
+ delete data . $promise ;
499
+ delete data . $resolved ;
500
+ return data ;
501
+ } ;
502
+
496
503
forEach ( actions , function ( action , name ) {
497
504
var hasBody = / ^ ( P O S T | P U T | P A T C H ) $ / i. test ( action . method ) ;
498
505
Original file line number Diff line number Diff line change @@ -653,6 +653,20 @@ describe("resource", function() {
653
653
expect ( person2 ) . toEqual ( jasmine . any ( Person ) ) ;
654
654
} ) ;
655
655
656
+ it ( 'should not include $promise and $resolved when resource is toJson\'ed' , function ( ) {
657
+ $httpBackend . expect ( 'GET' , '/CreditCard/123' ) . respond ( { id : 123 , number : '9876' } ) ;
658
+ var cc = CreditCard . get ( { id : 123 } ) ;
659
+ $httpBackend . flush ( ) ;
660
+
661
+ expect ( cc . $promise ) . toBeDefined ( ) ;
662
+ expect ( cc . $resolved ) . toBe ( true ) ;
663
+
664
+ var json = JSON . parse ( angular . toJson ( cc ) ) ;
665
+ expect ( json . $promise ) . not . toBeDefined ( ) ;
666
+ expect ( json . $resolved ) . not . toBeDefined ( ) ;
667
+ expect ( json ) . toEqual ( { id : 123 , number : '9876' } ) ;
668
+ } ) ;
669
+
656
670
describe ( 'promise api' , function ( ) {
657
671
658
672
var $rootScope ;
You can’t perform that action at this time.
0 commit comments