This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 2 files changed +41
-4
lines changed
2 files changed +41
-4
lines changed Original file line number Diff line number Diff line change @@ -492,8 +492,6 @@ angular.module('ngResource', ['ng']).
492
492
493
493
value . $resolved = true ;
494
494
495
- ( success || noop ) ( value , response . headers ) ;
496
-
497
495
response . resource = value ;
498
496
499
497
return response ;
@@ -503,8 +501,15 @@ angular.module('ngResource', ['ng']).
503
501
( error || noop ) ( response ) ;
504
502
505
503
return $q . reject ( response ) ;
506
- } ) . then ( responseInterceptor , responseErrorInterceptor ) ;
504
+ } ) ;
507
505
506
+ promise = promise . then (
507
+ function ( response ) {
508
+ var value = responseInterceptor ( response ) ;
509
+ ( success || noop ) ( value , response . headers ) ;
510
+ return value ;
511
+ } ,
512
+ responseErrorInterceptor ) ;
508
513
509
514
if ( ! isInstanceCall ) {
510
515
// we are creating instance / collection
Original file line number Diff line number Diff line change @@ -630,6 +630,38 @@ describe("resource", function() {
630
630
631
631
expect ( cc . url ) . toBe ( '/new-id' ) ;
632
632
} ) ;
633
+
634
+ it ( 'should pass the same transformed value to success callbacks and to promises' , function ( ) {
635
+ $httpBackend . expect ( 'GET' , '/CreditCard' ) . respond ( 200 , { value : 'original' } ) ;
636
+
637
+ var transformResponse = function ( response ) {
638
+ return { value : 'transformed' } ;
639
+ } ;
640
+
641
+ var CreditCard = $resource ( '/CreditCard' , { } , {
642
+ call : {
643
+ method : 'get' ,
644
+ interceptor : { response : transformResponse }
645
+ }
646
+ } ) ;
647
+
648
+ var successValue ,
649
+ promiseValue ;
650
+
651
+ var cc = new CreditCard ( { name : 'Me' } ) ;
652
+
653
+ var req = cc . $call ( { } , function ( result ) {
654
+ successValue = result ;
655
+ } ) ;
656
+ req . then ( function ( result ) {
657
+ promiseValue = result ;
658
+ } ) ;
659
+
660
+ $httpBackend . flush ( ) ;
661
+ expect ( successValue ) . toEqual ( { value : 'transformed' } ) ;
662
+ expect ( promiseValue ) . toEqual ( { value : 'transformed' } ) ;
663
+ expect ( successValue ) . toBe ( promiseValue ) ;
664
+ } ) ;
633
665
} ) ;
634
666
635
667
@@ -1084,4 +1116,4 @@ describe('resource', function() {
1084
1116
} ) ;
1085
1117
1086
1118
1087
- } ) ;
1119
+ } ) ;
You can’t perform that action at this time.
0 commit comments