36 return [NSURL URLWithString:@RAILS_BASE_URL];
40 #pragma mark Person Class
65 post = [[
Post alloc] initWithSite:ActiveResourceKitTestsBaseURL()];
66 postComment = [[
PostComment alloc] initWithSite:[NSURL URLWithString:@"/posts/:post_id" relativeToURL:ActiveResourceKitTestsBaseURL()]];
84 [ryan
setAttributes:[NSDictionary dictionaryWithObjectsAndKeys:@"Ryan", @"first", @"Daigle", @"last", nil]];
89 STAssertNil([ryan service], nil);
90 STAssertFalse([ryan persisted], nil);
91 STAssertTrue([ryan isNew], nil);
92 STAssertTrue([ryan isNewRecord], nil);
96 STAssertEqualObjects([ryan valueForKey:
@"first"],
@"Ryan", nil);
97 STAssertEqualObjects([ryan valueForKey:
@"last"],
@"Daigle", nil);
112 [service setSite:[NSURL URLWithString:@"http://user:password@localhost:3000/resources/:resource_id?x=y;a=b"]];
113 STAssertEqualObjects([[service
site] scheme],
@"http", nil);
114 STAssertEqualObjects([[service
site] user],
@"user", nil);
115 STAssertEqualObjects([[service
site] password],
@"password", nil);
116 STAssertEqualObjects([[service
site] host],
@"localhost", nil);
117 STAssertEqualObjects([[service
site] port], [NSNumber numberWithInt:3000], nil);
118 STAssertEqualObjects([[service
site] path],
@"/resources/:resource_id", nil);
119 STAssertEqualObjects([[service
site] query],
@"x=y;a=b", nil);
127 [service setSite:[NSURL URLWithString:@"http://user:password@localhost:3000"]];
128 STAssertEqualObjects([[service
site] path],
@"", nil);
155 [service setPrefixSource:@"/resources/:resource_id"];
156 NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:1] forKey:@"resource_id"];
158 STAssertEqualObjects(prefix,
@"/resources/1", nil);
167 ARService *resourceService = [[
ARService alloc] initWithSite:[NSURL URLWithString:@"http://localhost/api/"] elementName:@"resource"];
169 STAssertEqualObjects([resourceService prefixWithOptions:nil],
@"/api/", nil);
170 STAssertEqualObjects([subresourceService prefixWithOptions:nil],
@"/api/resources/:resource_id/", nil);
176 [service setPrefixSource:@"/resources/:resource_id"];
177 NSString *prefix = [service
prefixWithOptions:[NSDictionary dictionaryWithObject:@"some text" forKey:@"resource_id"]];
178 STAssertEqualObjects(prefix,
@"/resources/some%20text", nil);
194 STAssertEqualObjects(elementPath,
@"/posts/1.json", nil);
199 NSDictionary *query = [NSDictionary dictionaryWithObject:@"value string" forKey:@"key string"];
201 STAssertEqualObjects(elementPath,
@"/posts/1.json?key%20string=value%20string", nil);
207 STAssertEqualObjects(newElementPath,
@"/posts/new.json", nil);
213 STAssertEqualObjects(collectionPath,
@"/posts.json", nil);
219 STAssertEqualObjects([format extension],
@"json", nil);
220 STAssertEqualObjects([format MIMEType],
@"application/json", nil);
225 NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:5] forKey:@"post_id"];
226 STAssertEqualObjects([
postComment newElementPathWithPrefixOptions:options],
@"/posts/5/comments/new.json", nil);
227 STAssertEqualObjects([
postComment collectionPathWithPrefixOptions:options queryOptions:nil],
@"/posts/5/comments.json", nil);
250 STAssertNotNil(resource, nil);
251 STAssertNil(error, nil);
260 STAssertNotNil(resources, nil);
261 STAssertNil(error, nil);
264 for (ARResource *resource in resources)
266 NSLog(@"%@", [resource attributes]);
276 STAssertNotNil(resource, nil);
277 STAssertNil(error, nil);
278 NSLog(@"%@", [resource attributes]);
288 STAssertNil(error, nil);
296 NSDictionary *headerFields = [NSDictionary dictionaryWithObject:@"/foo/bar/1" forKey:@"Location"];
297 ARHTTPResponse *response = [[
ARHTTPResponse alloc] initWithURLResponse:[[NSHTTPURLResponse alloc] initWithURL:nil statusCode:0 HTTPVersion:nil headerFields:headerFields] body:nil];
298 STAssertEqualObjects(
ARIDFromResponse(response), [NSNumber numberWithInt:1], nil);