Skip to content

Commit

Permalink
Fix and test a regression in 56c1c0d; closes #22
Browse files Browse the repository at this point in the history
  • Loading branch information
clayallsopp committed Apr 3, 2014
1 parent 3cafc2c commit d12d028
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Routable/Routable.m
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,11 @@ - (RouterParams *)routerParamsForUrl:(NSString *)url {
}

NSArray *givenParts = url.pathComponents;
NSArray *legacyParts = [url componentsSeparatedByString:@"/"];
if ([legacyParts count] != [givenParts count]) {
NSLog(@"Routable Warning - your URL %@ has empty path components - this will throw an error in an upcoming release", url);
givenParts = legacyParts;
}

RouterParams *openParams = nil;
for (NSString *routerUrl in self.routes.allKeys) {
Expand Down
25 changes: 25 additions & 0 deletions RoutableTests/RoutableTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
@interface UserController : UIViewController

@property (readwrite, nonatomic, copy) NSString *userId;
@property (readwrite, nonatomic, copy) NSString *userName;

- (id)initWithRouterParams:(NSDictionary *)params;
@end
Expand All @@ -21,6 +22,7 @@ @implementation UserController
- (id)initWithRouterParams:(NSDictionary *)params {
if ((self = [self initWithNibName:nil bundle:nil])) {
self.userId = [params objectForKey:@"user_id"];
self.userName = [params objectForKey:@"user_name"];
}
return self;
}
Expand Down Expand Up @@ -50,6 +52,7 @@ @interface RoutableTests()
@end

#define USER_ID [(UserController *)self.router.navigationController.topViewController userId]
#define USER_NAME [(UserController *)self.router.navigationController.topViewController userName]
#define STATIC_USER_ID [(StaticController *)self.router.navigationController.topViewController userId]

@implementation RoutableTests
Expand Down Expand Up @@ -78,6 +81,28 @@ - (void)test_basicRoute {
STAssertTrue([USER_ID isEqualToString:@"4"], @"Should have an ID of 4");
}

- (void)test_basicRouteWithMultipleComponents {
[self.router map:@"users/:user_id/:user_name" toController:[UserController class]];

[self.router open:@"users/4/clay"];

STAssertTrue([USER_ID isEqualToString:@"4"], @"Should have an ID of 4");
STAssertTrue([USER_NAME isEqualToString:@"clay"], @"Name should be Clay");
}

- (void)test_basicRouteWithEmptyComponents {
[self.router map:@"users/:user_id/:user_name" toController:[UserController class]];

[self.router open:@"users//clay"];

STAssertTrue([USER_ID isEqualToString:@""], @"Should have an empty ID");
STAssertTrue([USER_NAME isEqualToString:@"clay"], @"Name should be Clay");

[self.router open:@"users/ /clay"];
STAssertTrue([USER_ID isEqualToString:@" "], @"Should have an empty ID");
STAssertTrue([USER_NAME isEqualToString:@"clay"], @"Name should be Clay");
}

- (void)test_emptyRoute {
[self.router map:@"users" toController:[UserController class]];

Expand Down

0 comments on commit d12d028

Please sign in to comment.