Ensure the fetch request blocks are given a relative URL if possible to make path matching easier

This commit is contained in:
Blake Watters
2012-10-14 16:03:12 -04:00
parent 4ee29df72f
commit 1811d5250d
2 changed files with 36 additions and 1 deletions

View File

@@ -7,6 +7,11 @@
//
#import "RKTestEnvironment.h"
#import "RKManagedObjectRequestOperation.h"
@interface RKManagedObjectRequestOperation ()
- (NSSet *)localObjectsFromFetchRequestsMatchingRequestURL:(NSError **)error;
@end
@interface RKManagedObjectRequestOperationTest : RKTestCase
@end
@@ -18,4 +23,26 @@
}
- (void)testFetchRequestBlocksAreInvokedWithARelativeURL
{
NSURL *baseURL = [NSURL URLWithString:@"http://restkit.org/api/v1/"];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"categories/1234" relativeToURL:baseURL]];
RKObjectMapping *mapping = [RKObjectMapping requestMapping];
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:mapping pathPattern:@"categories/:categoryID" keyPath:nil statusCodes:[NSIndexSet indexSetWithIndex:200]];
responseDescriptor.baseURL = baseURL;
RKManagedObjectRequestOperation *operation = [[RKManagedObjectRequestOperation alloc] initWithRequest:request responseDescriptors:@[responseDescriptor]];
__block NSURL *blockURL = nil;
RKFetchRequestBlock fetchRequesBlock = ^NSFetchRequest *(NSURL *URL) {
blockURL = URL;
return nil;
};
operation.fetchRequestBlocks = @[fetchRequesBlock];
NSError *error;
[operation localObjectsFromFetchRequestsMatchingRequestURL:&error];
expect(blockURL).notTo.beNil();
expect([blockURL.baseURL absoluteString]).to.equal(@"http://restkit.org/api/v1/");
expect(blockURL.relativePath).to.equal(@"categories/1234");
}
@end