Resource Path -> Path

This commit is contained in:
Blake Watters
2012-09-04 21:24:33 -04:00
parent d31b7a13c2
commit 627f6f5b7b
19 changed files with 177 additions and 210 deletions

View File

@@ -159,7 +159,7 @@
if (! localObjects) return NO;
for (id object in localObjects) {
if (NO == [results containsObject:object]) {
RKLogDebug(@"Deleting orphaned object %@: not found in result set and expected at this resource path", object);
RKLogDebug(@"Deleting orphaned object %@: not found in result set and expected at this URL", object);
[self.privateContext performBlockAndWait:^{
[self.privateContext deleteObject:object];
}];

View File

@@ -85,7 +85,7 @@ RKMappingResult, RKRequestDescriptor, RKResponseDescriptor;
<h4>Configuring Routes</h4>
Routing is the process of transforming objects and actions (as defined by HTTP verbs) into resource paths. RestKit ships
Routing is the process of transforming objects and actions (as defined by HTTP verbs) into paths. RestKit ships
<h4>Initializing a Core Data Object Store</h4>
<h3>Loading Remote Objects</h3>
@@ -185,16 +185,16 @@ RKMappingResult, RKRequestDescriptor, RKResponseDescriptor;
/// @name Building Object Request Operations
/**
Creates and returns an RKObjectPaginator instance targeting the specified resource path pattern.
Creates and returns an RKObjectPaginator instance targeting the specified path pattern.
The paginator instantiated will be initialized with an RKURL built by appending the resourcePathPattern to the
The paginator instantiated will be initialized with a URL built by appending the pathPattern to the
baseURL of the client.
@return The newly created paginator instance.
@see RKObjectMappingProvider
@see RKObjectPaginator
*/
//- (RKObjectPaginator *)paginatorWithResourcePathPattern:(NSString *)resourcePathPattern;
//- (RKObjectPaginator *)paginatorWithPathPattern:(NSString *)pathPattern;
////////////////////////////////////////////////////////
/// @name Registered Object Loaders
@@ -295,6 +295,7 @@ RKMappingResult, RKRequestDescriptor, RKResponseDescriptor;
- (void)addResponseDescriptorsFromArray:(NSArray *)responseDescriptors;
- (void)removeResponseDescriptor:(RKResponseDescriptor *)responseDescriptor;
// Moves to RKObjectManager+CoreData
@property (nonatomic, readonly) NSArray *fetchRequestBlocks;
- (void)addFetchRequestBlock:(RKFetchRequestBlock)block;

View File

@@ -188,7 +188,7 @@ static NSOperationQueue *defaultMappingQueue = nil;
/////////////////////////////////////////////////////////////
#pragma mark - Object Collection Loaders
//- (RKObjectPaginator *)paginatorWithResourcePathPattern:(NSString *)resourcePathPattern
//- (RKObjectPaginator *)paginatorWithPathPattern:(NSString *)pathPattern
//{
// RKURL *patternURL = [[self baseURL] URLByAppendingResourcePath:resourcePathPattern];
// RKObjectPaginator *paginator = [RKObjectPaginator paginatorWithPatternURL:patternURL

View File

@@ -60,19 +60,19 @@
//- (id)initWithPatternURL:(RKURL *)patternURL mappingProvider:(RKObjectMappingProvider *)mappingProvider;
//
///**
// A RKURL with a resource path pattern for building a complete URL from
// A RKURL with a path pattern for building a complete URL from
// which to load the paginated resource collection. The patterned resource
// path will be evaluated against the state of the paginator object itself.
//
// For example, given a paginated collection of data at the /articles resource path,
// the patterned resource path may look like:
// For example, given a paginated collection of data at the /articles path,
// the path pattern may look like:
//
// /articles?per_page=:perPage&page_number=:currentPage
//
// When the pattern is evaluated against the state of the paginator, this will
// yield a complete resource path that can be used to load the specified page. Given
// yield a complete path that can be used to load the specified page. Given
// a paginator configured with 100 objects per page and a current page number of 3,
// the resource path of the pagination URL would become:
// the path portion of the pagination URL would become:
//
// /articles?per_page=100&page_number=3
//

View File

@@ -21,23 +21,23 @@
#import "RKHTTPUtilities.h"
/**
The RKRoute class models a single routable resource path pattern in use by the application. A route
can be combined with an RKURL base URL and interpolated with an object to produce a new fully hydrated
URL object. Routes are always instantiated with a resource path pattern and metadata to provide for
The RKRoute class models a single routable path pattern in use by the application. A route
can be combined with an NSURL base URL and interpolated with an object to produce a new fully hydrated
URL object. Routes are always instantiated with a path pattern and metadata to provide for
the subsequent identification of the defined route.
There are three types of routes modeled by the RKRoute class:
1. Named Routes: A named route represents a single resource path and optional request method within
1. Named Routes: A named route represents a single path and optional request method within
the application. The route is not affiliated with any particular class. For example, one might
define a route with the name `@"airlines_list"` as a GET to /airlines.json
1. Class Routes: An class route represents a single resource path that is identified by object class
define a route with the name `@"airlines_list"` as a GET to the path '/airlines.json'.
1. Class Routes: An class route represents a single path that is identified by object class
and request method for which it is appropriate. For example, one might define a route for the class
`RKArticle` for a POST to /articles.json.
1. Relationship Routes: A relationship route represents a single resource path through which the relationship
`RKArticle` for a POST to the path '/articles.json'.
1. Relationship Routes: A relationship route represents a single path through which the relationship
of a parent object can be manipulated. For example, given an `RKArticle` and `RKComment` class, one
might define a relationship route for the `RKArticle` class's `@"comments"` relationship as pointing to
a GET to `@"/articles/:articleID/comments".
a GET to the path `@"/articles/:articleID/comments".
The RKRoute class is internally implemented as a class cluster and is not to be directly instantiated via alloc and
init.
@@ -70,55 +70,55 @@
@property (nonatomic, assign, readonly) RKRequestMethod method;
/**
The resource path pattern of the receiver.
The path pattern of the receiver.
A SOCKit pattern that describes the resource path of the route. Required and used by all route types.
A SOCKit pattern that describes the format of the path portion of URL's generated from the receiver. Required and used by all route types.
@see SOCPattern
*/
@property (nonatomic, strong, readonly) NSString *resourcePathPattern;
@property (nonatomic, strong, readonly) NSString *pathPattern;
/**
A Boolean value that determines if the resource path pattern should be escaped when evaluated.
A Boolean value that determines if the path pattern should be escaped when evaluated.
*Default*: NO
*/
@property (nonatomic, assign) BOOL shouldEscapeResourcePath;
@property (nonatomic, assign) BOOL shouldEscapePath;
///-----------------------------------------------------------------------------
/// @name Instantiating Routes
///-----------------------------------------------------------------------------
/**
Creates and returns a new named route object with the given name, resource path pattern and method.
Creates and returns a new named route object with the given name, path pattern and method.
@param name A unique identifying name for the route.
@param resourcePathPattern A SOCKit pattern describing the resource path represented by the route.
@param pathPattern A SOCKit pattern describing the format of URL paths generated from the route.
@param method The request method of the route.
@return A new named route object with the given name, resource path pattern and request method.
@return A new named route object with the given name, path pattern and request method.
*/
+ (id)routeWithName:(NSString *)name resourcePathPattern:(NSString *)resourcePathPattern method:(RKRequestMethod)method;
+ (id)routeWithName:(NSString *)name pathPattern:(NSString *)pathPattern method:(RKRequestMethod)method;
/**
Creates and returns a new class route object with the given object class, resource path pattern and method.
Creates and returns a new class route object with the given object class, path pattern and method.
@param objectClass The class that is represented by the route.
@param resourcePathPattern A SOCKit pattern describing the resource path represented by the route.
@param pathPattern A SOCKit pattern describing the format of URL paths generated from the route.
@param method The request method of the route.
@return A new class route object with the given object class, resource path pattern and request method.
@return A new class route object with the given object class, path pattern and request method.
*/
+ (id)routeWithClass:(Class)objectClass resourcePathPattern:(NSString *)resourcePathPattern method:(RKRequestMethod)method;
+ (id)routeWithClass:(Class)objectClass pathPattern:(NSString *)pathPattern method:(RKRequestMethod)method;
/**
Creates and returns a new relationship route object with the given relationship name, object class, resource path pattern and method.
Creates and returns a new relationship route object with the given relationship name, object class, path pattern and method.
@param relationshipName The name of the relationship represented by the route.
@param objectClass The class containing the relationship represented by the route.
@param resourcePathPattern A SOCKit pattern describing the resource path represented by the route.
@param pathPattern A SOCKit pattern describing the format of URL paths generated from the route.
@param method The request method of the route.
@return A new class route object with the given object class, resource path pattern and request method.
@return A new class route object with the given object class, path pattern and request method.
*/
+ (id)routeWithRelationshipName:(NSString *)name objectClass:(Class)objectClass resourcePathPattern:(NSString *)resourcePathPattern method:(RKRequestMethod)method;
+ (id)routeWithRelationshipName:(NSString *)name objectClass:(Class)objectClass pathPattern:(NSString *)pathPattern method:(RKRequestMethod)method;
///-----------------------------------------------------------------------------
/// @name Inspecting Route Types

View File

@@ -24,7 +24,7 @@
@property (nonatomic, strong, readwrite) NSString *name;
@property (nonatomic, strong, readwrite) Class objectClass;
@property (nonatomic, assign, readwrite) RKRequestMethod method;
@property (nonatomic, strong, readwrite) NSString *resourcePathPattern;
@property (nonatomic, strong, readwrite) NSString *pathPattern;
@end
@interface RKNamedRoute : RKRoute
@@ -39,36 +39,37 @@
@implementation RKRoute
+ (id)routeWithName:(NSString *)name resourcePathPattern:(NSString *)resourcePathPattern method:(RKRequestMethod)method
+ (id)routeWithName:(NSString *)name pathPattern:(NSString *)pathPattern method:(RKRequestMethod)method
{
NSParameterAssert(name);
NSParameterAssert(resourcePathPattern);
NSParameterAssert(pathPattern);
RKNamedRoute *route = [RKNamedRoute new];
route.name = name;
route.resourcePathPattern = resourcePathPattern;
route.pathPattern = pathPattern;
route.method = method;
return route;
}
+ (id)routeWithClass:(Class)objectClass resourcePathPattern:(NSString *)resourcePathPattern method:(RKRequestMethod)method
+ (id)routeWithClass:(Class)objectClass pathPattern:(NSString *)pathPattern method:(RKRequestMethod)method
{
NSParameterAssert(objectClass);
NSParameterAssert(resourcePathPattern);
NSParameterAssert(pathPattern);
RKClassRoute *route = [RKClassRoute new];
route.objectClass = objectClass;
route.resourcePathPattern = resourcePathPattern;
route.pathPattern = pathPattern;
route.method = method;
return route;
}
+ (id)routeWithRelationshipName:(NSString *)relationshipName objectClass:(Class)objectClass resourcePathPattern:(NSString *)resourcePathPattern method:(RKRequestMethod)method
+ (id)routeWithRelationshipName:(NSString *)relationshipName objectClass:(Class)objectClass pathPattern:(NSString *)pathPattern method:(RKRequestMethod)method
{
NSParameterAssert(relationshipName);
NSParameterAssert(objectClass);
NSParameterAssert(pathPattern);
RKRelationshipRoute *route = [RKRelationshipRoute new];
route.name = relationshipName;
route.objectClass = objectClass;
route.resourcePathPattern = resourcePathPattern;
route.pathPattern = pathPattern;
route.method = method;
return route;
}
@@ -114,8 +115,8 @@
- (NSString *)description
{
return [NSString stringWithFormat:@"<%@: %p name=%@ method=%@ resourcePathPattern=%@>",
NSStringFromClass([self class]), self, self.name, RKStringFromRequestMethod(self.method), self.resourcePathPattern];
return [NSString stringWithFormat:@"<%@: %p name=%@ method=%@ pathPattern=%@>",
NSStringFromClass([self class]), self, self.name, RKStringFromRequestMethod(self.method), self.pathPattern];
}
@end
@@ -129,9 +130,9 @@
- (NSString *)description
{
return [NSString stringWithFormat:@"<%@: %p objectClass=%@ method=%@ resourcePathPattern=%@>",
return [NSString stringWithFormat:@"<%@: %p objectClass=%@ method=%@ pathPattern=%@>",
NSStringFromClass([self class]), self, NSStringFromClass(self.objectClass),
RKStringFromRequestMethod(self.method), self.resourcePathPattern];
RKStringFromRequestMethod(self.method), self.pathPattern];
}
@end
@@ -145,9 +146,9 @@
- (NSString *)description
{
return [NSString stringWithFormat:@"<%@: %p relationshipName=%@ objectClass=%@ method=%@ resourcePathPattern=%@>",
return [NSString stringWithFormat:@"<%@: %p relationshipName=%@ objectClass=%@ method=%@ pathPattern=%@>",
NSStringFromClass([self class]), self, self.name, NSStringFromClass(self.objectClass),
RKStringFromRequestMethod(self.method), self.resourcePathPattern];
RKStringFromRequestMethod(self.method), self.pathPattern];
}
@end

View File

@@ -159,12 +159,4 @@ extern RKRequestMethod const RKRequestMethodAny;
*/
- (RKRoute *)routeForObject:(id)object method:(RKRequestMethod)method;
/**
Retrieves all routes with a given resource path pattern.
@param resourcePathPattern The resource path pattern of the routes to be retrieved.
@return An array containing all routes with a resource path pattern equal to the given value.
*/
- (NSArray *)routesWithResourcePathPattern:(NSString *)resourcePathPattern;
@end

View File

@@ -196,16 +196,4 @@ RKRequestMethod const RKRequestMethodAny = RKRequestMethodInvalid;
return nil;
}
- (NSArray *)routesWithResourcePathPattern:(NSString *)resourcePathPattern
{
NSMutableArray *routes = [NSMutableArray array];
for (RKRoute *route in self.routes) {
if ([route.resourcePathPattern isEqualToString:resourcePathPattern]) {
[routes addObject:route];
}
}
return [NSArray arrayWithArray:routes];
}
@end

View File

@@ -28,13 +28,13 @@
that are used by the application.
URL's can be generated by the router in three ways:
1. By name. Named routes link a symbolic name with a resource path and an HTTP request method.
1. By name. Named routes link a symbolic name with a path and an HTTP request method.
2. By object. Routes can be defined by class and HTTP request method. When a URL is requested from the
router for an object, the router will identify the most appropriate route for the object
and instantiate an RKURL with the route's resource path pattern and interpolate it against the object.
and instantiate an RKURL with the route's path pattern and interpolate it against the object.
3. By object relationship. Routes can be defined for relationships to other objects. When a URL is requested
from the router for a relationship, the router will retrieve the appropriate route for the relationship
from the route set and interpolate the route's resource path pattern against the source object.
from the route set and interpolate the route's path pattern against the source object.
@see RKURL
@see RKRoute
@@ -72,15 +72,15 @@
Generates a URL for the route with the given name.
The route set is searched for a route with the given name and a new RKURL object is instantiated
with the baseURL of the receiver and the resource path pattern of the route, optionally interpolated
with the baseURL of the receiver and the path pattern of the route, optionally interpolated
with a given object. If a pointer to an RKRequestMethod variable is provided, the HTTP method
for the route will be assigned to the reference.
@param routeName The name of the route for which a URL is to be generated.
@param method A pointer to an RKRequestMethod variable in which to store the HTTP method associated
with the named route.
@param object An optional object against which to interpolate the resource path pattern.
@return A new URL object constructed by appending the resource path pattern to the baseURL of the
@param object An optional object against which to interpolate the path pattern.
@return A new URL object constructed by appending the path pattern to the baseURL of the
receiver and interpolating against a given object; or nil if no route was found with the given
name.
*/
@@ -93,12 +93,12 @@
the object being routed. If there is not an exact match for the object's class, the inheritance
hierarchy is searched until a match is found or all possible routes are exhausted. Exact HTTP request
matches are favored over the wildcard method (RKRequestMethodAny). Once the appropriate route is identified,
a new RKURL object is instantiated with the baseURL of the receiver and the resource path pattern of the route,
a new RKURL object is instantiated with the baseURL of the receiver and the path pattern of the route,
interpolated against the object being routed.
@param object The object for which a URL is to be generated.
@param method The HTTP method for which the URL is to be generated.
@return A new URL object constructed by appending the resource path pattern of the route for the object and
@return A new URL object constructed by appending the path pattern of the route for the object and
HTTP method to the baseURL of the receiver, interpolated against the routed object; or nil if no route was found
for the given object and HTTP method.
*/
@@ -109,12 +109,12 @@
The route set is searched for a route that matches the relationship of the given object's class and the given
HTTP method. If a matching route is found, a new RKURL object is instantiated with the baseURL of the receiver
and the resource path pattern of the route, interpolated against the object being routed.
and the path pattern of the route, interpolated against the object being routed.
@param relationshipName The name of the relationship for which a URL is to be generated.
@param object The object for which the URL is to be generated.
@param method The HTTP method for which the URL is to be generated.
@return A new URL object constructed by appending the resource path pattern of the route for the given object's
@return A new URL object constructed by appending the path pattern of the route for the given object's
relationship and HTTP method to the baseURL of the receiver, interpolated against the routed object; or nil if no
route was found for the given relationship, object and HTTP method.
*/

View File

@@ -70,9 +70,9 @@
- (NSString *)pathFromRoute:(RKRoute *)route forObject:(id)object
{
if (! object) return route.resourcePathPattern;
RKPathMatcher *pathMatcher = [RKPathMatcher matcherWithPattern:route.resourcePathPattern];
return [pathMatcher pathFromObject:object addingEscapes:route.shouldEscapeResourcePath];
if (! object) return route.pathPattern;
RKPathMatcher *pathMatcher = [RKPathMatcher matcherWithPattern:route.pathPattern];
return [pathMatcher pathFromObject:object addingEscapes:route.shouldEscapePath];
}
@end

View File

@@ -27,17 +27,16 @@
@interface NSString (RKAdditions)
/**
Returns a resource path from a dictionary of query parameters URL encoded and appended
This is a convenience method for constructing a new resource path that includes a query. For example,
when given a resourcePath of /contacts and a dictionary of parameters containing foo=bar and color=red,
Returns a new path from a dictionary of query parameters URL encoded and appended
This is a convenience method for constructing a new path that includes a query. For example,
when given a path of /contacts and a dictionary of parameters containing foo=bar and color=red,
will return /contacts?foo=bar&amp;color=red
*NOTE *- Assumes that the resource path does not already contain any query parameters.
@param queryParameters A dictionary of query parameters to be URL encoded and appended to the resource path
@return A new resource path with the query parameters appended
*NOTE *- Assumes that the path does not already contain any query parameters.
@param queryParameters A dictionary of query parameters to be URL encoded and appended to the path
@return A new path with the query parameters appended.
*/
- (NSString *)stringByAppendingQueryParameters:(NSDictionary *)queryParameters;
- (NSString *)appendQueryParams:(NSDictionary *)queryParams DEPRECATED_ATTRIBUTE;
/**
Convenience method for generating a path against the properties of an object. Takes
@@ -46,7 +45,7 @@
For example, given an 'article' object with an 'articleID' property of 12345
[@"articles/:articleID" interpolateWithObject:article] would generate @"articles/12345"
This functionality is the basis for resource path generation in the Router.
This functionality is the basis for path generation in the Router.
@param object The object to interpolate the properties against
@see RKMakePathWithObject

View File

@@ -45,12 +45,6 @@ RK_FIX_CATEGORY_BUG(NSString_RKAdditions)
return [NSString stringWithString:self];
}
// Deprecated
- (NSString *)appendQueryParams:(NSDictionary *)queryParams
{
return [self stringByAppendingQueryParameters:queryParams];
}
- (NSString *)interpolateWithObject:(id)object addingEscapes:(BOOL)addEscapes
{
NSCAssert(object != NULL, @"Object provided is invalid; cannot create a path from a NULL object");

View File

@@ -22,10 +22,10 @@
@class SOCPattern;
/**
This class performs pattern matching and parameter parsing of strings, usually resource paths.
It provides much of the necessary tools to map a given resource path to local objects (the inverse
This class performs pattern matching and parameter parsing of strings, typically paths.
It provides much of the necessary tools to map a given path to local objects (the inverse
of RKRouter's function). This makes it easier to implement RKManagedObjectCache, and generate fetched
requests from a given resource path. There are two means of instantiating and using a matcher object
requests from a given path. There are two means of instantiating and using a matcher object
in order to provide more flexibility in implementations, and to improve efficiency by eliminating
repetitive and costly pattern initializations.
@@ -38,7 +38,7 @@
@property (copy, readonly) NSDictionary *queryParameters;
/**
Creates an RKPathMatcher starting from a resource path string. This method should be followed by
Creates an RKPathMatcher starting from a path string. This method should be followed by
matchesPattern:tokenizeQueryStrings:parsedArguments:
@param pathString The string to evaluate and parse, such as /districts/tx/upper/?apikey=GC5512354
@@ -90,7 +90,7 @@
+ (RKPathMatcher *)matcherWithPattern:(NSString *)patternString;
/**
Determines if the provided resource path string matches a pattern, and yields a dictionary with the resulting
Determines if the given path string matches a pattern, and yields a dictionary with the resulting
matched key/value pairs. Use of this method should be preceded by matcherWithPattern:
@param pathString The string to evaluate and parse, such as /districts/tx/upper/?apikey=GC5512354
@@ -101,16 +101,16 @@
- (BOOL)matchesPath:(NSString *)pathString tokenizeQueryStrings:(BOOL)shouldTokenize parsedArguments:(NSDictionary **)arguments;
/**
This generates a resource path by interpolating the properties of the 'object' argument, assuming the existence
Generates a new path by interpolating the properties of the 'object' argument, assuming the existence
of a previously specified pattern established via matcherWithPattern:. Otherwise, this method is identical in
function to RKMakePathWithObject (in fact it is a shortcut for this method).
For example, given an 'article' object with an 'articleID' property value of 12345 ...
RKPathMatcher *matcher = [RKPathMatcher matcherWithPattern:@"/articles/:articleID"];
NSString *resourcePath = [matcher pathFromObject:article];
NSString *path = [matcher pathFromObject:article];
... will produce a 'resourcePath' containing the string "/articles/12345"
... will produce a 'path' containing the string "/articles/12345"
@param object The object containing the properties to interpolate.
@return A string with the object's interpolated property values inserted into the receiver's established pattern.
@@ -120,16 +120,16 @@
- (NSString *)pathFromObject:(id)object;
/**
This generates a resource path by interpolating the properties of the 'object' argument, assuming the existence
Generates a path by interpolating the properties of the 'object' argument, assuming the existence
of a previously specified pattern established via matcherWithPattern:. Otherwise, this method is identical in
function to RKMakePathWithObject (in fact it is a shortcut for this method).
For example, given an 'article' object with an 'articleID' property value of 12345 and a code of "This/That"...
RKPathMatcher *matcher = [RKPathMatcher matcherWithPattern:@"/articles/:articleID/:code"];
NSString *resourcePath = [matcher pathFromObject:article addingEscapes:YES];
NSString *path = [matcher pathFromObject:article addingEscapes:YES];
... will produce a 'resourcePath' containing the string "/articles/12345/This%2FThat"
... will produce a 'path' containing the string "/articles/12345/This%2FThat"
@param object The object containing the properties to interpolate.
@param addEscapes Conditionally add percent escapes to the interpolated property values

View File

@@ -1,5 +1,5 @@
//
// RKCoding.h
// RKSerialization.h
// RestKit
//
// Created by Blake Watters on 10/1/10.

View File

@@ -118,7 +118,7 @@
RKObjectManager *objectManager = [RKTestFactory objectManager];
[objectManager.mappingProvider setObjectMapping:humanMapping
forResourcePathPattern:@"/JSON/humans/all.json"
forpathPattern:@"/JSON/humans/all.json"
withFetchRequestBlock:^ (NSString *resourcePath) {
return fetchRequest;
}];
@@ -183,7 +183,7 @@
assertThatInteger(count, is(equalToInteger(2)));
[objectManager.mappingProvider setMapping:humanMapping forKeyPath:@"human"];
[objectManager.mappingProvider setObjectMapping:humanMapping forResourcePathPattern:@"/coredata/etag" withFetchRequestBlock:^NSFetchRequest *(NSString *resourcePath) {
[objectManager.mappingProvider setObjectMapping:humanMapping forpathPattern:@"/coredata/etag" withFetchRequestBlock:^NSFetchRequest *(NSString *resourcePath) {
return fetchRequest;
}];

View File

@@ -41,7 +41,7 @@
- (void)testAddingRoute
{
RKRouteSet *router = [RKRouteSet new];
RKRoute *route = [RKRoute routeWithName:@"test_router" resourcePathPattern:@"/routes" method:RKRequestMethodAny];
RKRoute *route = [RKRoute routeWithName:@"test_router" pathPattern:@"/routes" method:RKRequestMethodAny];
[router addRoute:route];
assertThat([router allRoutes], hasCountOf(1));
}
@@ -49,7 +49,7 @@
- (void)testRemovingRoute
{
RKRouteSet *router = [RKRouteSet new];
RKRoute *route = [RKRoute routeWithName:@"test_router" resourcePathPattern:@"/routes" method:RKRequestMethodAny];
RKRoute *route = [RKRoute routeWithName:@"test_router" pathPattern:@"/routes" method:RKRequestMethodAny];
[router addRoute:route];
assertThat([router allRoutes], hasCountOf(1));
[router removeRoute:route];
@@ -59,7 +59,7 @@
- (void)testCannotAddARouteThatIsAlreadyAdded
{
RKRouteSet *router = [RKRouteSet new];
RKRoute *route = [RKRoute routeWithName:@"test_router" resourcePathPattern:@"/routes" method:RKRequestMethodAny];
RKRoute *route = [RKRoute routeWithName:@"test_router" pathPattern:@"/routes" method:RKRequestMethodAny];
[router addRoute:route];
STAssertThrowsSpecificNamed([router addRoute:route], NSException, NSInternalInconsistencyException, @"Cannot add a route that is already added to the router.");
}
@@ -67,27 +67,27 @@
- (void)testCannotAddARouteWithAnExistingName
{
RKRouteSet *router = [RKRouteSet new];
RKRoute *route1 = [RKRoute routeWithName:@"test_router" resourcePathPattern:@"/routes" method:RKRequestMethodAny];
RKRoute *route1 = [RKRoute routeWithName:@"test_router" pathPattern:@"/routes" method:RKRequestMethodAny];
[router addRoute:route1];
RKRoute *route2 = [RKRoute routeWithName:@"test_router" resourcePathPattern:@"/routes2" method:RKRequestMethodAny];
RKRoute *route2 = [RKRoute routeWithName:@"test_router" pathPattern:@"/routes2" method:RKRequestMethodAny];
STAssertThrowsSpecificNamed([router addRoute:route2], NSException, NSInternalInconsistencyException, @"Cannot add a route with the same name as an existing route.");
}
- (void)testCanAddARouteWithAnExistingResourcePathPattern
{
RKRouteSet *router = [RKRouteSet new];
RKRoute *route1 = [RKRoute routeWithName:@"test_router" resourcePathPattern:@"/routes" method:RKRequestMethodAny];
RKRoute *route1 = [RKRoute routeWithName:@"test_router" pathPattern:@"/routes" method:RKRequestMethodAny];
[router addRoute:route1];
RKRoute *route2 = [RKRoute routeWithName:@"test_router2" resourcePathPattern:@"/routes" method:RKRequestMethodAny];
STAssertNoThrowSpecificNamed([router addRoute:route2], NSException, NSInternalInconsistencyException, @"Cannot add a route with the same resource path pattern as an existing route.");
RKRoute *route2 = [RKRoute routeWithName:@"test_router2" pathPattern:@"/routes" method:RKRequestMethodAny];
STAssertNoThrowSpecificNamed([router addRoute:route2], NSException, NSInternalInconsistencyException, @"Cannot add a route with the same path pattern as an existing route.");
}
- (void)testCannotAddARouteWithAnExistingObjectClassAndMethod
{
RKRouteSet *router = [RKRouteSet new];
RKRoute *routeWithObjectClassAndMethod = [RKRoute routeWithClass:[RKTestUser class] resourcePathPattern:@"/routes" method:RKRequestMethodGET];
RKRoute *routeWithObjectClassAndDifferentMethod = [RKRoute routeWithClass:[RKTestUser class] resourcePathPattern:@"/routes" method:RKRequestMethodPOST];
RKRoute *routeWithObjectClassAndDifferentPath = [RKRoute routeWithClass:[RKTestUser class] resourcePathPattern:@"/routes2" method:RKRequestMethodPOST];
RKRoute *routeWithObjectClassAndMethod = [RKRoute routeWithClass:[RKTestUser class] pathPattern:@"/routes" method:RKRequestMethodGET];
RKRoute *routeWithObjectClassAndDifferentMethod = [RKRoute routeWithClass:[RKTestUser class] pathPattern:@"/routes" method:RKRequestMethodPOST];
RKRoute *routeWithObjectClassAndDifferentPath = [RKRoute routeWithClass:[RKTestUser class] pathPattern:@"/routes2" method:RKRequestMethodPOST];
[router addRoute:routeWithObjectClassAndMethod];
STAssertNoThrowSpecificNamed([router addRoute:routeWithObjectClassAndDifferentMethod], NSException, NSInternalInconsistencyException, @"Cannot add a route with the same class and method as an existing route.");
@@ -98,9 +98,9 @@
- (void)testCannotAddARouteForAnExistingRelationshipNameAndMethod
{
RKRouteSet *router = [RKRouteSet new];
RKRoute *routeWithObjectClassAndMethod = [RKRoute routeWithRelationshipName:@"friends" objectClass:[RKTestUser class] resourcePathPattern:@"/friends" method:RKRequestMethodGET];
RKRoute *routeWithObjectClassAndDifferentMethod = [RKRoute routeWithRelationshipName:@"friends" objectClass:[RKTestUser class] resourcePathPattern:@"/friends" method:RKRequestMethodPOST];
RKRoute *routeWithIdenticalClassAndMethod = [RKRoute routeWithRelationshipName:@"friends" objectClass:[RKTestUser class] resourcePathPattern:@"/friends" method:RKRequestMethodGET];
RKRoute *routeWithObjectClassAndMethod = [RKRoute routeWithRelationshipName:@"friends" objectClass:[RKTestUser class] pathPattern:@"/friends" method:RKRequestMethodGET];
RKRoute *routeWithObjectClassAndDifferentMethod = [RKRoute routeWithRelationshipName:@"friends" objectClass:[RKTestUser class] pathPattern:@"/friends" method:RKRequestMethodPOST];
RKRoute *routeWithIdenticalClassAndMethod = [RKRoute routeWithRelationshipName:@"friends" objectClass:[RKTestUser class] pathPattern:@"/friends" method:RKRequestMethodGET];
[router addRoute:routeWithObjectClassAndMethod];
STAssertNoThrowSpecificNamed([router addRoute:routeWithObjectClassAndDifferentMethod], NSException, NSInternalInconsistencyException, @"Cannot add a relationship route with the same name and class as an existing route.");
@@ -111,26 +111,26 @@
- (void)testCanAddARouteWithAnExistingObjectClassIfMethodIsAny
{
RKRouteSet *router = [RKRouteSet new];
RKRoute *route1 = [RKRoute routeWithClass:[RKTestUser class] resourcePathPattern:@"/routes" method:RKRequestMethodAny];
RKRoute *route1 = [RKRoute routeWithClass:[RKTestUser class] pathPattern:@"/routes" method:RKRequestMethodAny];
[router addRoute:route1];
RKRoute *route2 = [RKRoute routeWithClass:[RKTestUser class] resourcePathPattern:@"/routes" method:RKRequestMethodPOST];
RKRoute *route2 = [RKRoute routeWithClass:[RKTestUser class] pathPattern:@"/routes" method:RKRequestMethodPOST];
STAssertNoThrowSpecificNamed([router addRoute:route2], NSException, NSInternalInconsistencyException, @"Cannot add a route with the same class and method as an existing route.");
}
- (void)testCannotRemoveARouteThatDoesNotExistInRouter
{
RKRouteSet *router = [RKRouteSet new];
RKRoute *route = [RKRoute routeWithName:@"fake" resourcePathPattern:@"whatever" method:RKRequestMethodGET];
RKRoute *route = [RKRoute routeWithName:@"fake" pathPattern:@"whatever" method:RKRequestMethodGET];
STAssertThrowsSpecificNamed([router removeRoute:route], NSException, NSInternalInconsistencyException, @"Cannot remove a route that is not added to the router.");
}
- (void)testAllRoutes
{
RKRouteSet *router = [RKRouteSet new];
RKRoute *route1 = [RKRoute routeWithName:@"test_router" resourcePathPattern:@"/routes" method:RKRequestMethodAny];
RKRoute *route1 = [RKRoute routeWithName:@"test_router" pathPattern:@"/routes" method:RKRequestMethodAny];
[router addRoute:route1];
RKRoute *route2 = [RKRoute routeWithName:@"test_router2" resourcePathPattern:@"/routes2" method:RKRequestMethodAny];
RKRoute *route2 = [RKRoute routeWithName:@"test_router2" pathPattern:@"/routes2" method:RKRequestMethodAny];
[router addRoute:route2];
assertThat([router allRoutes], contains(route1, route2, nil));
}
@@ -138,11 +138,11 @@
- (void)testNamedRoutes
{
RKRouteSet *router = [RKRouteSet new];
RKRoute *route1 = [RKRoute routeWithName:@"test_router" resourcePathPattern:@"/routes" method:RKRequestMethodAny];
RKRoute *route1 = [RKRoute routeWithName:@"test_router" pathPattern:@"/routes" method:RKRequestMethodAny];
[router addRoute:route1];
RKRoute *route2 = [RKRoute routeWithName:@"test_router2" resourcePathPattern:@"/routes2" method:RKRequestMethodAny];
RKRoute *route2 = [RKRoute routeWithName:@"test_router2" pathPattern:@"/routes2" method:RKRequestMethodAny];
[router addRoute:route2];
RKRoute *route3 = [RKRoute routeWithClass:[RKTestUser class] resourcePathPattern:@"/routes2" method:RKRequestMethodPUT];
RKRoute *route3 = [RKRoute routeWithClass:[RKTestUser class] pathPattern:@"/routes2" method:RKRequestMethodPUT];
[router addRoute:route3];
assertThat([router namedRoutes], contains(route1, route2, nil));
}
@@ -150,11 +150,11 @@
- (void)testClassRoutes
{
RKRouteSet *router = [RKRouteSet new];
RKRoute *route1 = [RKRoute routeWithName:@"test_router" resourcePathPattern:@"/routes" method:RKRequestMethodAny];
RKRoute *route1 = [RKRoute routeWithName:@"test_router" pathPattern:@"/routes" method:RKRequestMethodAny];
[router addRoute:route1];
RKRoute *route2 = [RKRoute routeWithName:@"test_router2" resourcePathPattern:@"/routes2" method:RKRequestMethodAny];
RKRoute *route2 = [RKRoute routeWithName:@"test_router2" pathPattern:@"/routes2" method:RKRequestMethodAny];
[router addRoute:route2];
RKRoute *route3 = [RKRoute routeWithClass:[RKTestUser class] resourcePathPattern:@"/routes2" method:RKRequestMethodPUT];
RKRoute *route3 = [RKRoute routeWithClass:[RKTestUser class] pathPattern:@"/routes2" method:RKRequestMethodPUT];
[router addRoute:route3];
assertThat([router classRoutes], contains(route3, nil));
}
@@ -162,7 +162,7 @@
- (void)testHasRouteForName
{
RKRouteSet *router = [RKRouteSet new];
RKRoute *route = [RKRoute routeWithName:@"test_router" resourcePathPattern:@"/routes" method:RKRequestMethodAny];
RKRoute *route = [RKRoute routeWithName:@"test_router" pathPattern:@"/routes" method:RKRequestMethodAny];
[router addRoute:route];
assertThat([router routeForName:@"test_router"], is(notNilValue()));
assertThat([router routeForName:@"test_router2"], is(nilValue()));
@@ -171,33 +171,25 @@
- (void)testRouteForName
{
RKRouteSet *router = [RKRouteSet new];
RKRoute *route = [RKRoute routeWithName:@"test_router" resourcePathPattern:@"/routes" method:RKRequestMethodAny];
RKRoute *route = [RKRoute routeWithName:@"test_router" pathPattern:@"/routes" method:RKRequestMethodAny];
[router addRoute:route];
assertThat([router routeForName:@"test_router"], is(equalTo(route)));
}
- (void)testRouteForResourcePathPattern
{
RKRouteSet *router = [RKRouteSet new];
RKRoute *route = [RKRoute routeWithName:@"test_router" resourcePathPattern:@"/routes" method:RKRequestMethodAny];
[router addRoute:route];
assertThat([router routesWithResourcePathPattern:@"/routes"], contains(route, nil));
}
- (void)testAddRouteWithName
{
RKRouteSet *router = [RKRouteSet new];
[router addRoute:[RKRoute routeWithName:@"testing" resourcePathPattern:@"/route" method:RKRequestMethodGET]];
[router addRoute:[RKRoute routeWithName:@"testing" pathPattern:@"/route" method:RKRequestMethodGET]];
RKRoute *route = [router routeForName:@"testing"];
assertThat(route.name, is(equalTo(@"testing")));
assertThat(route.resourcePathPattern, is(equalTo(@"/route")));
assertThat(route.pathPattern, is(equalTo(@"/route")));
assertThatInteger(route.method, is(equalToInteger(RKRequestMethodGET)));
}
- (void)testAddRouteWithClassAndMethod
{
RKRouteSet *router = [RKRouteSet new];
[router addRoute:[RKRoute routeWithClass:[RKTestUser class] resourcePathPattern:@"/users/:userID" method:RKRequestMethodGET]];
[router addRoute:[RKRoute routeWithClass:[RKTestUser class] pathPattern:@"/users/:userID" method:RKRequestMethodGET]];
RKRoute *route = [router routeForClass:[RKTestUser class] method:RKRequestMethodGET];
assertThat(route.objectClass, is(equalTo([RKTestUser class])));
assertThatInteger(route.method, is(equalToInteger(RKRequestMethodGET)));
@@ -206,7 +198,7 @@
- (void)testAddRouteWithClass
{
RKRouteSet *router = [RKRouteSet new];
[router addRoute:[RKRoute routeWithClass:[RKTestUser class] resourcePathPattern:@"/users/:userID" method:RKRequestMethodAny]];
[router addRoute:[RKRoute routeWithClass:[RKTestUser class] pathPattern:@"/users/:userID" method:RKRequestMethodAny]];
RKRoute *route = [router routeForClass:[RKTestUser class] method:RKRequestMethodGET];
assertThat(route.objectClass, is(equalTo([RKTestUser class])));
assertThatInteger(route.method, is(equalToInteger(RKRequestMethodAny)));
@@ -215,22 +207,22 @@
- (void)testRouteForObjectAndMethodWithExactMatch
{
RKRouteSet *router = [RKRouteSet new];
[router addRoute:[RKRoute routeWithClass:[RKTestUser class] resourcePathPattern:@"/users/:userID" method:RKRequestMethodGET]];
[router addRoute:[RKRoute routeWithClass:[RKTestUser class] pathPattern:@"/users/:userID" method:RKRequestMethodGET]];
RKTestUser *user = [RKTestUser new];
RKRoute *route = [router routeForObject:user method:RKRequestMethodGET];
assertThat(route, is(notNilValue()));
assertThat(route.resourcePathPattern, is(equalTo(@"/users/:userID")));
assertThat(route.pathPattern, is(equalTo(@"/users/:userID")));
assertThatInteger(route.method, is(equalToInteger(RKRequestMethodGET)));
}
- (void)testRouteForObjectAndMethodWithSuperclassMatch
{
RKRouteSet *router = [RKRouteSet new];
[router addRoute:[RKRoute routeWithClass:[RKTestObject class] resourcePathPattern:@"/users/:userID" method:RKRequestMethodGET]];
[router addRoute:[RKRoute routeWithClass:[RKTestObject class] pathPattern:@"/users/:userID" method:RKRequestMethodGET]];
RKTestSubclassedObject *subclassedObject = [RKTestSubclassedObject new];
RKRoute *route = [router routeForObject:subclassedObject method:RKRequestMethodGET];
assertThat(route, is(notNilValue()));
assertThat(route.resourcePathPattern, is(equalTo(@"/users/:userID")));
assertThat(route.pathPattern, is(equalTo(@"/users/:userID")));
assertThat(route.objectClass, is(equalTo([RKTestObject class])));
assertThatInteger(route.method, is(equalToInteger(RKRequestMethodGET)));
}
@@ -238,13 +230,13 @@
- (void)testRouteForObjectFindsNearestSuperclassMatch
{
RKRouteSet *router = [RKRouteSet new];
[router addRoute:[RKRoute routeWithClass:[RKTestObject class] resourcePathPattern:@"/users/:userID" method:RKRequestMethodGET]];
[router addRoute:[RKRoute routeWithClass:[RKTestSubclassedObject class] resourcePathPattern:@"/subclasses/users/:userID" method:RKRequestMethodGET]];
[router addRoute:[RKRoute routeWithClass:[RKTestDeeplySubclassedObject class] resourcePathPattern:@"/deeply/subclassed/users/:userID" method:RKRequestMethodGET]];
[router addRoute:[RKRoute routeWithClass:[RKTestObject class] pathPattern:@"/users/:userID" method:RKRequestMethodGET]];
[router addRoute:[RKRoute routeWithClass:[RKTestSubclassedObject class] pathPattern:@"/subclasses/users/:userID" method:RKRequestMethodGET]];
[router addRoute:[RKRoute routeWithClass:[RKTestDeeplySubclassedObject class] pathPattern:@"/deeply/subclassed/users/:userID" method:RKRequestMethodGET]];
RKTestDeeplySubclassedObject *deeplySubclassedObject = [RKTestDeeplySubclassedObject new];
RKRoute *route = [router routeForObject:deeplySubclassedObject method:RKRequestMethodGET];
assertThat(route, is(notNilValue()));
assertThat(route.resourcePathPattern, is(equalTo(@"/deeply/subclassed/users/:userID")));
assertThat(route.pathPattern, is(equalTo(@"/deeply/subclassed/users/:userID")));
assertThat(route.objectClass, is(equalTo([RKTestDeeplySubclassedObject class])));
assertThatInteger(route.method, is(equalToInteger(RKRequestMethodGET)));
}
@@ -252,13 +244,13 @@
- (void)testRouteForObjectPrefersSuperclassAnyMatchOverDistantParentMethodMatch
{
RKRouteSet *router = [RKRouteSet new];
[router addRoute:[RKRoute routeWithClass:[RKTestObject class] resourcePathPattern:@"/users/:userID" method:RKRequestMethodPOST]];
[router addRoute:[RKRoute routeWithClass:[RKTestSubclassedObject class] resourcePathPattern:@"/subclasses/users/:userID" method:RKRequestMethodAny]];
[router addRoute:[RKRoute routeWithClass:[RKTestDeeplySubclassedObject class] resourcePathPattern:@"/deeply/subclassed/users/:userID" method:RKRequestMethodGET]];
[router addRoute:[RKRoute routeWithClass:[RKTestObject class] pathPattern:@"/users/:userID" method:RKRequestMethodPOST]];
[router addRoute:[RKRoute routeWithClass:[RKTestSubclassedObject class] pathPattern:@"/subclasses/users/:userID" method:RKRequestMethodAny]];
[router addRoute:[RKRoute routeWithClass:[RKTestDeeplySubclassedObject class] pathPattern:@"/deeply/subclassed/users/:userID" method:RKRequestMethodGET]];
RKTestDeeplySubclassedObject *deeplySubclassedObject = [RKTestDeeplySubclassedObject new];
RKRoute *route = [router routeForObject:deeplySubclassedObject method:RKRequestMethodPOST];
assertThat(route, is(notNilValue()));
assertThat(route.resourcePathPattern, is(equalTo(@"/subclasses/users/:userID")));
assertThat(route.pathPattern, is(equalTo(@"/subclasses/users/:userID")));
assertThat(route.objectClass, is(equalTo([RKTestSubclassedObject class])));
assertThatInteger(route.method, is(equalToInteger(RKRequestMethodAny)));
}
@@ -266,9 +258,9 @@
- (void)testRoutesForClassReturnsAllRoutesForClass
{
RKRouteSet *router = [RKRouteSet new];
[router addRoute:[RKRoute routeWithClass:[RKTestObject class] resourcePathPattern:@"/users/:userID" method:RKRequestMethodGET]];
[router addRoute:[RKRoute routeWithClass:[RKTestObject class] resourcePathPattern:@"/users/:userID" method:RKRequestMethodPOST]];
[router addRoute:[RKRoute routeWithClass:[RKTestSubclassedObject class] resourcePathPattern:@"/users/:userID" method:RKRequestMethodGET]];
[router addRoute:[RKRoute routeWithClass:[RKTestObject class] pathPattern:@"/users/:userID" method:RKRequestMethodGET]];
[router addRoute:[RKRoute routeWithClass:[RKTestObject class] pathPattern:@"/users/:userID" method:RKRequestMethodPOST]];
[router addRoute:[RKRoute routeWithClass:[RKTestSubclassedObject class] pathPattern:@"/users/:userID" method:RKRequestMethodGET]];
NSArray *routes = [router routesForClass:[RKTestObject class]];
assertThat(routes, hasCountOf(2));
}
@@ -276,9 +268,9 @@
- (void)testRouteForObjectReturnsAllRoutesForClassAndSuperclasses
{
RKRouteSet *router = [RKRouteSet new];
[router addRoute:[RKRoute routeWithClass:[RKTestObject class] resourcePathPattern:@"/users/:userID" method:RKRequestMethodGET]];
[router addRoute:[RKRoute routeWithClass:[RKTestObject class] resourcePathPattern:@"/users/:userID" method:RKRequestMethodPOST]];
[router addRoute:[RKRoute routeWithClass:[RKTestSubclassedObject class] resourcePathPattern:@"/users/:userID" method:RKRequestMethodGET]];
[router addRoute:[RKRoute routeWithClass:[RKTestObject class] pathPattern:@"/users/:userID" method:RKRequestMethodGET]];
[router addRoute:[RKRoute routeWithClass:[RKTestObject class] pathPattern:@"/users/:userID" method:RKRequestMethodPOST]];
[router addRoute:[RKRoute routeWithClass:[RKTestSubclassedObject class] pathPattern:@"/users/:userID" method:RKRequestMethodGET]];
RKTestSubclassedObject *subclassed = [[RKTestSubclassedObject new] autorelease];
NSArray *routes = [router routesForObject:subclassed];
@@ -288,61 +280,61 @@
- (void)testRouteForObjectAndMethodFavorsExactMatchOverSuperclass
{
RKRouteSet *router = [RKRouteSet new];
[router addRoute:[RKRoute routeWithClass:[RKTestObject class] resourcePathPattern:@"/users/:userID/1" method:RKRequestMethodGET]];
[router addRoute:[RKRoute routeWithClass:[RKTestObject class] resourcePathPattern:@"/users/:userID/2" method:RKRequestMethodPOST]];
[router addRoute:[RKRoute routeWithClass:[RKTestSubclassedObject class] resourcePathPattern:@"/users/:userID/3" method:RKRequestMethodGET]];
[router addRoute:[RKRoute routeWithClass:[RKTestObject class] pathPattern:@"/users/:userID/1" method:RKRequestMethodGET]];
[router addRoute:[RKRoute routeWithClass:[RKTestObject class] pathPattern:@"/users/:userID/2" method:RKRequestMethodPOST]];
[router addRoute:[RKRoute routeWithClass:[RKTestSubclassedObject class] pathPattern:@"/users/:userID/3" method:RKRequestMethodGET]];
RKTestSubclassedObject *subclassed = [[RKTestSubclassedObject new] autorelease];
RKRoute *route = [router routeForObject:subclassed method:RKRequestMethodGET];
assertThat(route.objectClass, is(equalTo([RKTestSubclassedObject class])));
assertThatInteger(route.method, is(equalToInteger(RKRequestMethodGET)));
assertThat(route.resourcePathPattern, is(equalTo(@"/users/:userID/3")));
assertThat(route.pathPattern, is(equalTo(@"/users/:userID/3")));
}
- (void)testRouteForObjectAndMethodFavorsWildcardMatchOnExactClassOverSuperclass
{
RKRouteSet *router = [RKRouteSet new];
[router addRoute:[RKRoute routeWithClass:[RKTestObject class] resourcePathPattern:@"/users/:userID/1" method:RKRequestMethodGET]];
[router addRoute:[RKRoute routeWithClass:[RKTestObject class] resourcePathPattern:@"/users/:userID/2" method:RKRequestMethodPOST]];
[router addRoute:[RKRoute routeWithClass:[RKTestSubclassedObject class] resourcePathPattern:@"/users/:userID/3" method:RKRequestMethodAny]];
[router addRoute:[RKRoute routeWithClass:[RKTestObject class] pathPattern:@"/users/:userID/1" method:RKRequestMethodGET]];
[router addRoute:[RKRoute routeWithClass:[RKTestObject class] pathPattern:@"/users/:userID/2" method:RKRequestMethodPOST]];
[router addRoute:[RKRoute routeWithClass:[RKTestSubclassedObject class] pathPattern:@"/users/:userID/3" method:RKRequestMethodAny]];
RKTestSubclassedObject *subclassed = [[RKTestSubclassedObject new] autorelease];
RKRoute *route = [router routeForObject:subclassed method:RKRequestMethodGET];
assertThat(route.objectClass, is(equalTo([RKTestSubclassedObject class])));
assertThatInteger(route.method, is(equalToInteger(RKRequestMethodAny)));
assertThat(route.resourcePathPattern, is(equalTo(@"/users/:userID/3")));
assertThat(route.pathPattern, is(equalTo(@"/users/:userID/3")));
}
- (void)testRouteForObjectAndMethodFavorsExactSuperclassMethodMatchOverWildcard
{
RKRouteSet *router = [RKRouteSet new];
[router addRoute:[RKRoute routeWithClass:[RKTestObject class] resourcePathPattern:@"/users/:userID/1" method:RKRequestMethodGET]];
[router addRoute:[RKRoute routeWithClass:[RKTestObject class] resourcePathPattern:@"/users/:userID/2" method:RKRequestMethodAny]];
[router addRoute:[RKRoute routeWithClass:[RKTestObject class] pathPattern:@"/users/:userID/1" method:RKRequestMethodGET]];
[router addRoute:[RKRoute routeWithClass:[RKTestObject class] pathPattern:@"/users/:userID/2" method:RKRequestMethodAny]];
RKTestSubclassedObject *subclassed = [[RKTestSubclassedObject new] autorelease];
RKRoute *route = [router routeForObject:subclassed method:RKRequestMethodGET];
assertThat(route.objectClass, is(equalTo([RKTestObject class])));
assertThatInteger(route.method, is(equalToInteger(RKRequestMethodGET)));
assertThat(route.resourcePathPattern, is(equalTo(@"/users/:userID/1")));
assertThat(route.pathPattern, is(equalTo(@"/users/:userID/1")));
}
- (void)testRouteForObjectAndMethodFallsBackToSuperclassWildcardMatch
{
RKRouteSet *router = [RKRouteSet new];
[router addRoute:[RKRoute routeWithClass:[RKTestObject class] resourcePathPattern:@"/users/:userID/1" method:RKRequestMethodGET]];
[router addRoute:[RKRoute routeWithClass:[RKTestObject class] resourcePathPattern:@"/users/:userID/2" method:RKRequestMethodAny]];
[router addRoute:[RKRoute routeWithClass:[RKTestObject class] pathPattern:@"/users/:userID/1" method:RKRequestMethodGET]];
[router addRoute:[RKRoute routeWithClass:[RKTestObject class] pathPattern:@"/users/:userID/2" method:RKRequestMethodAny]];
RKTestSubclassedObject *subclassed = [[RKTestSubclassedObject new] autorelease];
RKRoute *route = [router routeForObject:subclassed method:RKRequestMethodPOST];
assertThat(route.objectClass, is(equalTo([RKTestObject class])));
assertThatInteger(route.method, is(equalToInteger(RKRequestMethodAny)));
assertThat(route.resourcePathPattern, is(equalTo(@"/users/:userID/2")));
assertThat(route.pathPattern, is(equalTo(@"/users/:userID/2")));
}
//- (void)testResourcePathForObject
//{
// RKRouter *router = [RKRouter new];
// [router addRoute:[RKRoute routeWithClass:[RKTestUser class] resourcePathPattern:@"/users/:userID" method:RKRequestMethodAny];
// [router addRoute:[RKRoute routeWithClass:[RKTestUser class] pathPattern:@"/users/:userID" method:RKRequestMethodAny];
// RKTestUser *user = [RKTestUser new];
// user.userID = [NSNumber numberWithInteger:12345];
// NSString *resourcePath = [router resourcePathForObject:user method:RKRequestMethodGET];
@@ -352,7 +344,7 @@
//- (void)testResourcePathForRouteNamed
//{
// RKRouter *router = [RKRouter new];
// [router addRoute:[RKRoute routeWithName:@"airlines_list" resourcePathPattern:@"/airlines.json"];
// [router addRoute:[RKRoute routeWithName:@"airlines_list" pathPattern:@"/airlines.json"];
// NSString *resourcePath = [router resourcePathForRouteNamed:@"airlines_list"];
// assertThat(resourcePath, is(equalTo(@"/airlines.json")));
//}
@@ -360,7 +352,7 @@
//- (void)testResourcePathForRouteNamedInterpolatedWithObject
//{
// RKRouter *router = [RKRouter new];
// [router addRoute:[RKRoute routeWithName:@"user_bookmarks_path" resourcePathPattern:@"/users/:userID/bookmarks"];
// [router addRoute:[RKRoute routeWithName:@"user_bookmarks_path" pathPattern:@"/users/:userID/bookmarks"];
// RKTestUser *user = [RKTestUser new];
// user.userID = [NSNumber numberWithInteger:12345];
// NSString *resourcePath = [router resourcePathForRouteNamed:@"user_bookmarks_path" interpolatedWithObject:user];
@@ -372,20 +364,20 @@
- (void)testRouteForRelationshipOfClass
{
RKRouteSet *router = [RKRouteSet new];
[router addRoute:[RKRoute routeWithRelationshipName:@"friends" objectClass:[RKTestUser class] resourcePathPattern:@"/friends" method:RKRequestMethodGET]];
[router addRoute:[RKRoute routeWithRelationshipName:@"friends" objectClass:[RKTestUser class] pathPattern:@"/friends" method:RKRequestMethodGET]];
RKRoute *route = [router routeForRelationship:@"friends" ofClass:[RKTestUser class] method:RKRequestMethodGET];
assertThat(route, is(notNilValue()));
assertThat(route.name, is(equalTo(@"friends")));
assertThat(route.resourcePathPattern, is(equalTo(@"/friends")));
assertThat(route.pathPattern, is(equalTo(@"/friends")));
assertThatInteger(route.method, is(equalToInteger(RKRequestMethodGET)));
}
- (void)testRoutesForRelationship
{
RKRouteSet *router = [RKRouteSet new];
[router addRoute:[RKRoute routeWithRelationshipName:@"friends" objectClass:[RKTestUser class] resourcePathPattern:@"/friends" method:RKRequestMethodGET]];
[router addRoute:[RKRoute routeWithRelationshipName:@"friends" objectClass:[RKTestUser class] resourcePathPattern:@"/friends" method:RKRequestMethodPOST]];
[router addRoute:[RKRoute routeWithRelationshipName:@"enemies" objectClass:[RKTestUser class] resourcePathPattern:@"/enemies" method:RKRequestMethodGET]];
[router addRoute:[RKRoute routeWithRelationshipName:@"friends" objectClass:[RKTestUser class] pathPattern:@"/friends" method:RKRequestMethodGET]];
[router addRoute:[RKRoute routeWithRelationshipName:@"friends" objectClass:[RKTestUser class] pathPattern:@"/friends" method:RKRequestMethodPOST]];
[router addRoute:[RKRoute routeWithRelationshipName:@"enemies" objectClass:[RKTestUser class] pathPattern:@"/enemies" method:RKRequestMethodGET]];
NSArray *routes = [router routesForRelationship:@"friends" ofClass:[RKTestUser class]];
assertThat(routes, hasCountOf(2));

View File

@@ -295,7 +295,7 @@
RKObjectMapping *serializationMapping = [mapping inverseMapping];
RKObjectManager *objectManager = [RKTestFactory objectManager];
[objectManager.router.routeSet addRoute:[RKRoute routeWithClass:[RKTestComplexUser class] resourcePathPattern:@"/204"method:RKRequestMethodAny]];
[objectManager.router.routeSet addRoute:[RKRoute routeWithClass:[RKTestComplexUser class] pathPattern:@"/204"method:RKRequestMethodAny]];
[objectManager.mappingProvider setSerializationMapping:serializationMapping forClass:[RKTestComplexUser class]];
RKTestComplexUser *user = [[RKTestComplexUser new] autorelease];
@@ -320,7 +320,7 @@
RKObjectMapping *serializationMapping = [mapping inverseMapping];
RKObjectManager *objectManager = [RKTestFactory objectManager];
[objectManager.router.routeSet addRoute:[RKRoute routeWithClass:[RKTestComplexUser class] resourcePathPattern:@"/notNestedUser" method:RKRequestMethodAny]];
[objectManager.router.routeSet addRoute:[RKRoute routeWithClass:[RKTestComplexUser class] pathPattern:@"/notNestedUser" method:RKRequestMethodAny]];
[objectManager.mappingProvider setSerializationMapping:serializationMapping forClass:[RKTestComplexUser class]];
RKTestComplexUser *user = [[RKTestComplexUser new] autorelease];
@@ -349,7 +349,7 @@
RKObjectManager *objectManager = [RKTestFactory objectManager];
[[RKParserRegistry sharedRegistry] setParserClass:[RKJSONParserJSONKit class] forMIMEType:@"text/html"];
[objectManager.router.routeSet addRoute:[RKRoute routeWithClass:[RKTestComplexUser class] resourcePathPattern:@"/noMIME" method:RKRequestMethodAny]];
[objectManager.router.routeSet addRoute:[RKRoute routeWithClass:[RKTestComplexUser class] pathPattern:@"/noMIME" method:RKRequestMethodAny]];
[objectManager.mappingProvider setSerializationMapping:serializationMapping forClass:[RKTestComplexUser class]];
RKTestComplexUser *user = [[RKTestComplexUser new] autorelease];
@@ -377,7 +377,7 @@
[targetMapping mapAttributes:@"ID", nil];
RKObjectManager *objectManager = [RKTestFactory objectManager];
[objectManager.router.routeSet addRoute:[RKRoute routeWithClass:[RKTestComplexUser class] resourcePathPattern:@"/notNestedUser" method:RKRequestMethodAny]];
[objectManager.router.routeSet addRoute:[RKRoute routeWithClass:[RKTestComplexUser class] pathPattern:@"/notNestedUser" method:RKRequestMethodAny]];
[objectManager.mappingProvider setSerializationMapping:serializationMapping forClass:[RKTestComplexUser class]];
RKTestComplexUser *user = [[RKTestComplexUser new] autorelease];
@@ -414,9 +414,9 @@
[targetMapping mapAttributes:@"ID", nil];
RKObjectManager *objectManager = [RKTestFactory objectManager];
[objectManager.router.routeSet addRoute:[RKRoute routeWithClass:[RKTestComplexUser class] resourcePathPattern:@"/notNestedUser" method:RKRequestMethodAny]];
[objectManager.router.routeSet addRoute:[RKRoute routeWithClass:[RKTestComplexUser class] pathPattern:@"/notNestedUser" method:RKRequestMethodAny]];
[objectManager.mappingProvider setSerializationMapping:serializationMapping forClass:[RKTestComplexUser class]];
[objectManager.mappingProvider setObjectMapping:targetMapping forResourcePathPattern:@"/notNestedUser"];
[objectManager.mappingProvider setObjectMapping:targetMapping forpathPattern:@"/notNestedUser"];
RKTestComplexUser *user = [[RKTestComplexUser new] autorelease];
user.firstname = @"Blake";
@@ -449,7 +449,7 @@
RKObjectMapping *serializationMapping = [mapping inverseMapping];
RKObjectManager *objectManager = [RKTestFactory objectManager];
[objectManager.router.routeSet addRoute:[RKRoute routeWithClass:[RKTestComplexUser class] resourcePathPattern:@"/notNestedUser" method:RKRequestMethodAny]];
[objectManager.router.routeSet addRoute:[RKRoute routeWithClass:[RKTestComplexUser class] pathPattern:@"/notNestedUser" method:RKRequestMethodAny]];
[objectManager.mappingProvider setSerializationMapping:serializationMapping forClass:[RKTestComplexUser class]];
RKTestComplexUser *user = [[RKTestComplexUser new] autorelease];
@@ -500,7 +500,7 @@
RKObjectManager *objectManager = [RKObjectManager managerWithBaseURL:[RKTestFactory baseURL]];
RKTestResponseLoader *responseLoader = [RKTestResponseLoader responseLoader];
RKObjectMappingProvider *mappingProvider = [RKObjectMappingProvider mappingProvider];
[mappingProvider setObjectMapping:userMapping forResourcePathPattern:@"/JSON/ComplexNestedUser.json"];
[mappingProvider setObjectMapping:userMapping forpathPattern:@"/JSON/ComplexNestedUser.json"];
RKURL *URL = [objectManager.baseURL URLByAppendingResourcePath:@"/JSON/ComplexNestedUser.json"];
RKObjectLoader *objectLoader = [RKObjectLoader loaderWithURL:URL mappingProvider:mappingProvider];
@@ -526,7 +526,7 @@
RKObjectManager *objectManager = [RKObjectManager managerWithBaseURL:[RKTestFactory baseURL]];
RKTestResponseLoader *responseLoader = [RKTestResponseLoader responseLoader];
RKObjectMappingProvider *mappingProvider = [RKObjectMappingProvider mappingProvider];
[mappingProvider setObjectMapping:userMapping forResourcePathPattern:@"/JSON/:name\\.json"];
[mappingProvider setObjectMapping:userMapping forpathPattern:@"/JSON/:name\\.json"];
RKURL *URL = [objectManager.baseURL URLByAppendingResourcePath:@"/JSON/ComplexNestedUser.json"];
RKObjectLoader *objectLoader = [RKObjectLoader loaderWithURL:URL mappingProvider:mappingProvider];
@@ -653,7 +653,7 @@
[objectManager.mappingQueue setSuspended:YES];
RKTestResponseLoader *responseLoader = [RKTestResponseLoader responseLoader];
[objectManager.mappingProvider setObjectMapping:userMapping forResourcePathPattern:@"/humans/1"];
[objectManager.mappingProvider setObjectMapping:userMapping forpathPattern:@"/humans/1"];
[objectManager loadObjectsAtResourcePath:@"/humans/1" delegate:nil];
[objectManager.client get:@"/empty/string" delegate:responseLoader];
[responseLoader waitForResponse];

View File

@@ -77,7 +77,7 @@
[humanSerialization addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"name" toKeyPath:@"name"]];
[provider setSerializationMapping:humanSerialization forClass:[RKHuman class]];
_objectManager.mappingProvider = provider;
[_objectManager.router.routeSet addRoute:[RKRoute routeWithClass:[RKHuman class] resourcePathPattern:@"/humans" method:RKRequestMethodPOST]];
[_objectManager.router.routeSet addRoute:[RKRoute routeWithClass:[RKHuman class] pathPattern:@"/humans" method:RKRequestMethodPOST]];
}
- (void)tearDown
@@ -186,7 +186,7 @@
- (void)testShouldPOSTAnObject
{
RKObjectManager *manager = [RKTestFactory objectManager];
[manager.router.routeSet addRoute:[RKRoute routeWithClass:[RKObjectMapperTestModel class] resourcePathPattern:@"/humans" method:RKRequestMethodPOST]];
[manager.router.routeSet addRoute:[RKRoute routeWithClass:[RKObjectMapperTestModel class] pathPattern:@"/humans" method:RKRequestMethodPOST]];
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[RKObjectMapperTestModel class]];
mapping.rootKeyPath = @"human";
@@ -210,7 +210,7 @@
- (void)testShouldNotSetAContentBodyOnAGET
{
RKObjectManager *objectManager = [RKTestFactory objectManager];
[objectManager.router.routeSet addRoute:[RKRoute routeWithClass:[RKObjectMapperTestModel class] resourcePathPattern:@"/humans/1" method:RKRequestMethodAny]];
[objectManager.router.routeSet addRoute:[RKRoute routeWithClass:[RKObjectMapperTestModel class] pathPattern:@"/humans/1" method:RKRequestMethodAny]];
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[RKObjectMapperTestModel class]];
[mapping mapAttributes:@"name", @"age", nil];
@@ -233,7 +233,7 @@
- (void)testShouldNotSetAContentBodyOnADELETE
{
RKObjectManager *objectManager = [RKTestFactory objectManager];
[objectManager.router.routeSet addRoute:[RKRoute routeWithClass:[RKObjectMapperTestModel class] resourcePathPattern:@"/humans/1" method:RKRequestMethodAny]];
[objectManager.router.routeSet addRoute:[RKRoute routeWithClass:[RKObjectMapperTestModel class] pathPattern:@"/humans/1" method:RKRequestMethodAny]];
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[RKObjectMapperTestModel class]];
[mapping mapAttributes:@"name", @"age", nil];
@@ -275,7 +275,7 @@
- (void)testShouldAllowYouToOverrideTheRoutedResourcePath
{
RKObjectManager *objectManager = [RKTestFactory objectManager];
[objectManager.router.routeSet addRoute:[RKRoute routeWithClass:[RKObjectMapperTestModel class] resourcePathPattern:@"/humans/2" method:RKRequestMethodAny]];
[objectManager.router.routeSet addRoute:[RKRoute routeWithClass:[RKObjectMapperTestModel class] pathPattern:@"/humans/2" method:RKRequestMethodAny]];
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[RKObjectMapperTestModel class]];
[mapping mapAttributes:@"name", @"age", nil];
[objectManager.mappingProvider registerMapping:mapping withRootKeyPath:@"human"];
@@ -373,7 +373,7 @@
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[RKObjectMapperTestModel class]];
mapping.rootKeyPath = @"human";
[objectManager.mappingProvider registerObjectMapping:mapping withRootKeyPath:@"human"];
[objectManager.router.routeSet addRoute:[RKRoute routeWithClass:[RKObjectMapperTestModel class] resourcePathPattern:@"/human/1" method:RKRequestMethodAny]];
[objectManager.router.routeSet addRoute:[RKRoute routeWithClass:[RKObjectMapperTestModel class] pathPattern:@"/human/1" method:RKRequestMethodAny]];
objectManager.serializationMIMEType = RKMIMETypeJSON;
RKTestResponseLoader *responseLoader = [RKTestResponseLoader responseLoader];

View File

@@ -1581,8 +1581,8 @@
// [mapping mapAttributes:@"name", @"website", nil];
// [mapping mapKeyPath:@"id" toAttribute:@"userID"];
//
// [objectManager.router.routeSet addRoute:[RKRoute routeWithClass:[RKTestUser class] resourcePathPattern:@"/humans/:userID" method:RKRequestMethodAny]];
// [objectManager.router.routeSet addRoute:[RKRoute routeWithClass:[RKTestUser class] resourcePathPattern:@"/humans" method:RKRequestMethodPOST]];
// [objectManager.router.routeSet addRoute:[RKRoute routeWithClass:[RKTestUser class] pathPattern:@"/humans/:userID" method:RKRequestMethodAny]];
// [objectManager.router.routeSet addRoute:[RKRoute routeWithClass:[RKTestUser class] pathPattern:@"/humans" method:RKRequestMethodPOST]];
// [objectManager.mappingProvider registerMapping:mapping withRootKeyPath:@"human"];
//
// RKTestUser *user = [RKTestUser new];