mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-19 13:09:19 +08:00
Fix all build errors in unit tests. Restore execution of core mapping tests.
This commit is contained in:
@@ -82,8 +82,8 @@
|
||||
RKMappingOperation *operation = [[RKMappingOperation alloc] initWithSourceObject:self.object destinationObject:dictionary mapping:self.mapping];
|
||||
operation.dataSource = dataSource;
|
||||
operation.delegate = self;
|
||||
BOOL success = [operation performMapping:error];
|
||||
if (!success) {
|
||||
[operation start];
|
||||
if (operation.error) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ typedef RKObjectMapping *(^RKDynamicMappingDelegateBlock)(id);
|
||||
@param block The block object to invoke to select the object mapping with which to map the given object representation.
|
||||
*/
|
||||
- (void)setObjectMappingForDataBlock:(RKDynamicMappingDelegateBlock)block;
|
||||
// TODO: Better method signature...
|
||||
|
||||
/**
|
||||
Defines a dynamic mapping rule stating that when the value of the key property matches the specified value, the given mapping should be used to map the representation.
|
||||
|
||||
@@ -170,7 +170,7 @@
|
||||
|
||||
@param mapper The mapper operation performing the mapping.
|
||||
@param dictionaryOrArrayOfDictionaries The `NSDictictionary` or `NSArray` of `NSDictionary` object representations that was found at the `keyPath`.
|
||||
@param keyPath The key path that the representation was read from in the `sourceObject`.
|
||||
@param keyPath The key path that the representation was read from in the `sourceObject`. If the `keyPath` was `[NSNull null]` in the `mappingsDictionary`, it will be given as `nil` to the delegate.
|
||||
*/
|
||||
- (void)mapper:(RKMapperOperation *)mapper didFindRespresentation:(id)dictionaryOrArrayOfDictionaries atKeyPath:(NSString *)keyPath;
|
||||
|
||||
@@ -178,7 +178,7 @@
|
||||
Tells the delegate that the mapper failed to find a mappable object at a key path specified in the `mappingsDictionary`.
|
||||
|
||||
@param mapper The mapper operation performing the mapping.
|
||||
@param keyPath The key path that was searched for a mappable object representation.
|
||||
@param keyPath The key path that was searched for a mappable object representation.
|
||||
*/
|
||||
- (void)mapper:(RKMapperOperation *)mapper didNotFindReprsentationAtKeyPath:(NSString *)keyPath;
|
||||
|
||||
@@ -191,7 +191,7 @@
|
||||
|
||||
@param mapper The mapper operation performing the mapping.
|
||||
@param mappingOperation The mapping operation that is about to be started.
|
||||
@param keyPath The key path that was mapped.
|
||||
@param keyPath The key path that was mapped. A `nil` key path indicates that the mapping matched the entire `sourceObject`.
|
||||
*/
|
||||
- (void)mapper:(RKMapperOperation *)mapper willStartMappingOperation:(RKMappingOperation *)mappingOperation forKeyPath:(NSString *)keyPath;
|
||||
|
||||
@@ -200,7 +200,7 @@
|
||||
|
||||
@param mapper The mapper operation performing the mapping.
|
||||
@param mappingOperation The mapping operation that has finished.
|
||||
@param keyPath The key path that was mapped.
|
||||
@param keyPath The key path that was mapped. A `nil` key path indicates that the mapping matched the entire `sourceObject`.
|
||||
*/
|
||||
- (void)mapper:(RKMapperOperation *)mapper didFinishMappingOperation:(RKMappingOperation *)mappingOperation forKeyPath:(NSString *)keyPath;
|
||||
|
||||
@@ -209,7 +209,7 @@
|
||||
|
||||
@param mapper The mapper operation performing the mapping.
|
||||
@param mappingOperation The mapping operation that has failed.
|
||||
@param keyPath The key path that was mapped.
|
||||
@param keyPath The key path that was mapped. A `nil` key path indicates that the mapping matched the entire `sourceObject`.
|
||||
@param error The error that occurred during the execution of the mapping operation.
|
||||
*/
|
||||
- (void)mapper:(RKMapperOperation *)mapper didFailMappingOperation:(RKMappingOperation *)mappingOperation forKeyPath:(NSString *)keyPath withError:(NSError *)error;
|
||||
|
||||
@@ -32,6 +32,11 @@ NSString * const RKMappingErrorKeyPathErrorKey = @"keyPath";
|
||||
#undef RKLogComponent
|
||||
#define RKLogComponent lcl_cRestKitObjectMapping
|
||||
|
||||
static NSString *RKDelegateKeyPathFromKeyPath(NSString *keyPath)
|
||||
{
|
||||
return ([keyPath isEqual:[NSNull null]]) ? nil : keyPath;
|
||||
}
|
||||
|
||||
@interface RKMapperOperation ()
|
||||
|
||||
@property (nonatomic, strong, readwrite) NSError *error;
|
||||
@@ -80,6 +85,7 @@ NSString * const RKMappingErrorKeyPathErrorKey = @"keyPath";
|
||||
[userInfo addEntriesFromDictionary:otherInfo];
|
||||
NSError *error = [NSError errorWithDomain:RKErrorDomain code:errorCode userInfo:userInfo];
|
||||
[self addError:error];
|
||||
self.error = error;
|
||||
}
|
||||
|
||||
- (void)addErrorForUnmappableKeyPath:(NSString *)keyPath
|
||||
@@ -204,27 +210,27 @@ NSString * const RKMappingErrorKeyPathErrorKey = @"keyPath";
|
||||
NSAssert(mapping != nil, @"Cannot map without an mapping");
|
||||
|
||||
RKLogDebug(@"Asked to map source object %@ with mapping %@", mappableObject, mapping);
|
||||
NSError *error = nil;
|
||||
|
||||
RKMappingOperation *mappingOperation = [[RKMappingOperation alloc] initWithSourceObject:mappableObject destinationObject:destinationObject mapping:mapping];
|
||||
mappingOperation.dataSource = self.mappingOperationDataSource;
|
||||
if ([self.delegate respondsToSelector:@selector(mapper:willStartMappingOperation:)]) {
|
||||
[self.delegate mapper:self willStartMappingOperation:mappingOperation forKeyPath:keyPath];
|
||||
if ([self.delegate respondsToSelector:@selector(mapper:willStartMappingOperation:forKeyPath:)]) {
|
||||
[self.delegate mapper:self willStartMappingOperation:mappingOperation forKeyPath:RKDelegateKeyPathFromKeyPath(keyPath)];
|
||||
}
|
||||
BOOL success = [mappingOperation performMapping:&error];
|
||||
if (success) {
|
||||
if ([self.delegate respondsToSelector:@selector(mapper:didFinishMappingOperation:)]) {
|
||||
[self.delegate mapper:self didFinishMappingOperation:mappingOperation forKeyPath:keyPath];
|
||||
[mappingOperation start];
|
||||
if (mappingOperation.error) {
|
||||
if ([self.delegate respondsToSelector:@selector(mapper:didFailMappingOperation:forKeyPath:withError:)]) {
|
||||
[self.delegate mapper:self didFailMappingOperation:mappingOperation forKeyPath:RKDelegateKeyPathFromKeyPath(keyPath) withError:mappingOperation.error];
|
||||
}
|
||||
} else if (error) {
|
||||
if ([self.delegate respondsToSelector:@selector(mapper:didFailMappingOperation:withError:)]) {
|
||||
[self.delegate mapper:self didFailMappingOperation:mappingOperation forKeyPath:keyPath withError:error];
|
||||
[self addError:mappingOperation.error];
|
||||
|
||||
return NO;
|
||||
} else {
|
||||
if ([self.delegate respondsToSelector:@selector(mapper:didFinishMappingOperation:forKeyPath:)]) {
|
||||
[self.delegate mapper:self didFinishMappingOperation:mappingOperation forKeyPath:RKDelegateKeyPathFromKeyPath(keyPath)];
|
||||
}
|
||||
[self addError:error];
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
- (id)objectWithMapping:(RKMapping *)mapping andData:(id)mappableData
|
||||
@@ -286,7 +292,7 @@ NSString * const RKMappingErrorKeyPathErrorKey = @"keyPath";
|
||||
RKLogDebug(@"Found unmappable value at keyPath: %@", keyPath);
|
||||
|
||||
if ([self.delegate respondsToSelector:@selector(mapper:didNotFindReprsentationAtKeyPath:)]) {
|
||||
[self.delegate mapper:self didNotFindReprsentationAtKeyPath:keyPath];
|
||||
[self.delegate mapper:self didNotFindReprsentationAtKeyPath:RKDelegateKeyPathFromKeyPath(keyPath)];
|
||||
}
|
||||
|
||||
continue;
|
||||
@@ -295,8 +301,8 @@ NSString * const RKMappingErrorKeyPathErrorKey = @"keyPath";
|
||||
// Found something to map
|
||||
foundMappable = YES;
|
||||
RKMapping *mapping = [mappingsByKeyPath objectForKey:keyPath];
|
||||
if ([self.delegate respondsToSelector:@selector(mapper:didFindMappableObject:atKeyPath:)]) {
|
||||
[self.delegate mapper:self didFindRespresentation:mappableValue atKeyPath:keyPath];
|
||||
if ([self.delegate respondsToSelector:@selector(mapper:didFindRespresentation:atKeyPath:)]) {
|
||||
[self.delegate mapper:self didFindRespresentation:mappableValue atKeyPath:RKDelegateKeyPathFromKeyPath(keyPath)];
|
||||
}
|
||||
|
||||
mappingResult = [self performMappingForObject:mappableValue atKeyPath:keyPath usingMapping:mapping];
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
@param operation The object mapping operation being performed.
|
||||
@param value A new value that was set on the destination object.
|
||||
@param keyPath The key path in the destination object for which a new value has been set.
|
||||
@param propertyMapping The RKAttributeMapping or RKRelationshipMapping found for the key path.
|
||||
@param propertyMapping The `RKAttributeMapping` or `RKRelationshipMapping` found for the key path.
|
||||
*/
|
||||
- (void)mappingOperation:(RKMappingOperation *)operation didSetValue:(id)value forKeyPath:(NSString *)keyPath usingMapping:(RKPropertyMapping *)propertyMapping;
|
||||
|
||||
@@ -65,7 +65,7 @@
|
||||
@param operation The object mapping operation being performed.
|
||||
@param value A unchanged value for the key path in the destination object.
|
||||
@param keyPath The key path in the destination object for which a unchanged value was not set.
|
||||
@param propertyMapping The RKAttributeMapping or RKRelationshipMapping found for the key path.
|
||||
@param propertyMapping The `RKAttributeMapping` or `RKRelationshipMapping` found for the key path.
|
||||
*/
|
||||
- (void)mappingOperation:(RKMappingOperation *)operation didNotSetUnchangedValue:(id)value forKeyPath:(NSString *)keyPath usingMapping:(RKPropertyMapping *)propertyMapping;
|
||||
|
||||
@@ -80,7 +80,7 @@
|
||||
/**
|
||||
Tells the delegate that the mapping operation has selected a concrete object mapping with which to map the source object.
|
||||
|
||||
Only sent if the receiver was initialized with an instance of RKDynamicMapping as the mapping.
|
||||
Only sent if the receiver was initialized with an instance of `RKDynamicMapping` as the mapping.
|
||||
|
||||
@param operation The mapping operation.
|
||||
@param objectMapping The concrete object mapping with which to perform the mapping.
|
||||
@@ -93,7 +93,7 @@
|
||||
/**
|
||||
Instances of `RKMappingOperation` perform transformation between object representations according to the rules expressed in `RKObjectMapping` objects. Mapping operations provide the foundation for the RestKit object mapping engine and perform the work of inspecting the attributes and relationships of a source object and determining how to map them into new representations on a destination object.
|
||||
*/
|
||||
@interface RKMappingOperation : NSObject
|
||||
@interface RKMappingOperation : NSOperation
|
||||
|
||||
///---------------------------------------
|
||||
/// @name Initializing a Mapping Operation
|
||||
@@ -146,6 +146,11 @@
|
||||
*/
|
||||
@property (nonatomic, weak) id<RKMappingOperationDataSource> dataSource;
|
||||
|
||||
/**
|
||||
The error, if any, that occurred during the execution of the mapping operation.
|
||||
*/
|
||||
@property (nonatomic, strong, readonly) NSError *error;
|
||||
|
||||
///-------------------------
|
||||
/// @name Performing Mapping
|
||||
///-------------------------
|
||||
|
||||
@@ -72,6 +72,7 @@ extern NSString * const RKObjectMappingNestingAttributeKeyName;
|
||||
@property (nonatomic, strong, readwrite) id destinationObject;
|
||||
@property (nonatomic, strong) NSDictionary *nestedAttributeSubstitution;
|
||||
@property (nonatomic, strong) NSError *validationError;
|
||||
@property (nonatomic, strong, readwrite) NSError *error;
|
||||
@property (nonatomic, strong) RKObjectMapping *objectMapping; // The concrete mapping
|
||||
@end
|
||||
|
||||
@@ -425,7 +426,9 @@ extern NSString * const RKObjectMappingNestingAttributeKeyName;
|
||||
RKMappingOperation *subOperation = [[RKMappingOperation alloc] initWithSourceObject:anObject destinationObject:anotherObject mapping:relationshipMapping.mapping];
|
||||
subOperation.dataSource = self.dataSource;
|
||||
subOperation.delegate = self.delegate;
|
||||
if (NO == [subOperation performMapping:&error]) {
|
||||
[subOperation start];
|
||||
|
||||
if (subOperation.error) {
|
||||
RKLogWarning(@"WARNING: Failed mapping nested object: %@", [error localizedDescription]);
|
||||
}
|
||||
|
||||
@@ -626,7 +629,7 @@ extern NSString * const RKObjectMappingNestingAttributeKeyName;
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)performMapping:(NSError **)error
|
||||
- (void)start
|
||||
{
|
||||
RKLogDebug(@"Starting mapping operation...");
|
||||
RKLogTrace(@"Performing mapping operation: %@", self);
|
||||
@@ -653,23 +656,29 @@ extern NSString * const RKObjectMappingNestingAttributeKeyName;
|
||||
if ([self.dataSource respondsToSelector:@selector(commitChangesForMappingOperation:)]) {
|
||||
[self.dataSource commitChangesForMappingOperation:self];
|
||||
}
|
||||
return YES;
|
||||
return;
|
||||
}
|
||||
|
||||
if (_validationError) {
|
||||
if (self.validationError) {
|
||||
// We failed out due to validation
|
||||
if (error) *error = _validationError;
|
||||
self.error = _validationError;
|
||||
if ([self.delegate respondsToSelector:@selector(mappingOperation:didFailWithError:)]) {
|
||||
[self.delegate mappingOperation:self didFailWithError:_validationError];
|
||||
[self.delegate mappingOperation:self didFailWithError:self.error];
|
||||
}
|
||||
|
||||
RKLogError(@"Failed mapping operation: %@", [_validationError localizedDescription]);
|
||||
RKLogError(@"Failed mapping operation: %@", [self.error localizedDescription]);
|
||||
} else {
|
||||
// We did not find anything to do
|
||||
RKLogDebug(@"Mapping operation did not find any mappable content");
|
||||
self.error = [NSError errorWithDomain:RKErrorDomain code:RKMappingErrorUnmappableContent userInfo:nil];
|
||||
}
|
||||
}
|
||||
|
||||
return NO;
|
||||
- (BOOL)performMapping:(NSError **)error
|
||||
{
|
||||
[self start];
|
||||
if (error) *error = self.error;
|
||||
return self.error == nil;
|
||||
}
|
||||
|
||||
- (NSString *)description
|
||||
|
||||
@@ -81,6 +81,20 @@
|
||||
*/
|
||||
@property (nonatomic, strong, readonly) NSArray *propertyMappings;
|
||||
|
||||
/**
|
||||
Returns the property mappings of the receiver in a dictionary, where the keys are the source key paths and the values are instances of `RKAttributeMapping` or `RKRelationshipMapping`.
|
||||
|
||||
@return The property mappings of the receiver in a dictionary, where the keys are the source key paths and the values are instances of `RKAttributeMapping` or `RKRelationshipMapping`.
|
||||
*/
|
||||
@property (nonatomic, readonly) NSDictionary *propertyMappingsBySourceKeyPath;
|
||||
|
||||
/**
|
||||
Returns the property mappings of the receiver in a dictionary, where the keys are the destination key paths and the values are instances of `RKAttributeMapping` or `RKRelationshipMapping`.
|
||||
|
||||
@return The property mappings of the receiver in a dictionary, where the keys are the destination key paths and the values are instances of `RKAttributeMapping` or `RKRelationshipMapping`.
|
||||
*/
|
||||
@property (nonatomic, readonly) NSDictionary *propertyMappingsByDestinationKeyPath;
|
||||
|
||||
/**
|
||||
The collection of attribute mappings within this object mapping.
|
||||
*/
|
||||
@@ -156,6 +170,7 @@
|
||||
|
||||
*/
|
||||
- (void)mapKeyOfNestedDictionaryToAttribute:(NSString *)attributeName;
|
||||
// TODO: Can we eliminate this API???
|
||||
|
||||
/**
|
||||
Returns the attribute mapping targeting the key of a nested dictionary in the source JSON.
|
||||
@@ -239,7 +254,7 @@
|
||||
quickly generate a corresponding serialization mapping from a configured object mapping. The inverse
|
||||
mapping will have the source and destination keyPaths swapped for all attribute and relationship mappings.
|
||||
*/
|
||||
//- (RKObjectMapping *)inverseMapping;
|
||||
- (RKObjectMapping *)inverseMapping;
|
||||
// TODO: Keep or kill inverse???
|
||||
|
||||
///---------------------------------------------------
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
|
||||
// Constants
|
||||
NSString * const RKObjectMappingNestingAttributeKeyName = @"<RK_NESTING_ATTRIBUTE>";
|
||||
static NSUInteger RKObjectMappingMaximumInverseMappingRecursionDepth = 100;
|
||||
|
||||
@interface RKObjectMapping ()
|
||||
@property (nonatomic, weak, readwrite) Class objectClass;
|
||||
@@ -87,6 +88,26 @@ NSString * const RKObjectMappingNestingAttributeKeyName = @"<RK_NESTING_ATTRIBUT
|
||||
return [NSArray arrayWithArray:_mutablePropertyMappings];
|
||||
}
|
||||
|
||||
- (NSDictionary *)propertyMappingsBySourceKeyPath
|
||||
{
|
||||
NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithCapacity:[self.propertyMappings count]];
|
||||
for (RKPropertyMapping *propertyMapping in self.propertyMappings) {
|
||||
[dictionary setObject:propertyMapping forKey:propertyMapping.sourceKeyPath];
|
||||
}
|
||||
|
||||
return dictionary;
|
||||
}
|
||||
|
||||
- (NSDictionary *)propertyMappingsByDestinationKeyPath
|
||||
{
|
||||
NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithCapacity:[self.propertyMappings count]];
|
||||
for (RKPropertyMapping *propertyMapping in self.propertyMappings) {
|
||||
[dictionary setObject:propertyMapping forKey:propertyMapping.destinationKeyPath];
|
||||
}
|
||||
|
||||
return dictionary;
|
||||
}
|
||||
|
||||
- (NSArray *)mappedKeyPaths
|
||||
{
|
||||
return [self.propertyMappings valueForKey:@"destinationKeyPath"];
|
||||
@@ -190,35 +211,32 @@ NSString * const RKObjectMappingNestingAttributeKeyName = @"<RK_NESTING_ATTRIBUT
|
||||
[self.mutablePropertyMappings removeObject:attributeOrRelationshipMapping];
|
||||
}
|
||||
|
||||
#ifndef MAX_INVERSE_MAPPING_RECURSION_DEPTH
|
||||
#define MAX_INVERSE_MAPPING_RECURSION_DEPTH (100)
|
||||
#endif
|
||||
//- (RKObjectMapping *)inverseMappingAtDepth:(NSInteger)depth
|
||||
//{
|
||||
// NSAssert(depth < MAX_INVERSE_MAPPING_RECURSION_DEPTH, @"Exceeded max recursion level in inverseMapping. This is likely due to a loop in the serialization graph. To break this loop, specify one-way relationships by setting serialize to NO in mapKeyPath:toRelationship:withObjectMapping:serialize:");
|
||||
// RKObjectMapping *inverseMapping = [RKObjectMapping mappingForClass:[NSMutableDictionary class]];
|
||||
// for (RKAttributeMapping *attributeMapping in self.attributeMappings) {
|
||||
// [inverseMapping mapKeyPath:attributeMapping.destinationKeyPath toAttribute:attributeMapping.sourceKeyPath];
|
||||
// }
|
||||
//
|
||||
// for (RKRelationshipMapping *relationshipMapping in self.relationshipMappings) {
|
||||
- (RKObjectMapping *)inverseMappingAtDepth:(NSInteger)depth
|
||||
{
|
||||
NSAssert(depth < RKObjectMappingMaximumInverseMappingRecursionDepth, @"Exceeded max recursion level in inverseMapping. This is likely due to a loop in the serialization graph. To break this loop, specify one-way relationships by setting serialize to NO in mapKeyPath:toRelationship:withObjectMapping:serialize:");
|
||||
RKObjectMapping *inverseMapping = [RKObjectMapping mappingForClass:[NSMutableDictionary class]];
|
||||
for (RKAttributeMapping *attributeMapping in self.attributeMappings) {
|
||||
[inverseMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:attributeMapping.destinationKeyPath toKeyPath:attributeMapping.sourceKeyPath]];
|
||||
}
|
||||
|
||||
for (RKRelationshipMapping *relationshipMapping in self.relationshipMappings) {
|
||||
// if (relationshipMapping.reversible) {
|
||||
// RKMapping *mapping = relationshipMapping.mapping;
|
||||
// if (! [mapping isKindOfClass:[RKObjectMapping class]]) {
|
||||
// RKLogWarning(@"Unable to generate inverse mapping for relationship '%@': %@ relationships cannot be inversed.", relationshipMapping.sourceKeyPath, NSStringFromClass([mapping class]));
|
||||
// continue;
|
||||
// }
|
||||
// [inverseMapping mapKeyPath:relationshipMapping.destinationKeyPath toRelationship:relationshipMapping.sourceKeyPath withMapping:[(RKObjectMapping *)mapping inverseMappingAtDepth:depth+1]];
|
||||
RKMapping *mapping = relationshipMapping.mapping;
|
||||
if (! [mapping isKindOfClass:[RKObjectMapping class]]) {
|
||||
RKLogWarning(@"Unable to generate inverse mapping for relationship '%@': %@ relationships cannot be inversed.", relationshipMapping.sourceKeyPath, NSStringFromClass([mapping class]));
|
||||
continue;
|
||||
}
|
||||
[inverseMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:relationshipMapping.destinationKeyPath toKeyPath:relationshipMapping.sourceKeyPath withMapping:[(RKObjectMapping *)mapping inverseMappingAtDepth:depth+1]]];
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return inverseMapping;
|
||||
//}
|
||||
//
|
||||
//- (RKObjectMapping *)inverseMapping
|
||||
//{
|
||||
// return [self inverseMappingAtDepth:0];
|
||||
//}
|
||||
}
|
||||
|
||||
return inverseMapping;
|
||||
}
|
||||
|
||||
- (RKObjectMapping *)inverseMapping
|
||||
{
|
||||
return [self inverseMappingAtDepth:0];
|
||||
}
|
||||
|
||||
- (void)mapKeyOfNestedDictionaryToAttribute:(NSString *)attributeName
|
||||
{
|
||||
@@ -316,31 +334,36 @@ NSString * const RKObjectMappingNestingAttributeKeyName = @"<RK_NESTING_ATTRIBUT
|
||||
static NSMutableArray *defaultDateFormatters = nil;
|
||||
static NSDateFormatter *preferredDateFormatter = nil;
|
||||
|
||||
static NSArray *RKDefaultDateFormattersArray()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@implementation RKObjectMapping (DateAndTimeFormatting)
|
||||
|
||||
+ (NSArray *)defaultDateFormatters
|
||||
{
|
||||
// TODO: Migrate into load/initialize...
|
||||
if (!defaultDateFormatters) {
|
||||
defaultDateFormatters = [[NSMutableArray alloc] init];
|
||||
|
||||
// Setup the default formatters
|
||||
|
||||
//NSNumberFormatter which creates dates from Unix timestamps
|
||||
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
|
||||
numberFormatter.numberStyle = NSNumberFormatterDecimalStyle;
|
||||
[self addDefaultDateFormatter:numberFormatter];
|
||||
|
||||
ISO8601DateFormatter *isoFormatter = [[ISO8601DateFormatter alloc] init];
|
||||
[self addDefaultDateFormatter:isoFormatter];
|
||||
|
||||
[self addDefaultDateFormatterForString:@"MM/dd/yyyy" inTimeZone:nil];
|
||||
[self addDefaultDateFormatterForString:@"yyyy-MM-dd'T'HH:mm:ss'Z'" inTimeZone:nil];
|
||||
}
|
||||
if (!defaultDateFormatters) [self resetDefaultDateFormatters];
|
||||
|
||||
return defaultDateFormatters;
|
||||
}
|
||||
|
||||
+ (void)resetDefaultDateFormatters
|
||||
{
|
||||
defaultDateFormatters = [[NSMutableArray alloc] init];
|
||||
|
||||
//NSNumberFormatter which creates dates from Unix timestamps
|
||||
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
|
||||
numberFormatter.numberStyle = NSNumberFormatterDecimalStyle;
|
||||
[self addDefaultDateFormatter:numberFormatter];
|
||||
|
||||
ISO8601DateFormatter *isoFormatter = [[ISO8601DateFormatter alloc] init];
|
||||
[self addDefaultDateFormatter:isoFormatter];
|
||||
|
||||
[self addDefaultDateFormatterForString:@"MM/dd/yyyy" inTimeZone:nil];
|
||||
[self addDefaultDateFormatterForString:@"yyyy-MM-dd'T'HH:mm:ss'Z'" inTimeZone:nil];
|
||||
}
|
||||
|
||||
+ (void)setDefaultDateFormatters:(NSArray *)dateFormatters
|
||||
{
|
||||
defaultDateFormatters = dateFormatters ? [[NSMutableArray alloc] initWithArray:dateFormatters] : [NSMutableArray array];
|
||||
|
||||
@@ -217,8 +217,8 @@ BOOL RKValueIsEqualToValue(id sourceValue, id destinationValue);
|
||||
mappingOperation.dataSource = self.mappingOperationDataSource;
|
||||
NSError *error = nil;
|
||||
mappingOperation.delegate = self;
|
||||
BOOL success = [mappingOperation performMapping:&error];
|
||||
if (! success) {
|
||||
[mappingOperation start];
|
||||
if (mappingOperation.error) {
|
||||
[NSException raise:NSInternalInconsistencyException format:@"%p: failed with error: %@\n%@ during mapping from %@ to %@ with mapping %@",
|
||||
self, error, [self description], self.sourceObject, self.destinationObject, self.mapping];
|
||||
}
|
||||
|
||||
@@ -264,8 +264,6 @@
|
||||
251610B71456F2330060A5C5 /* RKParent.m in Sources */ = {isa = PBXBuildFile; fileRef = 251610081456F2330060A5C5 /* RKParent.m */; };
|
||||
251610B81456F2330060A5C5 /* RKResident.m in Sources */ = {isa = PBXBuildFile; fileRef = 2516100A1456F2330060A5C5 /* RKResident.m */; };
|
||||
251610B91456F2330060A5C5 /* RKResident.m in Sources */ = {isa = PBXBuildFile; fileRef = 2516100A1456F2330060A5C5 /* RKResident.m */; };
|
||||
251610D01456F2330060A5C5 /* RKURLTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 2516101A1456F2330060A5C5 /* RKURLTest.m */; };
|
||||
251610D11456F2330060A5C5 /* RKURLTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 2516101A1456F2330060A5C5 /* RKURLTest.m */; };
|
||||
251610D21456F2330060A5C5 /* RKDynamicObjectMappingTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 2516101C1456F2330060A5C5 /* RKDynamicObjectMappingTest.m */; };
|
||||
251610D31456F2330060A5C5 /* RKDynamicObjectMappingTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 2516101C1456F2330060A5C5 /* RKDynamicObjectMappingTest.m */; };
|
||||
251610DC1456F2330060A5C5 /* RKObjectMappingNextGenTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 251610211456F2330060A5C5 /* RKObjectMappingNextGenTest.m */; };
|
||||
@@ -292,8 +290,6 @@
|
||||
251611111456F2340060A5C5 /* NSStringRestKitTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 251610531456F2330060A5C5 /* NSStringRestKitTest.m */; };
|
||||
251611121456F2340060A5C5 /* RKDotNetDateFormatterTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 251610541456F2330060A5C5 /* RKDotNetDateFormatterTest.m */; };
|
||||
251611131456F2340060A5C5 /* RKDotNetDateFormatterTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 251610541456F2330060A5C5 /* RKDotNetDateFormatterTest.m */; };
|
||||
251611141456F2340060A5C5 /* RKJSONParserJSONKitTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 251610551456F2330060A5C5 /* RKJSONParserJSONKitTest.m */; };
|
||||
251611151456F2340060A5C5 /* RKJSONParserJSONKitTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 251610551456F2330060A5C5 /* RKJSONParserJSONKitTest.m */; };
|
||||
251611161456F2340060A5C5 /* RKPathMatcherTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 251610561456F2330060A5C5 /* RKPathMatcherTest.m */; };
|
||||
251611171456F2340060A5C5 /* RKPathMatcherTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 251610561456F2330060A5C5 /* RKPathMatcherTest.m */; };
|
||||
251611291456F50F0060A5C5 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 251611281456F50F0060A5C5 /* SystemConfiguration.framework */; };
|
||||
@@ -318,8 +314,6 @@
|
||||
252029061577AE1800076FB4 /* RKRoute.m in Sources */ = {isa = PBXBuildFile; fileRef = 252029021577AE1800076FB4 /* RKRoute.m */; };
|
||||
252029091577C78600076FB4 /* RKRouteSetTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 252029081577C78600076FB4 /* RKRouteSetTest.m */; };
|
||||
2520290A1577C78600076FB4 /* RKRouteSetTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 252029081577C78600076FB4 /* RKRouteSetTest.m */; };
|
||||
252A2034153477870078F8AD /* NSArray+RKAdditionsTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 252A2033153477870078F8AD /* NSArray+RKAdditionsTest.m */; };
|
||||
252A2035153477870078F8AD /* NSArray+RKAdditionsTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 252A2033153477870078F8AD /* NSArray+RKAdditionsTest.m */; };
|
||||
252EFAFA14D8EAEC004863C8 /* RKEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 252EFAF914D8EAEC004863C8 /* RKEvent.m */; };
|
||||
252EFAFB14D8EAEC004863C8 /* RKEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 252EFAF914D8EAEC004863C8 /* RKEvent.m */; };
|
||||
252EFB2814DA0689004863C8 /* NakedEvents.json in Resources */ = {isa = PBXBuildFile; fileRef = 252EFB2714DA0689004863C8 /* NakedEvents.json */; };
|
||||
@@ -801,15 +795,6 @@
|
||||
251610081456F2330060A5C5 /* RKParent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RKParent.m; sourceTree = "<group>"; };
|
||||
251610091456F2330060A5C5 /* RKResident.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RKResident.h; sourceTree = "<group>"; };
|
||||
2516100A1456F2330060A5C5 /* RKResident.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RKResident.m; sourceTree = "<group>"; };
|
||||
251610101456F2330060A5C5 /* RKAuthenticationTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RKAuthenticationTest.m; sourceTree = "<group>"; };
|
||||
251610111456F2330060A5C5 /* RKClientTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RKClientTest.m; sourceTree = "<group>"; };
|
||||
251610121456F2330060A5C5 /* RKOAuthClientTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RKOAuthClientTest.m; sourceTree = "<group>"; };
|
||||
251610131456F2330060A5C5 /* RKParamsAttachmentTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RKParamsAttachmentTest.m; sourceTree = "<group>"; };
|
||||
251610141456F2330060A5C5 /* RKParamsTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RKParamsTest.m; sourceTree = "<group>"; };
|
||||
251610171456F2330060A5C5 /* RKRequestQueueTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RKRequestQueueTest.m; sourceTree = "<group>"; };
|
||||
251610181456F2330060A5C5 /* RKRequestTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RKRequestTest.m; sourceTree = "<group>"; };
|
||||
251610191456F2330060A5C5 /* RKResponseTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RKResponseTest.m; sourceTree = "<group>"; };
|
||||
2516101A1456F2330060A5C5 /* RKURLTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RKURLTest.m; sourceTree = "<group>"; };
|
||||
2516101C1456F2330060A5C5 /* RKDynamicObjectMappingTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RKDynamicObjectMappingTest.m; sourceTree = "<group>"; };
|
||||
2516101E1456F2330060A5C5 /* RKObjectLoaderTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RKObjectLoaderTest.m; sourceTree = "<group>"; };
|
||||
2516101F1456F2330060A5C5 /* RKObjectManagerTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RKObjectManagerTest.m; sourceTree = "<group>"; };
|
||||
@@ -830,9 +815,7 @@
|
||||
251610521456F2330060A5C5 /* NSDictionary+RKRequestSerializationTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSDictionary+RKRequestSerializationTest.m"; sourceTree = "<group>"; };
|
||||
251610531456F2330060A5C5 /* NSStringRestKitTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NSStringRestKitTest.m; sourceTree = "<group>"; };
|
||||
251610541456F2330060A5C5 /* RKDotNetDateFormatterTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RKDotNetDateFormatterTest.m; sourceTree = "<group>"; };
|
||||
251610551456F2330060A5C5 /* RKJSONParserJSONKitTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RKJSONParserJSONKitTest.m; sourceTree = "<group>"; };
|
||||
251610561456F2330060A5C5 /* RKPathMatcherTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RKPathMatcherTest.m; sourceTree = "<group>"; };
|
||||
251610571456F2330060A5C5 /* RKXMLParserTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RKXMLParserTest.m; sourceTree = "<group>"; };
|
||||
251611281456F50F0060A5C5 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; };
|
||||
2516112A1456F5170060A5C5 /* CFNetwork.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CFNetwork.framework; path = System/Library/Frameworks/CFNetwork.framework; sourceTree = SDKROOT; };
|
||||
2516112D1456F5520060A5C5 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; };
|
||||
@@ -846,12 +829,10 @@
|
||||
252029011577AE1800076FB4 /* RKRoute.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RKRoute.h; sourceTree = "<group>"; };
|
||||
252029021577AE1800076FB4 /* RKRoute.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RKRoute.m; sourceTree = "<group>"; };
|
||||
252029081577C78600076FB4 /* RKRouteSetTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RKRouteSetTest.m; sourceTree = "<group>"; };
|
||||
252A2033153477870078F8AD /* NSArray+RKAdditionsTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSArray+RKAdditionsTest.m"; sourceTree = "<group>"; };
|
||||
252EFAF814D8EAEC004863C8 /* RKEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RKEvent.h; sourceTree = "<group>"; };
|
||||
252EFAF914D8EAEC004863C8 /* RKEvent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RKEvent.m; sourceTree = "<group>"; };
|
||||
252EFAFC14D8EB30004863C8 /* RKTestNotificationObserver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RKTestNotificationObserver.h; path = Testing/RKTestNotificationObserver.h; sourceTree = "<group>"; };
|
||||
252EFAFD14D8EB30004863C8 /* RKTestNotificationObserver.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RKTestNotificationObserver.m; path = Testing/RKTestNotificationObserver.m; sourceTree = "<group>"; };
|
||||
252EFB0C14D98F76004863C8 /* RKMutableBlockDictionaryTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RKMutableBlockDictionaryTest.m; sourceTree = "<group>"; };
|
||||
252EFB2014D9B35D004863C8 /* RKTestFixture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RKTestFixture.h; path = Testing/RKTestFixture.h; sourceTree = "<group>"; };
|
||||
252EFB2114D9B35D004863C8 /* RKTestFixture.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RKTestFixture.m; path = Testing/RKTestFixture.m; sourceTree = "<group>"; };
|
||||
252EFB2714DA0689004863C8 /* NakedEvents.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = NakedEvents.json; sourceTree = "<group>"; };
|
||||
@@ -1555,15 +1536,6 @@
|
||||
2516100B1456F2330060A5C5 /* Network */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
251610101456F2330060A5C5 /* RKAuthenticationTest.m */,
|
||||
251610111456F2330060A5C5 /* RKClientTest.m */,
|
||||
251610121456F2330060A5C5 /* RKOAuthClientTest.m */,
|
||||
251610131456F2330060A5C5 /* RKParamsAttachmentTest.m */,
|
||||
251610141456F2330060A5C5 /* RKParamsTest.m */,
|
||||
251610171456F2330060A5C5 /* RKRequestQueueTest.m */,
|
||||
251610181456F2330060A5C5 /* RKRequestTest.m */,
|
||||
251610191456F2330060A5C5 /* RKResponseTest.m */,
|
||||
2516101A1456F2330060A5C5 /* RKURLTest.m */,
|
||||
252029081577C78600076FB4 /* RKRouteSetTest.m */,
|
||||
);
|
||||
name = Network;
|
||||
@@ -1650,14 +1622,10 @@
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
5C927E131608FFFD00DC8B07 /* RKDictionaryUtilitiesTest.m */,
|
||||
252EFB0C14D98F76004863C8 /* RKMutableBlockDictionaryTest.m */,
|
||||
251610521456F2330060A5C5 /* NSDictionary+RKRequestSerializationTest.m */,
|
||||
251610531456F2330060A5C5 /* NSStringRestKitTest.m */,
|
||||
251610541456F2330060A5C5 /* RKDotNetDateFormatterTest.m */,
|
||||
251610551456F2330060A5C5 /* RKJSONParserJSONKitTest.m */,
|
||||
251610561456F2330060A5C5 /* RKPathMatcherTest.m */,
|
||||
251610571456F2330060A5C5 /* RKXMLParserTest.m */,
|
||||
252A2033153477870078F8AD /* NSArray+RKAdditionsTest.m */,
|
||||
2501405215366000004E0466 /* RKObjectiveCppTest.mm */,
|
||||
);
|
||||
name = Support;
|
||||
@@ -2501,7 +2469,6 @@
|
||||
251610B41456F2330060A5C5 /* RKObjectMapperTestModel.m in Sources */,
|
||||
251610B61456F2330060A5C5 /* RKParent.m in Sources */,
|
||||
251610B81456F2330060A5C5 /* RKResident.m in Sources */,
|
||||
251610D01456F2330060A5C5 /* RKURLTest.m in Sources */,
|
||||
251610D21456F2330060A5C5 /* RKDynamicObjectMappingTest.m in Sources */,
|
||||
251610DC1456F2330060A5C5 /* RKObjectMappingNextGenTest.m in Sources */,
|
||||
251610DE1456F2330060A5C5 /* RKObjectMappingOperationTest.m in Sources */,
|
||||
@@ -2512,7 +2479,6 @@
|
||||
2516110E1456F2340060A5C5 /* NSDictionary+RKRequestSerializationTest.m in Sources */,
|
||||
251611101456F2340060A5C5 /* NSStringRestKitTest.m in Sources */,
|
||||
251611121456F2340060A5C5 /* RKDotNetDateFormatterTest.m in Sources */,
|
||||
251611141456F2340060A5C5 /* RKJSONParserJSONKitTest.m in Sources */,
|
||||
251611161456F2340060A5C5 /* RKPathMatcherTest.m in Sources */,
|
||||
25B6E9A614CF829400B1E881 /* NSInvocation+OCMAdditions.m in Sources */,
|
||||
25B6E9A814CF829400B1E881 /* NSMethodSignature+OCMAdditions.m in Sources */,
|
||||
@@ -2542,7 +2508,6 @@
|
||||
25E36E0215195CED00F9E448 /* RKFetchRequestMappingCacheTest.m in Sources */,
|
||||
25079C76151B952200266AE7 /* NSEntityDescription+RKAdditionsTest.m in Sources */,
|
||||
25DB7508151BD551009F01AF /* NSManagedObjectContext+RKAdditionsTest.m in Sources */,
|
||||
252A2034153477870078F8AD /* NSArray+RKAdditionsTest.m in Sources */,
|
||||
259D985A1550C6BE008C90F5 /* RKEntityByAttributeCacheTest.m in Sources */,
|
||||
259D986415521B20008C90F5 /* RKEntityCacheTest.m in Sources */,
|
||||
25AE61C615ADE9E500B319C8 /* OCClassMockRecorder.m in Sources */,
|
||||
@@ -2662,7 +2627,6 @@
|
||||
251610B51456F2330060A5C5 /* RKObjectMapperTestModel.m in Sources */,
|
||||
251610B71456F2330060A5C5 /* RKParent.m in Sources */,
|
||||
251610B91456F2330060A5C5 /* RKResident.m in Sources */,
|
||||
251610D11456F2330060A5C5 /* RKURLTest.m in Sources */,
|
||||
251610D31456F2330060A5C5 /* RKDynamicObjectMappingTest.m in Sources */,
|
||||
251610DD1456F2330060A5C5 /* RKObjectMappingNextGenTest.m in Sources */,
|
||||
251610DF1456F2330060A5C5 /* RKObjectMappingOperationTest.m in Sources */,
|
||||
@@ -2673,7 +2637,6 @@
|
||||
2516110F1456F2340060A5C5 /* NSDictionary+RKRequestSerializationTest.m in Sources */,
|
||||
251611111456F2340060A5C5 /* NSStringRestKitTest.m in Sources */,
|
||||
251611131456F2340060A5C5 /* RKDotNetDateFormatterTest.m in Sources */,
|
||||
251611151456F2340060A5C5 /* RKJSONParserJSONKitTest.m in Sources */,
|
||||
251611171456F2340060A5C5 /* RKPathMatcherTest.m in Sources */,
|
||||
25B6E9A714CF829400B1E881 /* NSInvocation+OCMAdditions.m in Sources */,
|
||||
25B6E9A914CF829400B1E881 /* NSMethodSignature+OCMAdditions.m in Sources */,
|
||||
@@ -2703,7 +2666,6 @@
|
||||
25E36E0315195CED00F9E448 /* RKFetchRequestMappingCacheTest.m in Sources */,
|
||||
25079C77151B952200266AE7 /* NSEntityDescription+RKAdditionsTest.m in Sources */,
|
||||
25DB7509151BD551009F01AF /* NSManagedObjectContext+RKAdditionsTest.m in Sources */,
|
||||
252A2035153477870078F8AD /* NSArray+RKAdditionsTest.m in Sources */,
|
||||
259D985B1550C6BE008C90F5 /* RKEntityByAttributeCacheTest.m in Sources */,
|
||||
259D986515521B20008C90F5 /* RKEntityCacheTest.m in Sources */,
|
||||
25AE61C715ADE9E500B319C8 /* OCClassMockRecorder.m in Sources */,
|
||||
|
||||
@@ -68,10 +68,10 @@
|
||||
objectManager.managedObjectStore = managedObjectStore;
|
||||
|
||||
RKObjectMapping *humanMapping = [RKEntityMapping mappingForEntityForName:@"RKHuman" inManagedObjectStore:managedObjectStore];
|
||||
[humanMapping mapAttributes:@"name", nil];
|
||||
[humanMapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
RKObjectMapping *catMapping = [RKEntityMapping mappingForEntityForName:@"RKCat" inManagedObjectStore:managedObjectStore];
|
||||
[catMapping mapAttributes:@"name", nil];
|
||||
[humanMapping mapKeyPath:@"favorite_cat" toRelationship:@"favoriteCat" withMapping:catMapping];
|
||||
[catMapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
[humanMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"favorite_cat" toKeyPath:@"favoriteCat" withMapping:catMapping]];;
|
||||
[objectManager.mappingProvider setMapping:humanMapping forKeyPath:@"human"];
|
||||
RKTestResponseLoader *responseLoader = [RKTestResponseLoader responseLoader];
|
||||
RKURL *URL = [objectManager.baseURL URLByAppendingResourcePath:@"/JSON/humans/with_to_one_relationship.json"];
|
||||
@@ -94,8 +94,8 @@
|
||||
RKManagedObjectStore *managedObjectStore = [RKTestFactory managedObjectStore];
|
||||
RKEntityMapping *humanMapping = [RKEntityMapping mappingForEntityForName:@"RKHuman"
|
||||
inManagedObjectStore:managedObjectStore];
|
||||
[humanMapping mapKeyPath:@"id" toAttribute:@"railsID"];
|
||||
[humanMapping mapAttributes:@"name", nil];
|
||||
[humanMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"id" toKeyPath:@"railsID"]];
|
||||
[humanMapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
humanMapping.primaryKeyAttribute = @"railsID";
|
||||
humanMapping.rootKeyPath = @"human";
|
||||
|
||||
@@ -165,8 +165,8 @@
|
||||
RKManagedObjectStore *managedObjectStore = [RKTestFactory managedObjectStore];
|
||||
objectManager.managedObjectStore = managedObjectStore;
|
||||
RKEntityMapping *humanMapping = [RKEntityMapping mappingForEntityForName:@"RKHuman" inManagedObjectStore:managedObjectStore];
|
||||
[humanMapping mapKeyPath:@"id" toAttribute:@"railsID"];
|
||||
[humanMapping mapAttributes:@"name", nil];
|
||||
[humanMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"id" toKeyPath:@"railsID"]];
|
||||
[humanMapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
humanMapping.primaryKeyAttribute = @"railsID";
|
||||
humanMapping.rootKeyPath = @"human";
|
||||
|
||||
@@ -269,7 +269,7 @@
|
||||
RKManagedObjectLoader *objectLoader = [objectManager loaderWithResourcePath:@"/humans/1"];
|
||||
objectLoader.objectMapping = mapping;
|
||||
objectLoader.serializationMapping = [RKObjectMapping serializationMapping];
|
||||
[objectLoader.serializationMapping mapAttributes:@"name", nil];
|
||||
[objectLoader.serializationMapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
|
||||
RKHuman *human = [NSEntityDescription insertNewObjectForEntityForName:@"RKHuman" inManagedObjectContext:managedObjectStore.primaryManagedObjectContext];
|
||||
assertThatBool([human.objectID isTemporaryID], is(equalToBool(YES)));
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
RKManagedObjectMappingOperationDataSource *dataSource = [[RKManagedObjectMappingOperationDataSource alloc] initWithManagedObjectContext:managedObjectStore.primaryManagedObjectContext
|
||||
cache:managedObjectStore.managedObjectCache];
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[RKMappableObject class]];
|
||||
id object = [dataSource objectForMappableContent:[NSDictionary dictionary] mapping:mapping];
|
||||
id object = [dataSource mappingOperation:nil targetObjectForRepresentation:[NSDictionary dictionary] withMapping:mapping];
|
||||
assertThat(object, isNot(nilValue()));
|
||||
assertThat([object class], is(equalTo([RKMappableObject class])));
|
||||
}
|
||||
@@ -50,7 +50,7 @@
|
||||
mapping.primaryKeyAttribute = @"railsID";
|
||||
|
||||
NSDictionary *data = [NSDictionary dictionary];
|
||||
id object = [dataSource objectForMappableContent:data mapping:mapping];
|
||||
id object = [dataSource mappingOperation:nil targetObjectForRepresentation:data withMapping:mapping];
|
||||
assertThat(object, isNot(nilValue()));
|
||||
assertThat(object, is(instanceOf([RKHuman class])));
|
||||
}
|
||||
@@ -62,8 +62,8 @@
|
||||
cache:managedObjectStore.managedObjectCache];
|
||||
RKEntityMapping *mapping = [RKEntityMapping mappingForEntityForName:@"RKHuman" inManagedObjectStore:managedObjectStore];
|
||||
|
||||
NSDictionary *data = [NSDictionary dictionary];
|
||||
id object = [dataSource objectForMappableContent:data mapping:mapping];
|
||||
NSDictionary *data = [NSDictionary dictionary];
|
||||
id object = [dataSource mappingOperation:nil targetObjectForRepresentation:data withMapping:mapping];
|
||||
assertThat(object, isNot(nilValue()));
|
||||
assertThat(object, is(instanceOf([RKHuman class])));
|
||||
}
|
||||
@@ -75,10 +75,10 @@
|
||||
cache:managedObjectStore.managedObjectCache];
|
||||
RKEntityMapping *mapping = [RKEntityMapping mappingForEntityForName:@"RKHuman" inManagedObjectStore:managedObjectStore];
|
||||
mapping.primaryKeyAttribute = @"railsID";
|
||||
[mapping addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"id" toKeyPath:@"railsID"]];
|
||||
[mapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"id" toKeyPath:@"railsID"]];
|
||||
|
||||
NSDictionary *data = [NSDictionary dictionaryWithObject:[NSNull null] forKey:@"id"];
|
||||
id object = [dataSource objectForMappableContent:data mapping:mapping];
|
||||
NSDictionary *data = [NSDictionary dictionaryWithObject:[NSNull null] forKey:@"id"];
|
||||
id object = [dataSource mappingOperation:nil targetObjectForRepresentation:data withMapping:mapping];
|
||||
assertThat(object, isNot(nilValue()));
|
||||
assertThat(object, is(instanceOf([RKHuman class])));
|
||||
}
|
||||
@@ -91,7 +91,7 @@
|
||||
managedObjectStore.managedObjectCache = [RKFetchRequestManagedObjectCache new];
|
||||
RKEntityMapping *mapping = [RKEntityMapping mappingForEntityForName:@"RKHuman" inManagedObjectStore:managedObjectStore];
|
||||
mapping.primaryKeyAttribute = @"railsID";
|
||||
[mapping addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"id" toKeyPath:@"railsID"]];
|
||||
[mapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"id" toKeyPath:@"railsID"]];
|
||||
|
||||
RKHuman *human = [NSEntityDescription insertNewObjectForEntityForName:@"RKHuman" inManagedObjectContext:managedObjectStore.primaryManagedObjectContext];
|
||||
human.railsID = [NSNumber numberWithInt:123];
|
||||
@@ -105,7 +105,7 @@
|
||||
RKManagedObjectMappingOperationDataSource *dataSource = [[RKManagedObjectMappingOperationDataSource alloc] initWithManagedObjectContext:managedObjectStore.primaryManagedObjectContext
|
||||
cache:managedObjectStore.managedObjectCache];
|
||||
NSDictionary *data = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:123] forKey:@"id"];
|
||||
id object = [dataSource objectForMappableContent:data mapping:mapping];
|
||||
id object = [dataSource mappingOperation:nil targetObjectForRepresentation:data withMapping:mapping];
|
||||
assertThat(object, isNot(nilValue()));
|
||||
assertThat(object, is(equalTo(human)));
|
||||
}
|
||||
@@ -116,7 +116,7 @@
|
||||
managedObjectStore.managedObjectCache = [RKFetchRequestManagedObjectCache new];
|
||||
RKEntityMapping *mapping = [RKEntityMapping mappingForEntityForName:@"RKHuman" inManagedObjectStore:managedObjectStore];
|
||||
mapping.primaryKeyAttribute = @"railsID";
|
||||
[mapping addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"monkey.id" toKeyPath:@"railsID"]];
|
||||
[mapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"monkey.id" toKeyPath:@"railsID"]];
|
||||
|
||||
RKHuman *human = [NSEntityDescription insertNewObjectForEntityForName:@"RKHuman" inManagedObjectContext:managedObjectStore.primaryManagedObjectContext];
|
||||
human.railsID = [NSNumber numberWithInt:123];
|
||||
@@ -132,7 +132,7 @@
|
||||
|
||||
RKManagedObjectMappingOperationDataSource *dataSource = [[RKManagedObjectMappingOperationDataSource alloc] initWithManagedObjectContext:managedObjectStore.primaryManagedObjectContext
|
||||
cache:managedObjectStore.managedObjectCache];
|
||||
id object = [dataSource objectForMappableContent:nestedDictionary mapping:mapping];
|
||||
id object = [dataSource mappingOperation:nil targetObjectForRepresentation:nestedDictionary withMapping:mapping];
|
||||
assertThat(object, isNot(nilValue()));
|
||||
assertThat(object, is(equalTo(human)));
|
||||
}
|
||||
@@ -145,7 +145,7 @@
|
||||
managedObjectStore.managedObjectCache = [[RKInMemoryManagedObjectCache alloc] initWithManagedObjectContext:managedObjectStore.primaryManagedObjectContext];
|
||||
RKEntityMapping *mapping = [RKEntityMapping mappingForEntityForName:@"RKHuman" inManagedObjectStore:managedObjectStore];
|
||||
mapping.primaryKeyAttribute = @"railsID";
|
||||
[mapping addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"id" toKeyPath:@"railsID"]];
|
||||
[mapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"id" toKeyPath:@"railsID"]];
|
||||
|
||||
RKHuman *human = [NSEntityDescription insertNewObjectForEntityForName:@"RKHuman" inManagedObjectContext:managedObjectStore.primaryManagedObjectContext];
|
||||
human.railsID = [NSNumber numberWithInt:123];
|
||||
@@ -159,8 +159,8 @@
|
||||
|
||||
NSDictionary *data = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:123] forKey:@"id"];
|
||||
RKManagedObjectMappingOperationDataSource *dataSource = [[RKManagedObjectMappingOperationDataSource alloc] initWithManagedObjectContext:managedObjectStore.primaryManagedObjectContext
|
||||
cache:managedObjectStore.managedObjectCache];
|
||||
NSManagedObject *object = [dataSource objectForMappableContent:data mapping:mapping];
|
||||
cache:managedObjectStore.managedObjectCache];
|
||||
NSManagedObject *object = [dataSource mappingOperation:nil targetObjectForRepresentation:data withMapping:mapping];
|
||||
assertThat([object managedObjectContext], is(equalTo(managedObjectStore.primaryManagedObjectContext)));
|
||||
assertThat(object, isNot(nilValue()));
|
||||
assertThat(object, is(equalTo(human)));
|
||||
@@ -172,7 +172,7 @@
|
||||
managedObjectStore.managedObjectCache = [[RKInMemoryManagedObjectCache alloc] initWithManagedObjectContext:managedObjectStore.primaryManagedObjectContext];
|
||||
RKEntityMapping *mapping = [RKEntityMapping mappingForEntityForName:@"RKHuman" inManagedObjectStore:managedObjectStore];
|
||||
mapping.primaryKeyAttribute = @"railsID";
|
||||
[mapping addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"monkey.id" toKeyPath:@"railsID"]];
|
||||
[mapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"monkey.id" toKeyPath:@"railsID"]];
|
||||
|
||||
RKHuman *human = [NSEntityDescription insertNewObjectForEntityForName:@"RKHuman" inManagedObjectContext:managedObjectStore.primaryManagedObjectContext];
|
||||
human.railsID = [NSNumber numberWithInt:123];
|
||||
@@ -189,7 +189,7 @@
|
||||
|
||||
RKManagedObjectMappingOperationDataSource *dataSource = [[RKManagedObjectMappingOperationDataSource alloc] initWithManagedObjectContext:managedObjectStore.primaryManagedObjectContext
|
||||
cache:managedObjectStore.managedObjectCache];
|
||||
id object = [dataSource objectForMappableContent:nestedDictionary mapping:mapping];
|
||||
id object = [dataSource mappingOperation:nil targetObjectForRepresentation:nestedDictionary withMapping:mapping];
|
||||
assertThat(object, isNot(nilValue()));
|
||||
assertThat(object, is(equalTo(human)));
|
||||
}
|
||||
@@ -202,7 +202,7 @@
|
||||
mapping.primaryKeyAttribute = @"name";
|
||||
NSEntityDescription *entity = [NSEntityDescription entityForName:@"RKHuman" inManagedObjectContext:managedObjectStore.primaryManagedObjectContext];
|
||||
entity.primaryKeyAttributeName = @"railsID";
|
||||
[mapping addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"monkey.name" toKeyPath:@"name"]];
|
||||
[mapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"monkey.name" toKeyPath:@"name"]];
|
||||
|
||||
RKHuman *human = [NSEntityDescription insertNewObjectForEntityForName:@"RKHuman" inManagedObjectContext:managedObjectStore.primaryManagedObjectContext];
|
||||
human.name = @"Testing";
|
||||
@@ -218,7 +218,7 @@
|
||||
NSDictionary *nestedDictionary = [NSDictionary dictionaryWithObject:data forKey:@"monkey"];
|
||||
RKManagedObjectMappingOperationDataSource *dataSource = [[RKManagedObjectMappingOperationDataSource alloc] initWithManagedObjectContext:managedObjectStore.primaryManagedObjectContext
|
||||
cache:managedObjectStore.managedObjectCache];
|
||||
id object = [dataSource objectForMappableContent:nestedDictionary mapping:mapping];
|
||||
id object = [dataSource mappingOperation:nil targetObjectForRepresentation:nestedDictionary withMapping:mapping];
|
||||
assertThat(object, isNot(nilValue()));
|
||||
assertThat(object, is(equalTo(human)));
|
||||
|
||||
@@ -231,10 +231,10 @@
|
||||
RKManagedObjectStore *managedObjectStore = [RKTestFactory managedObjectStore];
|
||||
managedObjectStore.managedObjectCache = [[RKInMemoryManagedObjectCache alloc] initWithManagedObjectContext:managedObjectStore.primaryManagedObjectContext];
|
||||
NSEntityDescription *entity = [NSEntityDescription entityForName:@"RKHuman" inManagedObjectContext:managedObjectStore.primaryManagedObjectContext];
|
||||
RKEntityMapping *mapping = [RKEntityMapping mappingForEntity:entity];
|
||||
RKEntityMapping *mapping = [[RKEntityMapping alloc] initWithEntity:entity];
|
||||
mapping.primaryKeyAttribute = @"name";
|
||||
entity.primaryKeyAttributeName = @"railsID";
|
||||
[mapping addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"monkey.name" toKeyPath:@"name"]];
|
||||
[mapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"monkey.name" toKeyPath:@"name"]];
|
||||
|
||||
RKHuman *human = [NSEntityDescription insertNewObjectForEntityForName:@"RKHuman" inManagedObjectContext:managedObjectStore.primaryManagedObjectContext];
|
||||
human.name = @"Testing";
|
||||
@@ -250,7 +250,7 @@
|
||||
NSDictionary *nestedDictionary = [NSDictionary dictionaryWithObject:data forKey:@"monkey"];
|
||||
RKManagedObjectMappingOperationDataSource *dataSource = [[RKManagedObjectMappingOperationDataSource alloc] initWithManagedObjectContext:managedObjectStore.primaryManagedObjectContext
|
||||
cache:managedObjectStore.managedObjectCache];
|
||||
id object = [dataSource objectForMappableContent:nestedDictionary mapping:mapping];
|
||||
id object = [dataSource mappingOperation:nil targetObjectForRepresentation:nestedDictionary withMapping:mapping];
|
||||
assertThat(object, isNot(nilValue()));
|
||||
assertThat(object, is(equalTo(human)));
|
||||
|
||||
@@ -263,11 +263,11 @@
|
||||
RKManagedObjectStore *managedObjectStore = [RKTestFactory managedObjectStore];
|
||||
managedObjectStore.managedObjectCache = [[RKInMemoryManagedObjectCache alloc] initWithManagedObjectContext:managedObjectStore.primaryManagedObjectContext];
|
||||
NSEntityDescription *entity = [NSEntityDescription entityForName:@"RKHuman" inManagedObjectContext:managedObjectStore.primaryManagedObjectContext];
|
||||
RKEntityMapping *mapping = [RKEntityMapping mappingForEntity:entity];
|
||||
RKEntityMapping *mapping = [[RKEntityMapping alloc] initWithEntity:entity];
|
||||
mapping.primaryKeyAttribute = @"railsID";
|
||||
entity.primaryKeyAttributeName = @"railsID";
|
||||
[mapping addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"monkey.name" toKeyPath:@"name"]];
|
||||
[mapping addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"monkey.railsID" toKeyPath:@"railsID"]];
|
||||
[mapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"monkey.name" toKeyPath:@"name"]];
|
||||
[mapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"monkey.railsID" toKeyPath:@"railsID"]];
|
||||
|
||||
RKHuman *human = [NSEntityDescription insertNewObjectForEntityForName:@"RKHuman" inManagedObjectContext:managedObjectStore.primaryManagedObjectContext];
|
||||
human.name = @"Testing";
|
||||
@@ -285,7 +285,7 @@
|
||||
|
||||
RKManagedObjectMappingOperationDataSource *dataSource = [[RKManagedObjectMappingOperationDataSource alloc] initWithManagedObjectContext:managedObjectStore.primaryManagedObjectContext
|
||||
cache:managedObjectStore.managedObjectCache];
|
||||
RKHuman *object = [dataSource objectForMappableContent:nestedDictionary mapping:mapping];
|
||||
RKHuman *object = [dataSource mappingOperation:nil targetObjectForRepresentation:nestedDictionary withMapping:mapping];
|
||||
assertThat(object, isNot(nilValue()));
|
||||
assertThat(object, is(equalTo(human)));
|
||||
assertThatInteger([object.railsID integerValue], is(equalToInteger(12345)));
|
||||
|
||||
@@ -58,7 +58,7 @@
|
||||
[managedObjectContext performBlockAndWait:^{
|
||||
RKEntityMapping *humanMapping = [RKEntityMapping mappingForEntityForName:@"RKHuman" inManagedObjectStore:managedObjectStore];
|
||||
humanMapping.primaryKeyAttribute = @"railsID";
|
||||
[humanMapping mapAttributes:@"name", @"favoriteCatID", nil];
|
||||
[humanMapping addAttributeMappingsFromArray:@[@"name", @"favoriteCatID"]];
|
||||
NSEntityDescription *entity = [NSEntityDescription entityForName:@"RKHuman" inManagedObjectContext:managedObjectContext];
|
||||
RKHuman *human = [[RKHuman alloc] initWithEntity:entity insertIntoManagedObjectContext:managedObjectContext];
|
||||
RKMappingOperation *mappingOperation = [RKMappingOperation mappingOperationFromObject:sourceObject toObject:human withMapping:humanMapping];
|
||||
@@ -77,11 +77,11 @@
|
||||
|
||||
RKEntityMapping *catMapping = [RKEntityMapping mappingForEntityForName:@"RKCat" inManagedObjectStore:managedObjectStore];
|
||||
catMapping.primaryKeyAttribute = @"railsID";
|
||||
[catMapping mapAttributes:@"name", nil];
|
||||
[catMapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
|
||||
RKEntityMapping *humanMapping = [RKEntityMapping mappingForEntityForName:@"RKHuman" inManagedObjectStore:managedObjectStore];
|
||||
humanMapping.primaryKeyAttribute = @"railsID";
|
||||
[humanMapping mapAttributes:@"name", @"favoriteCatID", nil];
|
||||
[humanMapping addAttributeMappingsFromArray:@[@"name", @"favoriteCatID"]];
|
||||
[humanMapping connectRelationship:@"favoriteCat" fromKeyPath:@"favoriteCatID" toKeyPath:@"railsID" withMapping:catMapping];
|
||||
|
||||
// Create a cat to connect
|
||||
@@ -111,11 +111,11 @@
|
||||
|
||||
RKEntityMapping *humanMapping = [RKEntityMapping mappingForEntityForName:@"RKHuman" inManagedObjectStore:managedObjectStore];
|
||||
humanMapping.primaryKeyAttribute = @"railsID";
|
||||
[humanMapping mapAttributes:@"name", @"favoriteCatID", nil];
|
||||
[humanMapping addAttributeMappingsFromArray:@[@"name", @"favoriteCatID"]];
|
||||
|
||||
RKEntityMapping *catMapping = [RKEntityMapping mappingForEntityForName:@"RKCat" inManagedObjectStore:managedObjectStore];
|
||||
catMapping.primaryKeyAttribute = @"railsID";
|
||||
[catMapping mapAttributes:@"name", @"railsID", nil];
|
||||
[catMapping addAttributeMappingsFromArray:@[@"name", @"railsID"]];
|
||||
[catMapping connectRelationship:@"favoriteOfHumans" fromKeyPath:@"railsID" toKeyPath:@"favoriteCatID" withMapping:humanMapping];
|
||||
|
||||
// Create some humans to connect
|
||||
@@ -159,11 +159,11 @@
|
||||
|
||||
RKEntityMapping *catMapping = [RKEntityMapping mappingForEntityForName:@"RKCat" inManagedObjectStore:managedObjectStore];
|
||||
catMapping.primaryKeyAttribute = @"railsID";
|
||||
[catMapping mapAttributes:@"name", nil];
|
||||
[catMapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
|
||||
RKEntityMapping *humanMapping = [RKEntityMapping mappingForEntityForName:@"RKHuman" inManagedObjectStore:managedObjectStore];
|
||||
humanMapping.primaryKeyAttribute = @"railsID";
|
||||
[humanMapping mapAttributes:@"name", @"favoriteCatID", nil];
|
||||
[humanMapping addAttributeMappingsFromArray:@[@"name", @"favoriteCatID"]];
|
||||
[humanMapping connectRelationship:@"favoriteCat" fromKeyPath:@"favoriteCatID" toKeyPath:@"railsID" withMapping:catMapping];
|
||||
|
||||
// Create a cat to connect
|
||||
@@ -192,11 +192,11 @@
|
||||
|
||||
RKEntityMapping *catMapping = [RKEntityMapping mappingForEntityForName:@"RKCat" inManagedObjectStore:managedObjectStore];
|
||||
catMapping.primaryKeyAttribute = @"railsID";
|
||||
[catMapping mapAttributes:@"name", nil];
|
||||
[catMapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
|
||||
RKEntityMapping *humanMapping = [RKEntityMapping mappingForEntityForName:@"RKHuman" inManagedObjectStore:managedObjectStore];
|
||||
humanMapping.primaryKeyAttribute = @"railsID";
|
||||
[humanMapping mapAttributes:@"name", @"favoriteCatID", nil];
|
||||
[humanMapping addAttributeMappingsFromArray:@[@"name", @"favoriteCatID"]];
|
||||
[humanMapping connectRelationship:@"favoriteCat" fromKeyPath:@"favoriteCatID" toKeyPath:@"railsID" withMapping:catMapping];
|
||||
|
||||
// Create a cat to connect
|
||||
@@ -225,11 +225,11 @@
|
||||
|
||||
RKEntityMapping *catMapping = [RKEntityMapping mappingForEntityForName:@"RKCat" inManagedObjectStore:managedObjectStore];
|
||||
catMapping.primaryKeyAttribute = @"railsID";
|
||||
[catMapping mapAttributes:@"name", nil];
|
||||
[catMapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
|
||||
RKEntityMapping *humanMapping = [RKEntityMapping mappingForEntityForName:@"RKHuman" inManagedObjectStore:managedObjectStore];
|
||||
humanMapping.primaryKeyAttribute = @"railsID";
|
||||
[humanMapping mapAttributes:@"name", @"catIDs", nil];
|
||||
[humanMapping addAttributeMappingsFromArray:@[@"name", @"catIDs"]];
|
||||
[humanMapping connectRelationship:@"cats" fromKeyPath:@"catIDs" toKeyPath:@"railsID" withMapping:catMapping];
|
||||
|
||||
// Create a couple of cats to connect
|
||||
@@ -266,11 +266,11 @@
|
||||
|
||||
RKEntityMapping *humanMapping = [RKEntityMapping mappingForEntityForName:@"RKHuman" inManagedObjectStore:managedObjectStore];
|
||||
humanMapping.primaryKeyAttribute = @"railsID";
|
||||
[humanMapping mapAttributes:@"name", @"railsID", nil];
|
||||
[humanMapping addAttributeMappingsFromArray:@[@"name", @"railsID"]];
|
||||
|
||||
RKEntityMapping *catMapping = [RKEntityMapping mappingForEntityForName:@"RKCat" inManagedObjectStore:managedObjectStore];
|
||||
catMapping.primaryKeyAttribute = @"railsID";
|
||||
[catMapping mapAttributes:@"name", @"humanId", nil];
|
||||
[catMapping addAttributeMappingsFromArray:@[@"name", @"humanId"]];
|
||||
[catMapping connectRelationship:@"human" fromKeyPath:@"humanId" toKeyPath:@"railsID" withMapping:humanMapping];
|
||||
|
||||
// Create a human to connect
|
||||
@@ -298,11 +298,11 @@
|
||||
RKManagedObjectStore *managedObjectStore = [RKTestFactory managedObjectStore];
|
||||
RKEntityMapping *catMapping = [RKEntityMapping mappingForEntityForName:@"RKCat" inManagedObjectStore:managedObjectStore];
|
||||
catMapping.primaryKeyAttribute = @"railsID";
|
||||
[catMapping mapAttributes:@"name", nil];
|
||||
[catMapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
|
||||
RKEntityMapping *humanMapping = [RKEntityMapping mappingForEntityForName:@"RKHuman" inManagedObjectStore:managedObjectStore];
|
||||
humanMapping.primaryKeyAttribute = @"railsID";
|
||||
[humanMapping mapAttributes:@"name", @"favoriteCatID", nil];
|
||||
[humanMapping addAttributeMappingsFromArray:@[@"name", @"favoriteCatID"]];
|
||||
[humanMapping hasMany:@"cats" withMapping:catMapping];
|
||||
|
||||
NSArray *catsData = [NSArray arrayWithObject:[NSDictionary dictionaryWithObject:@"Asia" forKey:@"name"]];
|
||||
@@ -323,12 +323,12 @@
|
||||
RKManagedObjectStore *managedObjectStore = [RKTestFactory managedObjectStore];
|
||||
RKEntityMapping *catMapping = [RKEntityMapping mappingForEntityForName:@"RKCat" inManagedObjectStore:managedObjectStore];
|
||||
catMapping.primaryKeyAttribute = @"railsID";
|
||||
[catMapping mapAttributes:@"name", nil];
|
||||
[catMapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
|
||||
RKEntityMapping *humanMapping = [RKEntityMapping mappingForEntityForName:@"RKHuman" inManagedObjectStore:managedObjectStore];
|
||||
humanMapping.primaryKeyAttribute = @"railsID";
|
||||
[humanMapping mapAttributes:@"name", @"favoriteCatID", nil];
|
||||
[humanMapping mapKeyPath:@"cats" toRelationship:@"catsInOrderByAge" withMapping:catMapping];
|
||||
[humanMapping addAttributeMappingsFromArray:@[@"name", @"favoriteCatID"]];
|
||||
[humanMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"cats" toKeyPath:@"catsInOrderByAge" withMapping:catMapping]];;
|
||||
|
||||
NSArray *catsData = [NSArray arrayWithObject:[NSDictionary dictionaryWithObject:@"Asia" forKey:@"name"]];
|
||||
NSDictionary *mappableData = [NSDictionary dictionaryWithKeysAndObjects:@"name", @"Blake", @"favoriteCatID", [NSNumber numberWithInt:31337], @"cats", catsData, nil];
|
||||
@@ -348,10 +348,10 @@
|
||||
{
|
||||
RKManagedObjectStore *managedObjectStore = [RKTestFactory managedObjectStore];
|
||||
RKEntityMapping *catMapping = [RKEntityMapping mappingForEntityForName:@"RKCat" inManagedObjectStore:managedObjectStore];
|
||||
[catMapping mapAttributes:@"name", nil];
|
||||
[catMapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
|
||||
RKEntityMapping *humanMapping = [RKEntityMapping mappingForEntityForName:@"RKHuman" inManagedObjectStore:managedObjectStore];
|
||||
[humanMapping mapAttributes:@"name", @"favoriteCatID", nil];
|
||||
[humanMapping addAttributeMappingsFromArray:@[@"name", @"favoriteCatID"]];
|
||||
[humanMapping hasMany:@"cats" withMapping:catMapping];
|
||||
|
||||
NSDictionary *mappableData = [NSDictionary dictionaryWithKeysAndObjects:@"name", @"Blake", @"cats", [NSNull null], nil];
|
||||
@@ -371,10 +371,10 @@
|
||||
{
|
||||
RKManagedObjectStore *managedObjectStore = [RKTestFactory managedObjectStore];
|
||||
RKEntityMapping *cloudMapping = [RKEntityMapping mappingForEntityForName:@"RKCloud" inManagedObjectStore:managedObjectStore];
|
||||
[cloudMapping mapAttributes:@"name", nil];
|
||||
[cloudMapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
|
||||
RKEntityMapping *stormMapping = [RKEntityMapping mappingForEntityForName:@"RKStorm" inManagedObjectStore:managedObjectStore];
|
||||
[stormMapping mapAttributes:@"name", @"favoriteCatID", nil];
|
||||
[stormMapping addAttributeMappingsFromArray:@[@"name", @"favoriteCatID"]];
|
||||
[stormMapping hasMany:@"clouds" withMapping:cloudMapping];
|
||||
|
||||
NSArray *cloudsData = [NSArray arrayWithObject:[NSDictionary dictionaryWithObject:@"Nimbus" forKey:@"name"]];
|
||||
@@ -397,11 +397,11 @@
|
||||
|
||||
RKEntityMapping *catMapping = [RKEntityMapping mappingForEntityForName:@"RKCat" inManagedObjectStore:managedObjectStore];
|
||||
catMapping.primaryKeyAttribute = @"railsID";
|
||||
[catMapping mapAttributes:@"name", nil];
|
||||
[catMapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
|
||||
RKEntityMapping *humanMapping = [RKEntityMapping mappingForEntityForName:@"RKHuman" inManagedObjectStore:managedObjectStore];
|
||||
humanMapping.primaryKeyAttribute = @"railsID";
|
||||
[humanMapping mapAttributes:@"name", @"favoriteCatID", nil];
|
||||
[humanMapping addAttributeMappingsFromArray:@[@"name", @"favoriteCatID"]];
|
||||
[humanMapping connectRelationship:@"favoriteCat" fromKeyPath:@"favoriteCatID" toKeyPath:@"railsID" withMapping:catMapping whenValueOfKeyPath:@"name" isEqualTo:@"Blake"];
|
||||
|
||||
// Create a cat to connect
|
||||
@@ -430,11 +430,11 @@
|
||||
|
||||
RKEntityMapping *catMapping = [RKEntityMapping mappingForEntityForName:@"RKCat" inManagedObjectStore:managedObjectStore];
|
||||
catMapping.primaryKeyAttribute = @"railsID";
|
||||
[catMapping mapAttributes:@"name", nil];
|
||||
[catMapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
|
||||
RKEntityMapping *humanMapping = [RKEntityMapping mappingForEntityForName:@"RKHuman" inManagedObjectStore:managedObjectStore];
|
||||
humanMapping.primaryKeyAttribute = @"railsID";
|
||||
[humanMapping mapAttributes:@"name", @"favoriteCatID", nil];
|
||||
[humanMapping addAttributeMappingsFromArray:@[@"name", @"favoriteCatID"]];
|
||||
[humanMapping connectRelationship:@"favoriteCat" fromKeyPath:@"favoriteCatID" toKeyPath:@"railsID" withMapping:catMapping whenValueOfKeyPath:@"name" isEqualTo:@"Jeff"];
|
||||
|
||||
// Create a cat to connect
|
||||
@@ -461,11 +461,11 @@
|
||||
RKManagedObjectStore *managedObjectStore = [RKTestFactory managedObjectStore];
|
||||
RKEntityMapping *childMapping = [RKEntityMapping mappingForEntityForName:@"RKChild" inManagedObjectStore:managedObjectStore];
|
||||
childMapping.primaryKeyAttribute = @"railsID";
|
||||
[childMapping mapAttributes:@"name", nil];
|
||||
[childMapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
|
||||
RKEntityMapping *parentMapping = [RKEntityMapping mappingForEntityForName:@"RKParent" inManagedObjectStore:managedObjectStore];
|
||||
parentMapping.primaryKeyAttribute = @"railsID";
|
||||
[parentMapping mapAttributes:@"name", @"age", nil];
|
||||
[parentMapping addAttributeMappingsFromArray:@[@"name", @"age"]];
|
||||
[parentMapping hasMany:@"children" withMapping:childMapping];
|
||||
|
||||
NSArray *childMappableData = [NSArray arrayWithObjects:[NSDictionary dictionaryWithKeysAndObjects:@"name", @"Maya", nil],
|
||||
@@ -495,11 +495,11 @@
|
||||
NSManagedObjectContext *managedObjectContext = managedObjectStore.primaryManagedObjectContext;
|
||||
|
||||
RKEntityMapping *parentMapping = [RKEntityMapping mappingForEntityForName:@"RKParent" inManagedObjectStore:managedObjectStore];
|
||||
[parentMapping mapAttributes:@"parentID", nil];
|
||||
[parentMapping addAttributeMappingsFromArray:@[@"parentID"]];
|
||||
parentMapping.primaryKeyAttribute = @"parentID";
|
||||
|
||||
RKEntityMapping *childMapping = [RKEntityMapping mappingForEntityForName:@"RKChild" inManagedObjectStore:managedObjectStore];
|
||||
[childMapping mapAttributes:@"fatherID", nil];
|
||||
[childMapping addAttributeMappingsFromArray:@[@"fatherID"]];
|
||||
[childMapping connectRelationship:@"father" fromKeyPath:@"fatherID" toKeyPath:@"parentID" withMapping:parentMapping];
|
||||
|
||||
RKObjectMappingProvider *mappingProvider = [RKObjectMappingProvider new];
|
||||
@@ -516,7 +516,7 @@
|
||||
[operationQueue setSuspended:YES];
|
||||
mappingOperationDataSource.operationQueue = operationQueue;
|
||||
[managedObjectContext performBlockAndWait:^{
|
||||
RKObjectMapper *mapper = [RKObjectMapper mapperWithObject:JSON mappingProvider:mappingProvider];
|
||||
RKMapperOperation *mapper = [[RKMapperOperation alloc] initWithObject:JSON mappingsDictionary:mappingsDictionary];
|
||||
mapper.mappingOperationDataSource = mappingOperationDataSource;
|
||||
[mapper performMapping];
|
||||
}];
|
||||
@@ -549,10 +549,10 @@
|
||||
|
||||
RKEntityMapping *childMapping = [RKEntityMapping mappingForEntityForName:@"RKChild" inManagedObjectStore:managedObjectStore];
|
||||
childMapping.primaryKeyAttribute = @"childID";
|
||||
[childMapping mapAttributes:@"name", @"childID", nil];
|
||||
[childMapping addAttributeMappingsFromArray:@[@"name", @"childID"]];
|
||||
|
||||
RKEntityMapping *parentMapping = [RKEntityMapping mappingForEntityForName:@"RKParent" inManagedObjectStore:managedObjectStore];
|
||||
[parentMapping mapAttributes:@"parentID", @"name", nil];
|
||||
[parentMapping addAttributeMappingsFromArray:@[@"parentID", @"name"]];
|
||||
parentMapping.primaryKeyAttribute = @"parentID";
|
||||
[parentMapping mapRelationship:@"children" withMapping:childMapping];
|
||||
|
||||
@@ -562,7 +562,7 @@
|
||||
[mappingProvider setObjectMapping:parentMapping forKeyPath:@"parents"];
|
||||
|
||||
NSDictionary *JSON = [RKTestFixture parsedObjectWithContentsOfFixture:@"parents_and_children.json"];
|
||||
RKObjectMapper *mapper = [RKObjectMapper mapperWithObject:JSON mappingProvider:mappingProvider];
|
||||
RKMapperOperation *mapper = [[RKMapperOperation alloc] initWithObject:JSON mappingsDictionary:mappingsDictionary];
|
||||
mapper.mappingOperationDataSource = mappingOperationDataSource;
|
||||
[mapper performMapping];
|
||||
|
||||
@@ -582,10 +582,10 @@
|
||||
|
||||
RKEntityMapping *childMapping = [RKEntityMapping mappingForEntityForName:@"RKChild" inManagedObjectStore:managedObjectStore];
|
||||
childMapping.primaryKeyAttribute = @"childID";
|
||||
[childMapping mapAttributes:@"name", @"childID", nil];
|
||||
[childMapping addAttributeMappingsFromArray:@[@"name", @"childID"]];
|
||||
|
||||
RKEntityMapping *parentMapping = [RKEntityMapping mappingForEntityForName:@"RKParent" inManagedObjectStore:managedObjectStore];
|
||||
[parentMapping mapAttributes:@"parentID", @"name", nil];
|
||||
[parentMapping addAttributeMappingsFromArray:@[@"parentID", @"name"]];
|
||||
parentMapping.primaryKeyAttribute = @"parentID";
|
||||
[parentMapping mapRelationship:@"children" withMapping:childMapping];
|
||||
|
||||
@@ -595,7 +595,7 @@
|
||||
[mappingProvider setObjectMapping:parentMapping forKeyPath:@"parents"];
|
||||
|
||||
NSDictionary *JSON = [RKTestFixture parsedObjectWithContentsOfFixture:@"parents_and_children.json"];
|
||||
RKObjectMapper *mapper = [RKObjectMapper mapperWithObject:JSON mappingProvider:mappingProvider];
|
||||
RKMapperOperation *mapper = [[RKMapperOperation alloc] initWithObject:JSON mappingsDictionary:mappingsDictionary];
|
||||
mapper.mappingOperationDataSource = mappingOperationDataSource;
|
||||
[mapper performMapping];
|
||||
|
||||
@@ -622,10 +622,10 @@
|
||||
|
||||
RKEntityMapping *childMapping = [RKEntityMapping mappingForEntityForName:@"RKChild" inManagedObjectStore:managedObjectStore];
|
||||
childMapping.primaryKeyAttribute = @"childID";
|
||||
[childMapping mapAttributes:@"name", @"childID", nil];
|
||||
[childMapping addAttributeMappingsFromArray:@[@"name", @"childID"]];
|
||||
|
||||
RKEntityMapping *parentMapping = [RKEntityMapping mappingForEntityForName:@"RKParent" inManagedObjectStore:managedObjectStore];
|
||||
[parentMapping mapAttributes:@"parentID", @"name", nil];
|
||||
[parentMapping addAttributeMappingsFromArray:@[@"parentID", @"name"]];
|
||||
parentMapping.primaryKeyAttribute = @"parentID";
|
||||
[parentMapping mapRelationship:@"children" withMapping:childMapping];
|
||||
|
||||
@@ -635,7 +635,7 @@
|
||||
[mappingProvider setObjectMapping:parentMapping forKeyPath:@"parents"];
|
||||
|
||||
NSDictionary *JSON = [RKTestFixture parsedObjectWithContentsOfFixture:@"benchmark_parents_and_children.json"];
|
||||
RKObjectMapper *mapper = [RKObjectMapper mapperWithObject:JSON mappingProvider:mappingProvider];
|
||||
RKMapperOperation *mapper = [[RKMapperOperation alloc] initWithObject:JSON mappingsDictionary:mappingsDictionary];
|
||||
mapper.mappingOperationDataSource = mappingOperationDataSource;
|
||||
|
||||
RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelOff);
|
||||
@@ -662,10 +662,10 @@
|
||||
|
||||
RKEntityMapping *childMapping = [RKEntityMapping mappingForEntityForName:@"RKChild" inManagedObjectStore:managedObjectStore];
|
||||
childMapping.primaryKeyAttribute = @"childID";
|
||||
[childMapping mapAttributes:@"name", @"childID", nil];
|
||||
[childMapping addAttributeMappingsFromArray:@[@"name", @"childID"]];
|
||||
|
||||
RKEntityMapping *parentMapping = [RKEntityMapping mappingForEntityForName:@"RKParent" inManagedObjectStore:managedObjectStore];
|
||||
[parentMapping mapAttributes:@"parentID", @"name", nil];
|
||||
[parentMapping addAttributeMappingsFromArray:@[@"parentID", @"name"]];
|
||||
parentMapping.primaryKeyAttribute = @"parentID";
|
||||
[parentMapping mapRelationship:@"children" withMapping:childMapping];
|
||||
|
||||
@@ -675,7 +675,7 @@
|
||||
[mappingProvider setObjectMapping:parentMapping forKeyPath:@"parents"];
|
||||
|
||||
NSDictionary *JSON = [RKTestFixture parsedObjectWithContentsOfFixture:@"benchmark_parents_and_children.json"];
|
||||
RKObjectMapper *mapper = [RKObjectMapper mapperWithObject:JSON mappingProvider:mappingProvider];
|
||||
RKMapperOperation *mapper = [[RKMapperOperation alloc] initWithObject:JSON mappingsDictionary:mappingsDictionary];
|
||||
mapper.mappingOperationDataSource = mappingOperationDataSource;
|
||||
RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelOff);
|
||||
RKLogConfigureByName("RestKit/CoreData", RKLogLevelOff);
|
||||
@@ -699,11 +699,11 @@
|
||||
|
||||
RKEntityMapping* catMapping = [RKEntityMapping mappingForEntityForName:@"RKCat" inManagedObjectStore:managedObjectStore];
|
||||
catMapping.primaryKeyAttribute = @"railsID";
|
||||
[catMapping mapAttributes:@"name", nil];
|
||||
[catMapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
|
||||
RKEntityMapping* humanMapping = [RKEntityMapping mappingForEntityForName:@"RKHuman" inManagedObjectStore:managedObjectStore];
|
||||
humanMapping.primaryKeyAttribute = @"railsID";
|
||||
[humanMapping mapAttributes:@"name", @"favoriteCatID", nil];
|
||||
[humanMapping addAttributeMappingsFromArray:@[@"name", @"favoriteCatID"]];
|
||||
[humanMapping hasOne:@"favoriteCat" withMapping:catMapping];
|
||||
[humanMapping connectRelationship:@"favoriteCat" withObjectForPrimaryKeyAttribute:@"favoriteCatID"];
|
||||
|
||||
@@ -732,11 +732,11 @@
|
||||
|
||||
RKEntityMapping* catMapping = [RKEntityMapping mappingForEntityForName:@"RKCat" inManagedObjectStore:managedObjectStore];
|
||||
catMapping.primaryKeyAttribute = @"railsID";
|
||||
[catMapping mapAttributes:@"name", nil];
|
||||
[catMapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
|
||||
RKEntityMapping* humanMapping = [RKEntityMapping mappingForEntityForName:@"RKHuman" inManagedObjectStore:managedObjectStore];
|
||||
humanMapping.primaryKeyAttribute = @"railsID";
|
||||
[humanMapping mapAttributes:@"name", @"favoriteCatID", nil];
|
||||
[humanMapping addAttributeMappingsFromArray:@[@"name", @"favoriteCatID"]];
|
||||
[humanMapping hasOne:@"favoriteCat" withMapping:catMapping];
|
||||
[humanMapping connectRelationship:@"favoriteCat" withObjectForPrimaryKeyAttribute:@"favoriteCatID"];
|
||||
|
||||
@@ -765,11 +765,11 @@
|
||||
|
||||
RKEntityMapping* catMapping = [RKEntityMapping mappingForEntityForName:@"RKCat" inManagedObjectStore:managedObjectStore];
|
||||
catMapping.primaryKeyAttribute = @"railsID";
|
||||
[catMapping mapAttributes:@"name", nil];
|
||||
[catMapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
|
||||
RKEntityMapping* humanMapping = [RKEntityMapping mappingForEntityForName:@"RKHuman" inManagedObjectStore:managedObjectStore];
|
||||
humanMapping.primaryKeyAttribute = @"railsID";
|
||||
[humanMapping mapAttributes:@"name", @"favoriteCatID", nil];
|
||||
[humanMapping addAttributeMappingsFromArray:@[@"name", @"favoriteCatID"]];
|
||||
[humanMapping hasOne:@"favoriteCat" withMapping:catMapping];
|
||||
[humanMapping connectRelationship:@"favoriteCat" withObjectForPrimaryKeyAttribute:@"favoriteCatID"];
|
||||
|
||||
@@ -798,11 +798,11 @@
|
||||
|
||||
RKEntityMapping* catMapping = [RKEntityMapping mappingForEntityForName:@"RKCat" inManagedObjectStore:managedObjectStore];
|
||||
catMapping.primaryKeyAttribute = @"railsID";
|
||||
[catMapping mapAttributes:@"name", nil];
|
||||
[catMapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
|
||||
RKEntityMapping* humanMapping = [RKEntityMapping mappingForEntityForName:@"RKHuman" inManagedObjectStore:managedObjectStore];
|
||||
humanMapping.primaryKeyAttribute = @"railsID";
|
||||
[humanMapping mapAttributes:@"name", @"favoriteCatID", @"catIDs", nil];
|
||||
[humanMapping addAttributeMappingsFromArray:@[@"name", @"favoriteCatID", @"catIDs"]];
|
||||
[humanMapping mapRelationship:@"cats" withMapping:catMapping];
|
||||
[humanMapping connectRelationship:@"cats" withObjectForPrimaryKeyAttribute:@"catIDs"];
|
||||
|
||||
@@ -838,11 +838,11 @@
|
||||
|
||||
RKEntityMapping* catMapping = [RKEntityMapping mappingForEntityForName:@"RKCat" inManagedObjectStore:managedObjectStore];
|
||||
catMapping.primaryKeyAttribute = @"railsID";
|
||||
[catMapping mapAttributes:@"name", nil];
|
||||
[catMapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
|
||||
RKEntityMapping* humanMapping = [RKEntityMapping mappingForEntityForName:@"RKHuman" inManagedObjectStore:managedObjectStore];
|
||||
humanMapping.primaryKeyAttribute = @"railsID";
|
||||
[humanMapping mapAttributes:@"name", @"favoriteCatID", nil];
|
||||
[humanMapping addAttributeMappingsFromArray:@[@"name", @"favoriteCatID"]];
|
||||
[humanMapping hasOne:@"favoriteCat" withMapping:catMapping];
|
||||
[humanMapping connectRelationship:@"favoriteCat" withObjectForPrimaryKeyAttribute:@"favoriteCatID" whenValueOfKeyPath:@"name" isEqualTo:@"Blake"];
|
||||
|
||||
@@ -871,11 +871,11 @@
|
||||
|
||||
RKEntityMapping* catMapping = [RKEntityMapping mappingForEntityForName:@"RKCat" inManagedObjectStore:managedObjectStore];
|
||||
catMapping.primaryKeyAttribute = @"railsID";
|
||||
[catMapping mapAttributes:@"name", nil];
|
||||
[catMapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
|
||||
RKEntityMapping* humanMapping = [RKEntityMapping mappingForEntityForName:@"RKHuman" inManagedObjectStore:managedObjectStore];
|
||||
humanMapping.primaryKeyAttribute = @"railsID";
|
||||
[humanMapping mapAttributes:@"name", @"favoriteCatID", nil];
|
||||
[humanMapping addAttributeMappingsFromArray:@[@"name", @"favoriteCatID"]];
|
||||
[humanMapping hasOne:@"favoriteCat" withMapping:catMapping];
|
||||
[humanMapping connectRelationship:@"favoriteCat" withObjectForPrimaryKeyAttribute:@"favoriteCatID" whenValueOfKeyPath:@"name" isEqualTo:@"Jeff"];
|
||||
|
||||
@@ -902,11 +902,11 @@
|
||||
RKManagedObjectStore *managedObjectStore = [RKTestFactory managedObjectStore];
|
||||
NSManagedObjectContext *managedObjectContext = managedObjectStore.primaryManagedObjectContext;
|
||||
RKEntityMapping *parentMapping = [RKEntityMapping mappingForEntityForName:@"RKParent" inManagedObjectStore:managedObjectStore];
|
||||
[parentMapping mapAttributes:@"parentID", nil];
|
||||
[parentMapping addAttributeMappingsFromArray:@[@"parentID"]];
|
||||
parentMapping.primaryKeyAttribute = @"parentID";
|
||||
|
||||
RKEntityMapping *childMapping = [RKEntityMapping mappingForEntityForName:@"RKChild" inManagedObjectStore:managedObjectStore];
|
||||
[childMapping mapAttributes:@"fatherID", nil];
|
||||
[childMapping addAttributeMappingsFromArray:@[@"fatherID"]];
|
||||
[childMapping mapRelationship:@"father" withMapping:parentMapping];
|
||||
[childMapping connectRelationship:@"father" withObjectForPrimaryKeyAttribute:@"fatherID"];
|
||||
|
||||
@@ -927,7 +927,7 @@
|
||||
|
||||
__block RKMappingResult *result;
|
||||
[managedObjectContext performBlockAndWait:^{
|
||||
RKObjectMapper *mapper = [RKObjectMapper mapperWithObject:JSON mappingProvider:mappingProvider];
|
||||
RKMapperOperation *mapper = [[RKMapperOperation alloc] initWithObject:JSON mappingsDictionary:mappingsDictionary];
|
||||
mapper.mappingOperationDataSource = mappingOperationDataSource;
|
||||
result = [mapper performMapping];
|
||||
}];
|
||||
|
||||
@@ -61,10 +61,10 @@
|
||||
mapping.forceCollectionMapping = YES;
|
||||
mapping.primaryKeyAttribute = @"name";
|
||||
[mapping mapKeyOfNestedDictionaryToAttribute:@"name"];
|
||||
RKAttributeMapping *idMapping = [RKAttributeMapping mappingFromKeyPath:@"(name).id" toKeyPath:@"railsID"];
|
||||
[mapping addAttributeMapping:idMapping];
|
||||
RKObjectMappingProvider *provider = [[RKObjectMappingProvider new] autorelease];
|
||||
[provider setMapping:mapping forKeyPath:@"users"];
|
||||
RKAttributeMapping *idMapping = [RKAttributeMapping attributeMappingFromKeyPath:@"(name).id" toKeyPath:@"railsID"];
|
||||
[mapping addPropertyMapping:idMapping];
|
||||
NSMutableDictionary *mappingDictionary = [NSMutableDictionary dictionary];
|
||||
[mappingsDictionary setObject:mapping forKey:@"users"];
|
||||
|
||||
id mockCacheStrategy = [OCMockObject partialMockForObject:managedObjectStore.managedObjectCache];
|
||||
[[[mockCacheStrategy expect] andForwardToRealObject] findInstanceOfEntity:OCMOCK_ANY
|
||||
@@ -76,7 +76,7 @@
|
||||
value:@"rachit"
|
||||
inManagedObjectContext:managedObjectStore.primaryManagedObjectContext];
|
||||
id userInfo = [RKTestFixture parsedObjectWithContentsOfFixture:@"DynamicKeys.json"];
|
||||
RKObjectMapper *mapper = [RKObjectMapper mapperWithObject:userInfo mappingProvider:provider];
|
||||
RKMapperOperation *mapper = [[RKMapperOperation alloc] initWithObject:userInfo mappingsDictionary:mappingsDictionary];
|
||||
RKManagedObjectMappingOperationDataSource *dataSource = [[RKManagedObjectMappingOperationDataSource alloc] initWithManagedObjectContext:managedObjectStore.primaryManagedObjectContext
|
||||
cache:managedObjectStore.managedObjectCache];
|
||||
mapper.mappingOperationDataSource = dataSource;
|
||||
@@ -87,14 +87,14 @@
|
||||
- (void)testShouldPickTheAppropriateMappingBasedOnAnAttributeValue
|
||||
{
|
||||
RKManagedObjectStore *managedObjectStore = [RKTestFactory managedObjectStore];
|
||||
RKDynamicMapping *dynamicMapping = [RKDynamicMapping dynamicMapping];
|
||||
RKDynamicMapping *dynamicMapping = [RKDynamicMapping new];
|
||||
RKEntityMapping *childMapping = [RKEntityMapping mappingForEntityForName:@"RKChild" inManagedObjectStore:managedObjectStore];
|
||||
childMapping.primaryKeyAttribute = @"railsID";
|
||||
[childMapping mapAttributes:@"name", nil];
|
||||
[childMapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
|
||||
RKEntityMapping *parentMapping = [RKEntityMapping mappingForEntityForName:@"RKParent" inManagedObjectStore:managedObjectStore];
|
||||
parentMapping.primaryKeyAttribute = @"railsID";
|
||||
[parentMapping mapAttributes:@"name", @"age", nil];
|
||||
[parentMapping addAttributeMappingsFromArray:@[@"name", @"age"]];
|
||||
|
||||
[dynamicMapping setObjectMapping:parentMapping whenValueOfKeyPath:@"type" isEqualTo:@"Parent"];
|
||||
[dynamicMapping setObjectMapping:childMapping whenValueOfKeyPath:@"type" isEqualTo:@"Child"];
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
#import "RKTestEnvironment.h"
|
||||
#import "RKHuman.h"
|
||||
#import "RKDirectoryUtilities.h"
|
||||
#import "RKPathUtilities.h"
|
||||
|
||||
@interface RKManagedObjectStoreTest : RKTestCase
|
||||
|
||||
@@ -49,13 +49,6 @@
|
||||
[RKTestFactory tearDown];
|
||||
}
|
||||
|
||||
- (void)testInstantiationOfNewManagedObjectContextAssociatesWithObjectStore
|
||||
{
|
||||
RKManagedObjectStore *managedObjectStore = [RKTestFactory managedObjectStore];
|
||||
NSManagedObjectContext *context = [managedObjectStore newChildManagedObjectContextWithConcurrencyType:NSMainQueueConcurrencyType];
|
||||
assertThat([context managedObjectStore], is(equalTo(managedObjectStore)));
|
||||
}
|
||||
|
||||
- (void)testAdditionOfSQLiteStoreRetainsPathOfSeedDatabase
|
||||
{
|
||||
// Create a store with a SQLite database to use as our store
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
//
|
||||
// RKAuthenticationTest.m
|
||||
// RestKit
|
||||
//
|
||||
// Created by Blake Watters on 3/14/11.
|
||||
// Copyright (c) 2009-2012 RestKit. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
#import "RKTestEnvironment.h"
|
||||
#import "RKClient.h"
|
||||
|
||||
static NSString * const RKAuthenticationTestUsername = @"restkit";
|
||||
static NSString * const RKAuthenticationTestPassword = @"authentication";
|
||||
|
||||
@interface RKAuthenticationTest : RKTestCase {
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation RKAuthenticationTest
|
||||
|
||||
- (void)testShouldAccessUnprotectedResourcePaths
|
||||
{
|
||||
RKTestResponseLoader *loader = [RKTestResponseLoader responseLoader];
|
||||
RKClient *client = [RKTestFactory client];
|
||||
[client get:@"/authentication/none" delegate:loader];
|
||||
[loader waitForResponse];
|
||||
assertThatBool([loader.response isOK], is(equalToBool(YES)));
|
||||
}
|
||||
|
||||
- (void)testShouldAuthenticateViaHTTPAuthBasic
|
||||
{
|
||||
RKTestResponseLoader *loader = [RKTestResponseLoader responseLoader];
|
||||
RKClient *client = [RKTestFactory client];
|
||||
client.username = RKAuthenticationTestUsername;
|
||||
client.password = RKAuthenticationTestPassword;
|
||||
[client get:@"/authentication/basic" delegate:loader];
|
||||
[loader waitForResponse];
|
||||
assertThatBool([loader.response isOK], is(equalToBool(YES)));
|
||||
}
|
||||
|
||||
- (void)testShouldFailAuthenticationWithInvalidCredentialsForHTTPAuthBasic
|
||||
{
|
||||
RKTestResponseLoader *loader = [RKTestResponseLoader new];
|
||||
RKClient *client = [RKTestFactory client];
|
||||
client.username = RKAuthenticationTestUsername;
|
||||
client.password = @"INVALID";
|
||||
[client get:@"/authentication/basic" delegate:loader];
|
||||
[loader waitForResponse];
|
||||
assertThatBool([loader.response isOK], is(equalToBool(NO)));
|
||||
assertThatInteger([loader.response statusCode], is(equalToInt(0)));
|
||||
assertThatInteger([loader.error code], is(equalToInt(NSURLErrorUserCancelledAuthentication)));
|
||||
[loader.response.request cancel];
|
||||
[loader release];
|
||||
}
|
||||
|
||||
- (void)testShouldAuthenticateViaHTTPAuthDigest
|
||||
{
|
||||
RKTestResponseLoader *loader = [RKTestResponseLoader responseLoader];
|
||||
RKClient *client = [RKTestFactory client];
|
||||
client.username = RKAuthenticationTestUsername;
|
||||
client.password = RKAuthenticationTestPassword;
|
||||
[client get:@"/authentication/digest" delegate:loader];
|
||||
[loader waitForResponse];
|
||||
assertThatBool([loader.response isOK], is(equalToBool(YES)));
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,190 +0,0 @@
|
||||
//
|
||||
// RKClientTest.m
|
||||
// RestKit
|
||||
//
|
||||
// Created by Blake Watters on 1/31/11.
|
||||
// Copyright (c) 2009-2012 RestKit. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
#import <SenTestingKit/SenTestingKit.h>
|
||||
#import "RKTestEnvironment.h"
|
||||
#import "RKURL.h"
|
||||
|
||||
@interface RKClientTest : RKTestCase
|
||||
@end
|
||||
|
||||
|
||||
@implementation RKClientTest
|
||||
|
||||
- (void)setUp
|
||||
{
|
||||
[RKTestFactory setUp];
|
||||
}
|
||||
|
||||
- (void)tearDown
|
||||
{
|
||||
[RKTestFactory tearDown];
|
||||
}
|
||||
|
||||
- (void)testShouldDetectNetworkStatusWithAHostname
|
||||
{
|
||||
RKClient *client = [[RKClient alloc] initWithBaseURLString:@"http://restkit.org"];
|
||||
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.3]]; // Let the runloop cycle
|
||||
RKReachabilityNetworkStatus status = [client.reachabilityObserver networkStatus];
|
||||
assertThatInt(status, is(equalToInt(RKReachabilityReachableViaWiFi)));
|
||||
[client release];
|
||||
}
|
||||
|
||||
- (void)testShouldDetectNetworkStatusWithAnIPAddressBaseName
|
||||
{
|
||||
RKClient *client = [[RKClient alloc] initWithBaseURLString:@"http://173.45.234.197"];
|
||||
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.3]]; // Let the runloop cycle
|
||||
RKReachabilityNetworkStatus status = [client.reachabilityObserver networkStatus];
|
||||
assertThatInt(status, isNot(equalToInt(RKReachabilityIndeterminate)));
|
||||
[client release];
|
||||
}
|
||||
|
||||
- (void)testShouldSetTheCachePolicyOfTheRequest
|
||||
{
|
||||
RKClient *client = [RKClient clientWithBaseURLString:@"http://restkit.org"];
|
||||
client.cachePolicy = RKRequestCachePolicyLoadIfOffline;
|
||||
RKRequest *request = [client requestWithResourcePath:@""];
|
||||
assertThatInt(request.cachePolicy, is(equalToInt(RKRequestCachePolicyLoadIfOffline)));
|
||||
}
|
||||
|
||||
- (void)testShouldInitializeTheCacheOfTheRequest
|
||||
{
|
||||
RKClient *client = [RKClient clientWithBaseURLString:@"http://restkit.org"];
|
||||
client.requestCache = [[[RKRequestCache alloc] init] autorelease];
|
||||
RKRequest *request = [client requestWithResourcePath:@""];
|
||||
assertThat(request.cache, is(equalTo(client.requestCache)));
|
||||
}
|
||||
|
||||
- (void)testShouldLoadPageWithNoContentTypeInformation
|
||||
{
|
||||
RKClient *client = [RKClient clientWithBaseURLString:@"http://www.semiose.fr"];
|
||||
client.defaultHTTPEncoding = NSISOLatin1StringEncoding;
|
||||
RKTestResponseLoader *loader = [RKTestResponseLoader responseLoader];
|
||||
RKRequest *request = [client requestWithResourcePath:@"/"];
|
||||
request.delegate = loader;
|
||||
[request send];
|
||||
[loader waitForResponse];
|
||||
assertThatBool(loader.wasSuccessful, is(equalToBool(YES)));
|
||||
assertThat([loader.response bodyEncodingName], is(nilValue()));
|
||||
assertThatInteger([loader.response bodyEncoding], is(equalToInteger(NSISOLatin1StringEncoding)));
|
||||
}
|
||||
|
||||
- (void)testShouldAllowYouToChangeTheBaseURL
|
||||
{
|
||||
RKClient *client = [RKClient clientWithBaseURLString:@"http://www.google.com"];
|
||||
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.3]]; // Let the runloop cycle
|
||||
assertThatBool([client isNetworkReachable], is(equalToBool(YES)));
|
||||
client.baseURL = [RKURL URLWithString:@"http://www.restkit.org"];
|
||||
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.3]]; // Let the runloop cycle
|
||||
assertThatBool([client isNetworkReachable], is(equalToBool(YES)));
|
||||
RKTestResponseLoader *loader = [RKTestResponseLoader responseLoader];
|
||||
RKRequest *request = [client requestWithResourcePath:@"/"];
|
||||
request.delegate = loader;
|
||||
[request send];
|
||||
[loader waitForResponse];
|
||||
assertThatBool(loader.wasSuccessful, is(equalToBool(YES)));
|
||||
}
|
||||
|
||||
- (void)testShouldLetYouChangeTheHTTPAuthCredentials
|
||||
{
|
||||
RKClient *client = [RKTestFactory client];
|
||||
client.authenticationType = RKRequestAuthenticationTypeHTTP;
|
||||
client.username = @"invalid";
|
||||
client.password = @"password";
|
||||
RKTestResponseLoader *responseLoader = [RKTestResponseLoader responseLoader];
|
||||
[client get:@"/authentication/basic" delegate:responseLoader];
|
||||
[responseLoader waitForResponse];
|
||||
assertThatBool(responseLoader.wasSuccessful, is(equalToBool(NO)));
|
||||
assertThat(responseLoader.error, is(notNilValue()));
|
||||
client.username = @"restkit";
|
||||
client.password = @"authentication";
|
||||
[client get:@"/authentication/basic" delegate:responseLoader];
|
||||
[responseLoader waitForResponse];
|
||||
assertThatBool(responseLoader.wasSuccessful, is(equalToBool(YES)));
|
||||
}
|
||||
|
||||
- (void)testShouldSuspendTheQueueOnBaseURLChangeWhenReachabilityHasNotBeenEstablished
|
||||
{
|
||||
RKClient *client = [RKClient clientWithBaseURLString:@"http://www.google.com"];
|
||||
client.baseURL = [RKURL URLWithString:@"http://restkit.org"];
|
||||
assertThatBool(client.requestQueue.suspended, is(equalToBool(YES)));
|
||||
}
|
||||
|
||||
- (void)testShouldNotSuspendTheMainQueueOnBaseURLChangeWhenReachabilityHasBeenEstablished
|
||||
{
|
||||
RKReachabilityObserver *observer = [RKReachabilityObserver reachabilityObserverForInternet];
|
||||
[observer getFlags];
|
||||
assertThatBool([observer isReachabilityDetermined], is(equalToBool(YES)));
|
||||
RKClient *client = [RKClient clientWithBaseURLString:@"http://www.google.com"];
|
||||
assertThatBool(client.requestQueue.suspended, is(equalToBool(YES)));
|
||||
client.reachabilityObserver = observer;
|
||||
assertThatBool(client.requestQueue.suspended, is(equalToBool(NO)));
|
||||
}
|
||||
|
||||
- (void)testShouldAllowYouToChangeTheTimeoutInterval
|
||||
{
|
||||
RKClient *client = [RKClient clientWithBaseURLString:@"http://restkit.org"];
|
||||
client.timeoutInterval = 20.0;
|
||||
RKRequest *request = [client requestWithResourcePath:@""];
|
||||
assertThatFloat(request.timeoutInterval, is(equalToFloat(20.0)));
|
||||
}
|
||||
|
||||
- (void)testShouldPerformAPUTWithParams
|
||||
{
|
||||
NSLog(@"PENDING ---> FIX ME!!!");
|
||||
return;
|
||||
RKClient *client = [RKClient clientWithBaseURLString:@"http://ohblockhero.appspot.com/api/v1"];
|
||||
client.cachePolicy = RKRequestCachePolicyNone;
|
||||
RKParams *params = [RKParams params];
|
||||
[params setValue:@"username" forParam:@"username"];
|
||||
[params setValue:@"Dear Daniel" forParam:@"fullName"];
|
||||
[params setValue:@"aa@aa.com" forParam:@"email"];
|
||||
RKTestResponseLoader *loader = [RKTestResponseLoader responseLoader];
|
||||
[client put:@"/userprofile" params:params delegate:loader];
|
||||
STAssertNoThrow([loader waitForResponse], @"");
|
||||
[loader waitForResponse];
|
||||
assertThatBool(loader.wasSuccessful, is(equalToBool(NO)));
|
||||
}
|
||||
|
||||
- (void)testShouldAllowYouToChangeTheCacheTimeoutInterval
|
||||
{
|
||||
RKClient *client = [RKClient clientWithBaseURLString:@"http://restkit.org"];
|
||||
client.cacheTimeoutInterval = 20.0;
|
||||
RKRequest *request = [client requestWithResourcePath:@""];
|
||||
assertThatFloat(request.cacheTimeoutInterval, is(equalToFloat(20.0)));
|
||||
}
|
||||
|
||||
- (void)testThatRunLoopModePropertyRespected
|
||||
{
|
||||
// FIXME: This test results in the suite hanging for some reason...
|
||||
RKLogCritical(@"Test disabled");
|
||||
return;
|
||||
NSString * const dummyRunLoopMode = @"dummyRunLoopMode";
|
||||
RKTestResponseLoader *loader = [RKTestResponseLoader responseLoader];
|
||||
RKClient *client = [RKTestFactory client];
|
||||
client.runLoopMode = dummyRunLoopMode;
|
||||
[client get:[[RKTestFactory baseURL] absoluteString] delegate:loader];
|
||||
for (NSUInteger i = 0; i < 25; i++) {
|
||||
[[NSRunLoop currentRunLoop] runMode:dummyRunLoopMode beforeDate:[[NSRunLoop currentRunLoop] limitDateForMode:dummyRunLoopMode]];
|
||||
}
|
||||
assertThatBool([loader wasSuccessful], is(equalToBool(YES)));
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,96 +0,0 @@
|
||||
//
|
||||
// RKOAuthClientTest.m
|
||||
// RestKit
|
||||
//
|
||||
// Created by Rodrigo Garcia on 8/4/11.
|
||||
// Copyright (c) 2009-2012 RestKit. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
#import "RKTestEnvironment.h"
|
||||
#import "RKPortCheck.h"
|
||||
|
||||
#define RKOAuthClientTestSkipWithoutMongoDB() \
|
||||
if (! [self isMongoRunning]) { \
|
||||
NSLog(@"!! Skipping OAuth Test: MongoDB not running"); \
|
||||
return; \
|
||||
}
|
||||
|
||||
@interface RKOAuthClientTest : RKTestCase
|
||||
|
||||
@end
|
||||
|
||||
@implementation RKOAuthClientTest
|
||||
|
||||
- (BOOL)isMongoRunning
|
||||
{
|
||||
static RKPortCheck *portCheck = nil;
|
||||
if (! portCheck) {
|
||||
portCheck = [[RKPortCheck alloc] initWithHost:@"localhost" port:27017];
|
||||
[portCheck run];
|
||||
}
|
||||
|
||||
return [portCheck isOpen];
|
||||
}
|
||||
|
||||
- (void)testShouldGetAccessToken
|
||||
{
|
||||
RKOAuthClientTestSkipWithoutMongoDB();
|
||||
|
||||
RKTestResponseLoader *loader = [RKTestResponseLoader responseLoader];
|
||||
RKOAuthClient *client = RKTestNewOAuthClient(loader);
|
||||
client.authorizationCode = @"4fa8182d7184797dd5000002";
|
||||
client.callbackURL = @"http://someURL.com";
|
||||
[client validateAuthorizationCode];
|
||||
[loader waitForResponse];
|
||||
assertThatBool(loader.wasSuccessful, is(equalToBool(YES)));
|
||||
}
|
||||
|
||||
- (void)testShouldNotGetAccessToken
|
||||
{
|
||||
RKOAuthClientTestSkipWithoutMongoDB();
|
||||
|
||||
RKTestResponseLoader *loader = [RKTestResponseLoader responseLoader];
|
||||
RKOAuthClient *client = RKTestNewOAuthClient(loader);
|
||||
client.authorizationCode = @"someInvalidAuthorizationCode";
|
||||
client.callbackURL = @"http://someURL.com";
|
||||
[client validateAuthorizationCode];
|
||||
[loader waitForResponse];
|
||||
|
||||
assertThatBool(loader.wasSuccessful, is(equalToBool(NO)));
|
||||
}
|
||||
|
||||
- (void)testShouldGetProtectedResource
|
||||
{
|
||||
RKOAuthClientTestSkipWithoutMongoDB();
|
||||
|
||||
//TODO: Encapsulate this code in a correct manner
|
||||
RKTestResponseLoader *loader = [RKTestResponseLoader responseLoader];
|
||||
RKOAuthClient *client = RKTestNewOAuthClient(loader);
|
||||
client.authorizationCode = @"4fa8182d7184797dd5000002";
|
||||
client.callbackURL = @"http://someURL.com";
|
||||
[client validateAuthorizationCode];
|
||||
|
||||
RKTestResponseLoader *resourceLoader = [RKTestResponseLoader responseLoader];
|
||||
RKClient *requestClient = [RKClient clientWithBaseURLString:[client authorizationURL]];
|
||||
requestClient.OAuth2AccessToken = client.accessToken;
|
||||
requestClient.authenticationType = RKRequestAuthenticationTypeOAuth2;
|
||||
RKRequest *request = [requestClient requestWithResourcePath:@"/oauth2/pregen/me"];
|
||||
request.delegate = resourceLoader;
|
||||
[request send];
|
||||
[resourceLoader waitForResponse];
|
||||
assertThatBool(loader.wasSuccessful, is(equalToBool(YES)));
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,63 +0,0 @@
|
||||
//
|
||||
// RKParamsAttachmentTest.m
|
||||
// RestKit
|
||||
//
|
||||
// Created by Blake Watters on 10/27/10.
|
||||
// Copyright (c) 2009-2012 RestKit. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
#import "RKTestEnvironment.h"
|
||||
#import "RKParamsAttachment.h"
|
||||
|
||||
@interface RKParamsAttachmentTest : RKTestCase {
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation RKParamsAttachmentTest
|
||||
|
||||
- (void)testShouldRaiseAnExceptionWhenTheAttachedFileDoesNotExist
|
||||
{
|
||||
NSException *exception = nil;
|
||||
@try {
|
||||
[[RKParamsAttachment alloc] initWithName:@"woot" file:@"/this/is/an/invalid/path"];
|
||||
}
|
||||
@catch (NSException *e) {
|
||||
exception = e;
|
||||
}
|
||||
assertThat(exception, isNot(nilValue()));
|
||||
}
|
||||
|
||||
- (void)testShouldReturnAnMD5ForSimpleValues
|
||||
{
|
||||
RKParamsAttachment *attachment = [[[RKParamsAttachment alloc] initWithName:@"foo" value:@"bar"] autorelease];
|
||||
assertThat([attachment MD5], is(equalTo(@"37b51d194a7513e45b56f6524f2d51f2")));
|
||||
}
|
||||
|
||||
- (void)testShouldReturnAnMD5ForNSData
|
||||
{
|
||||
RKParamsAttachment *attachment = [[[RKParamsAttachment alloc] initWithName:@"foo" data:[@"bar" dataUsingEncoding:NSUTF8StringEncoding]] autorelease];
|
||||
assertThat([attachment MD5], is(equalTo(@"37b51d194a7513e45b56f6524f2d51f2")));
|
||||
}
|
||||
|
||||
- (void)testShouldReturnAnMD5ForFiles
|
||||
{
|
||||
NSString *filePath = [RKTestFixture pathForFixture:@"blake.png"];
|
||||
RKParamsAttachment *attachment = [[[RKParamsAttachment alloc] initWithName:@"foo" file:filePath] autorelease];
|
||||
assertThat([attachment MD5], is(equalTo(@"db6cb9d879b58e7e15a595632af345cd")));
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,122 +0,0 @@
|
||||
//
|
||||
// RKParamsTest.m
|
||||
// RestKit
|
||||
//
|
||||
// Created by Blake Watters on 6/30/11.
|
||||
// Copyright (c) 2009-2012 RestKit. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
#import "RKTestEnvironment.h"
|
||||
#import "RKParams.h"
|
||||
#import "RKRequest.h"
|
||||
|
||||
@interface RKParamsTest : RKTestCase
|
||||
|
||||
@end
|
||||
|
||||
@implementation RKParamsTest
|
||||
|
||||
- (void)testShouldNotOverReleaseTheParams
|
||||
{
|
||||
NSDictionary *dictionary = [NSDictionary dictionaryWithObject:@"foo" forKey:@"bar"];
|
||||
RKParams *params = [[RKParams alloc] initWithDictionary:dictionary];
|
||||
NSURL *URL = [NSURL URLWithString:[[RKTestFactory baseURLString] stringByAppendingFormat:@"/echo_params"]];
|
||||
RKTestResponseLoader *responseLoader = [RKTestResponseLoader responseLoader];
|
||||
RKRequest *request = [[RKRequest alloc] initWithURL:URL];
|
||||
request.method = RKRequestMethodPOST;
|
||||
request.params = params;
|
||||
request.delegate = responseLoader;
|
||||
[request sendAsynchronously];
|
||||
[responseLoader waitForResponse];
|
||||
[request release];
|
||||
}
|
||||
|
||||
- (void)testShouldUploadFilesViaRKParams
|
||||
{
|
||||
RKClient *client = [RKTestFactory client];
|
||||
RKParams *params = [RKParams params];
|
||||
[params setValue:@"one" forParam:@"value"];
|
||||
[params setValue:@"two" forParam:@"value"];
|
||||
[params setValue:@"three" forParam:@"value"];
|
||||
[params setValue:@"four" forParam:@"value"];
|
||||
NSData *data = [RKTestFixture dataWithContentsOfFixture:@"blake.png"];
|
||||
[params setData:data MIMEType:@"image/png" forParam:@"file"];
|
||||
RKTestResponseLoader *responseLoader = [RKTestResponseLoader responseLoader];
|
||||
[client post:@"/upload" params:params delegate:responseLoader];
|
||||
[responseLoader waitForResponse];
|
||||
assertThatInteger(responseLoader.response.statusCode, is(equalToInt(200)));
|
||||
}
|
||||
|
||||
- (void)testShouldUploadFilesViaRKParamsWithMixedTypes
|
||||
{
|
||||
NSNumber *idUsuari = [NSNumber numberWithInt:1234];
|
||||
NSArray *userList = [NSArray arrayWithObjects:@"one", @"two", @"three", nil];
|
||||
NSNumber *idTema = [NSNumber numberWithInt:1234];
|
||||
NSString *titulo = @"whatever";
|
||||
NSString *texto = @"more text";
|
||||
NSData *data = [RKTestFixture dataWithContentsOfFixture:@"blake.png"];
|
||||
NSNumber *cel = [NSNumber numberWithFloat:1.232442];
|
||||
NSNumber *lon = [NSNumber numberWithFloat:18231.232442];;
|
||||
NSNumber *lat = [NSNumber numberWithFloat:13213123.232442];;
|
||||
|
||||
RKParams *params = [RKParams params];
|
||||
|
||||
// Set values
|
||||
[params setValue:idUsuari forParam:@"idUsuariPropietari"];
|
||||
[params setValue:userList forParam:@"telUser"];
|
||||
[params setValue:idTema forParam:@"idTema"];
|
||||
[params setValue:titulo forParam:@"titulo"];
|
||||
[params setValue:texto forParam:@"texto"];
|
||||
|
||||
[params setData:data MIMEType:@"image/png" forParam:@"file"];
|
||||
|
||||
[params setValue:cel forParam:@"cel"];
|
||||
[params setValue:lon forParam:@"lon"];
|
||||
[params setValue:lat forParam:@"lat"];
|
||||
|
||||
RKClient *client = [RKTestFactory client];
|
||||
RKTestResponseLoader *responseLoader = [RKTestResponseLoader responseLoader];
|
||||
[client post:@"/upload" params:params delegate:responseLoader];
|
||||
[responseLoader waitForResponse];
|
||||
assertThatInteger(responseLoader.response.statusCode, is(equalToInt(200)));
|
||||
}
|
||||
|
||||
- (void)testShouldCalculateAnMD5ForTheParams
|
||||
{
|
||||
NSDictionary *values = [NSDictionary dictionaryWithObjectsAndKeys:@"foo", @"bar", @"this", @"that", nil];
|
||||
RKParams *params = [RKParams paramsWithDictionary:values];
|
||||
NSString *MD5 = [params MD5];
|
||||
assertThat(MD5, is(equalTo(@"da7d80084b86aa5022b434e3bf084caf")));
|
||||
}
|
||||
|
||||
- (void)testShouldProperlyCalculateContentLengthForFileUploads
|
||||
{
|
||||
RKClient *client = [RKTestFactory client];
|
||||
RKParams *params = [RKParams params];
|
||||
[params setValue:@"one" forParam:@"value"];
|
||||
[params setValue:@"two" forParam:@"value"];
|
||||
[params setValue:@"three" forParam:@"value"];
|
||||
[params setValue:@"four" forParam:@"value"];
|
||||
NSData *data = [RKTestFixture dataWithContentsOfFixture:@"blake.png"];
|
||||
[params setData:data MIMEType:@"image/png" forParam:@"file"];
|
||||
RKRequest *request = [client requestWithResourcePath:@"/upload"];
|
||||
[request setMethod:RKRequestMethodPOST];
|
||||
request.params = params;
|
||||
[request prepareURLRequest];
|
||||
assertThatInteger([params HTTPHeaderValueForContentLength], is(equalToInt(23166)));
|
||||
assertThat([[request.URLRequest allHTTPHeaderFields] objectForKey:@"Content-Length"], is(equalTo(@"23166")));
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,301 +0,0 @@
|
||||
//
|
||||
// RKRequestQueueTest.m
|
||||
// RestKit
|
||||
//
|
||||
// Created by Blake Watters on 3/28/11.
|
||||
// Copyright (c) 2009-2012 RestKit. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
#import "RKTestEnvironment.h"
|
||||
|
||||
// Expose the request queue's [add|remove]LoadingRequest methods testing purposes...
|
||||
@interface RKRequestQueue ()
|
||||
- (void)addLoadingRequest:(RKRequest *)request;
|
||||
- (void)removeLoadingRequest:(RKRequest *)request;
|
||||
@end
|
||||
|
||||
@interface RKRequestQueueTest : RKTestCase {
|
||||
NSAutoreleasePool *_autoreleasePool;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation RKRequestQueueTest
|
||||
|
||||
- (void)setUp
|
||||
{
|
||||
_autoreleasePool = [NSAutoreleasePool new];
|
||||
}
|
||||
|
||||
- (void)tearDown
|
||||
{
|
||||
[_autoreleasePool drain];
|
||||
}
|
||||
|
||||
- (void)testShouldBeSuspendedWhenInitialized
|
||||
{
|
||||
RKRequestQueue *queue = [RKRequestQueue new];
|
||||
assertThatBool(queue.suspended, is(equalToBool(YES)));
|
||||
[queue release];
|
||||
}
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
|
||||
// TODO: Crashing...
|
||||
- (void)testShouldSuspendTheQueueOnTransitionToTheBackground
|
||||
{
|
||||
return;
|
||||
RKRequestQueue *queue = [RKRequestQueue new];
|
||||
assertThatBool(queue.suspended, is(equalToBool(YES)));
|
||||
queue.suspended = NO;
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:UIApplicationDidEnterBackgroundNotification object:nil];
|
||||
assertThatBool(queue.suspended, is(equalToBool(YES)));
|
||||
[queue release];
|
||||
}
|
||||
|
||||
- (void)testShouldUnsuspendTheQueueOnTransitionToTheForeground
|
||||
{
|
||||
// TODO: Crashing...
|
||||
return;
|
||||
RKRequestQueue *queue = [RKRequestQueue new];
|
||||
assertThatBool(queue.suspended, is(equalToBool(YES)));
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:UIApplicationWillEnterForegroundNotification object:nil];
|
||||
assertThatBool(queue.suspended, is(equalToBool(NO)));
|
||||
[queue release];
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
- (void)testShouldInformTheDelegateWhenSuspended
|
||||
{
|
||||
RKRequestQueue *queue = [RKRequestQueue new];
|
||||
assertThatBool(queue.suspended, is(equalToBool(YES)));
|
||||
queue.suspended = NO;
|
||||
OCMockObject *delegateMock = [OCMockObject niceMockForProtocol:@protocol(RKRequestQueueDelegate)];
|
||||
[[delegateMock expect] requestQueueWasSuspended:queue];
|
||||
queue.delegate = (NSObject<RKRequestQueueDelegate> *)delegateMock;
|
||||
queue.suspended = YES;
|
||||
[delegateMock verify];
|
||||
[queue release];
|
||||
}
|
||||
|
||||
- (void)testShouldInformTheDelegateWhenUnsuspended
|
||||
{
|
||||
RKRequestQueue *queue = [RKRequestQueue new];
|
||||
assertThatBool(queue.suspended, is(equalToBool(YES)));
|
||||
OCMockObject *delegateMock = [OCMockObject niceMockForProtocol:@protocol(RKRequestQueueDelegate)];
|
||||
[[delegateMock expect] requestQueueWasUnsuspended:queue];
|
||||
queue.delegate = (NSObject<RKRequestQueueDelegate> *)delegateMock;
|
||||
queue.suspended = NO;
|
||||
[delegateMock verify];
|
||||
[queue release];
|
||||
}
|
||||
|
||||
- (void)testShouldInformTheDelegateOnTransitionFromEmptyToProcessing
|
||||
{
|
||||
RKRequestQueue *queue = [RKRequestQueue new];
|
||||
OCMockObject *delegateMock = [OCMockObject niceMockForProtocol:@protocol(RKRequestQueueDelegate)];
|
||||
[[delegateMock expect] requestQueueDidBeginLoading:queue];
|
||||
queue.delegate = (NSObject<RKRequestQueueDelegate> *)delegateMock;
|
||||
NSURL *URL = [RKTestFactory baseURL];
|
||||
RKRequest *request = [[RKRequest alloc] initWithURL:URL];
|
||||
[queue addLoadingRequest:request];
|
||||
[delegateMock verify];
|
||||
[queue release];
|
||||
}
|
||||
|
||||
- (void)testShouldInformTheDelegateOnTransitionFromProcessingToEmpty
|
||||
{
|
||||
RKRequestQueue *queue = [RKRequestQueue new];
|
||||
OCMockObject *delegateMock = [OCMockObject niceMockForProtocol:@protocol(RKRequestQueueDelegate)];
|
||||
[[delegateMock expect] requestQueueDidFinishLoading:queue];
|
||||
queue.delegate = (NSObject<RKRequestQueueDelegate> *)delegateMock;
|
||||
NSURL *URL = [RKTestFactory baseURL];
|
||||
RKRequest *request = [[RKRequest alloc] initWithURL:URL];
|
||||
[queue addLoadingRequest:request];
|
||||
[queue removeLoadingRequest:request];
|
||||
[delegateMock verify];
|
||||
[queue release];
|
||||
}
|
||||
|
||||
- (void)testShouldInformTheDelegateOnTransitionFromProcessingToEmptyForQueuesWithASingleRequest
|
||||
{
|
||||
OCMockObject *delegateMock = [OCMockObject niceMockForProtocol:@protocol(RKRequestQueueDelegate)];
|
||||
RKTestResponseLoader *loader = [RKTestResponseLoader responseLoader];
|
||||
|
||||
NSString *url = [NSString stringWithFormat:@"%@/ok-with-delay/0.3", [RKTestFactory baseURLString]];
|
||||
NSURL *URL = [NSURL URLWithString:url];
|
||||
RKRequest *request = [[RKRequest alloc] initWithURL:URL];
|
||||
request.delegate = loader;
|
||||
|
||||
RKRequestQueue *queue = [RKRequestQueue new];
|
||||
queue.delegate = (NSObject<RKRequestQueueDelegate> *)delegateMock;
|
||||
[[delegateMock expect] requestQueueDidFinishLoading:queue];
|
||||
[queue addRequest:request];
|
||||
[queue start];
|
||||
[loader waitForResponse];
|
||||
[delegateMock verify];
|
||||
[queue release];
|
||||
}
|
||||
|
||||
// TODO: These tests cannot pass in the unit testing environment... Need to migrate to an integration
|
||||
// testing area
|
||||
//- (void)testShouldBeginSpinningTheNetworkActivityIfAsked {
|
||||
// [[UIApplication sharedApplication] rk_resetNetworkActivity];
|
||||
// RKRequestQueue *queue = [RKRequestQueue new];
|
||||
// queue.showsNetworkActivityIndicatorWhenBusy = YES;
|
||||
// assertThatBool([UIApplication sharedApplication].networkActivityIndicatorVisible, is(equalToBool(NO)));
|
||||
// [queue setValue:[NSNumber numberWithInt:1] forKey:@"loadingCount"];
|
||||
// assertThatBool([UIApplication sharedApplication].networkActivityIndicatorVisible, is(equalToBool(YES)));
|
||||
// [queue release];
|
||||
//}
|
||||
//
|
||||
//- (void)testShouldStopSpinningTheNetworkActivityIfAsked {
|
||||
// [[UIApplication sharedApplication] rk_resetNetworkActivity];
|
||||
// RKRequestQueue *queue = [RKRequestQueue new];
|
||||
// queue.showsNetworkActivityIndicatorWhenBusy = YES;
|
||||
// [queue setValue:[NSNumber numberWithInt:1] forKey:@"loadingCount"];
|
||||
// assertThatBool([UIApplication sharedApplication].networkActivityIndicatorVisible, is(equalToBool(YES)));
|
||||
// [queue setValue:[NSNumber numberWithInt:0] forKey:@"loadingCount"];
|
||||
// assertThatBool([UIApplication sharedApplication].networkActivityIndicatorVisible, is(equalToBool(NO)));
|
||||
// [queue release];
|
||||
//}
|
||||
//
|
||||
//- (void)testShouldJointlyManageTheNetworkActivityIndicator {
|
||||
// [[UIApplication sharedApplication] rk_resetNetworkActivity];
|
||||
// RKTestResponseLoader *loader = [RKTestResponseLoader responseLoader];
|
||||
// loader.timeout = 10;
|
||||
//
|
||||
// RKRequestQueue *queue1 = [RKRequestQueue new];
|
||||
// queue1.showsNetworkActivityIndicatorWhenBusy = YES;
|
||||
// NSString *url1 = [NSString stringWithFormat:@"%@/ok-with-delay/2.0", [RKTestFactory baseURL]];
|
||||
// NSURL *URL1 = [NSURL URLWithString:url1];
|
||||
// RKRequest *request1 = [[RKRequest alloc] initWithURL:URL1];
|
||||
// request1.delegate = loader;
|
||||
//
|
||||
// RKRequestQueue *queue2 = [RKRequestQueue new];
|
||||
// queue2.showsNetworkActivityIndicatorWhenBusy = YES;
|
||||
// NSString *url2 = [NSString stringWithFormat:@"%@/ok-with-delay/2.0", [RKTestFactory baseURL]];
|
||||
// NSURL *URL2 = [NSURL URLWithString:url2];
|
||||
// RKRequest *request2 = [[RKRequest alloc] initWithURL:URL2];
|
||||
// request2.delegate = loader;
|
||||
//
|
||||
// assertThatBool([UIApplication sharedApplication].networkActivityIndicatorVisible, is(equalToBool(NO)));
|
||||
// [queue1 addRequest:request1];
|
||||
// [queue1 start];
|
||||
// assertThatBool([UIApplication sharedApplication].networkActivityIndicatorVisible, is(equalToBool(YES)));
|
||||
// [queue2 addRequest:request2];
|
||||
// [queue2 start];
|
||||
// assertThatBool([UIApplication sharedApplication].networkActivityIndicatorVisible, is(equalToBool(YES)));
|
||||
// [loader waitForResponse];
|
||||
// assertThatBool([UIApplication sharedApplication].networkActivityIndicatorVisible, is(equalToBool(YES)));
|
||||
// [loader waitForResponse];
|
||||
// assertThatBool([UIApplication sharedApplication].networkActivityIndicatorVisible, is(equalToBool(NO)));
|
||||
//}
|
||||
|
||||
- (void)testShouldLetYouReturnAQueueByName
|
||||
{
|
||||
RKRequestQueue *queue = [RKRequestQueue requestQueueWithName:@"Images"];
|
||||
assertThat(queue, isNot(nilValue()));
|
||||
assertThat(queue.name, is(equalTo(@"Images")));
|
||||
}
|
||||
|
||||
- (void)testShouldReturnAnExistingQueueByName
|
||||
{
|
||||
RKRequestQueue *queue = [RKRequestQueue requestQueueWithName:@"Images2"];
|
||||
assertThat(queue, isNot(nilValue()));
|
||||
RKRequestQueue *secondQueue = [RKRequestQueue requestQueueWithName:@"Images2"];
|
||||
assertThat(queue, is(equalTo(secondQueue)));
|
||||
}
|
||||
|
||||
- (void)testShouldReturnTheQueueWithoutAModifiedRetainCount
|
||||
{
|
||||
RKRequestQueue *queue = [RKRequestQueue requestQueueWithName:@"Images3"];
|
||||
assertThat(queue, isNot(nilValue()));
|
||||
assertThatUnsignedInteger([queue retainCount], is(equalToInt(1)));
|
||||
}
|
||||
|
||||
- (void)testShouldReturnYESWhenAQueueExistsWithAGivenName
|
||||
{
|
||||
assertThatBool([RKRequestQueue requestQueueExistsWithName:@"Images4"], is(equalToBool(NO)));
|
||||
[RKRequestQueue requestQueueWithName:@"Images4"];
|
||||
assertThatBool([RKRequestQueue requestQueueExistsWithName:@"Images4"], is(equalToBool(YES)));
|
||||
}
|
||||
|
||||
- (void)testShouldRemoveTheQueueFromTheNamedInstancesOnDealloc
|
||||
{
|
||||
// TODO: Crashing...
|
||||
return;
|
||||
RKRequestQueue *queue = [RKRequestQueue requestQueueWithName:@"Images5"];
|
||||
assertThat(queue, isNot(nilValue()));
|
||||
assertThatBool([RKRequestQueue requestQueueExistsWithName:@"Images5"], is(equalToBool(YES)));
|
||||
[queue release];
|
||||
assertThatBool([RKRequestQueue requestQueueExistsWithName:@"Images5"], is(equalToBool(NO)));
|
||||
}
|
||||
|
||||
- (void)testShouldReturnANewOwningReferenceViaNewRequestWithName
|
||||
{
|
||||
RKRequestQueue *requestQueue = [RKRequestQueue newRequestQueueWithName:@"Images6"];
|
||||
assertThat(requestQueue, isNot(nilValue()));
|
||||
assertThatUnsignedInteger([requestQueue retainCount], is(equalToInt(1)));
|
||||
}
|
||||
|
||||
- (void)testShouldReturnNilIfNewRequestQueueWithNameIsCalledForAnExistingName
|
||||
{
|
||||
RKRequestQueue *queue = [RKRequestQueue newRequestQueueWithName:@"Images7"];
|
||||
assertThat(queue, isNot(nilValue()));
|
||||
RKRequestQueue *queue2 = [RKRequestQueue newRequestQueueWithName:@"Images7"];
|
||||
assertThat(queue2, is(nilValue()));
|
||||
}
|
||||
|
||||
- (void)testShouldRemoveItemsFromTheQueueWithAnUnmappableResponse
|
||||
{
|
||||
RKRequestQueue *queue = [RKRequestQueue requestQueue];
|
||||
RKObjectManager *objectManager = [RKTestFactory objectManager];
|
||||
RKTestResponseLoader *loader = [RKTestResponseLoader responseLoader];
|
||||
RKObjectLoader *objectLoader = [objectManager loaderWithResourcePath:@"/403"];
|
||||
objectLoader.delegate = loader;
|
||||
[queue addRequest:(RKRequest *)objectLoader];
|
||||
[queue start];
|
||||
[loader waitForResponse];
|
||||
assertThatUnsignedInteger(queue.loadingCount, is(equalToInt(0)));
|
||||
}
|
||||
|
||||
- (void)testThatSendingRequestToInvalidURLDoesNotGetSentTwice
|
||||
{
|
||||
RKRequestQueue *queue = [RKRequestQueue requestQueue];
|
||||
NSURL *URL = [NSURL URLWithString:@"http://localhost:7662/RKRequestQueueExample"];
|
||||
RKRequest *request = [RKRequest requestWithURL:URL];
|
||||
RKTestResponseLoader *responseLoader = [RKTestResponseLoader responseLoader];
|
||||
id mockResponseLoader = [OCMockObject partialMockForObject:responseLoader];
|
||||
[[[mockResponseLoader expect] andForwardToRealObject] request:request didFailLoadWithError:OCMOCK_ANY];
|
||||
request.delegate = responseLoader;
|
||||
id mockQueueDelegate = [OCMockObject niceMockForProtocol:@protocol(RKRequestQueueDelegate)];
|
||||
__block NSUInteger invocationCount = 0;
|
||||
[[mockQueueDelegate stub] requestQueue:queue willSendRequest:[OCMArg checkWithBlock:^BOOL(id request) {
|
||||
invocationCount++;
|
||||
return YES;
|
||||
}]];
|
||||
[queue addRequest:request];
|
||||
queue.delegate = mockQueueDelegate;
|
||||
[queue start];
|
||||
[mockResponseLoader waitForResponse];
|
||||
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0]];
|
||||
[mockResponseLoader verify];
|
||||
assertThatInteger(invocationCount, is(equalToInteger(1)));
|
||||
}
|
||||
|
||||
@end
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,338 +0,0 @@
|
||||
//
|
||||
// RKResponseTest.m
|
||||
// RestKit
|
||||
//
|
||||
// Created by Blake Watters on 1/15/10.
|
||||
// Copyright (c) 2009-2012 RestKit. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
#import "RKTestEnvironment.h"
|
||||
#import "RKResponse.h"
|
||||
|
||||
@interface RKResponseTest : RKTestCase {
|
||||
RKResponse *_response;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation RKResponseTest
|
||||
|
||||
- (void)setUp
|
||||
{
|
||||
_response = [[RKResponse alloc] init];
|
||||
}
|
||||
|
||||
- (void)testShouldConsiderResponsesLessThanOneHudredOrGreaterThanSixHundredInvalid
|
||||
{
|
||||
RKResponse *response = [[[RKResponse alloc] init] autorelease];
|
||||
id mock = [OCMockObject partialMockForObject:response];
|
||||
NSInteger statusCode = 99;
|
||||
[[[mock stub] andReturnValue:OCMOCK_VALUE(statusCode)] statusCode];
|
||||
assertThatBool([mock isInvalid], is(equalToBool(YES)));
|
||||
statusCode = 601;
|
||||
[[[mock stub] andReturnValue:OCMOCK_VALUE(statusCode)] statusCode];
|
||||
assertThatBool([mock isInvalid], is(equalToBool(YES)));
|
||||
}
|
||||
|
||||
- (void)testShouldConsiderResponsesInTheOneHudredsInformational
|
||||
{
|
||||
RKResponse *response = [[[RKResponse alloc] init] autorelease];
|
||||
id mock = [OCMockObject partialMockForObject:response];
|
||||
NSInteger statusCode = 100;
|
||||
[[[mock stub] andReturnValue:OCMOCK_VALUE(statusCode)] statusCode];
|
||||
assertThatBool([mock isInformational], is(equalToBool(YES)));
|
||||
statusCode = 199;
|
||||
[[[mock stub] andReturnValue:OCMOCK_VALUE(statusCode)] statusCode];
|
||||
assertThatBool([mock isInformational], is(equalToBool(YES)));
|
||||
}
|
||||
|
||||
- (void)testShouldConsiderResponsesInTheTwoHundredsSuccessful
|
||||
{
|
||||
RKResponse *response = [[[RKResponse alloc] init] autorelease];
|
||||
id mock = [OCMockObject partialMockForObject:response];
|
||||
NSInteger twoHundred = 200;
|
||||
[[[mock stub] andReturnValue:OCMOCK_VALUE(twoHundred)] statusCode];
|
||||
assertThatBool([mock isSuccessful], is(equalToBool(YES)));
|
||||
twoHundred = 299;
|
||||
[[[mock stub] andReturnValue:OCMOCK_VALUE(twoHundred)] statusCode];
|
||||
assertThatBool([mock isSuccessful], is(equalToBool(YES)));
|
||||
}
|
||||
|
||||
- (void)testShouldConsiderResponsesInTheThreeHundredsRedirects
|
||||
{
|
||||
RKResponse *response = [[[RKResponse alloc] init] autorelease];
|
||||
id mock = [OCMockObject partialMockForObject:response];
|
||||
NSInteger statusCode = 300;
|
||||
[[[mock stub] andReturnValue:OCMOCK_VALUE(statusCode)] statusCode];
|
||||
assertThatBool([mock isRedirection], is(equalToBool(YES)));
|
||||
statusCode = 399;
|
||||
[[[mock stub] andReturnValue:OCMOCK_VALUE(statusCode)] statusCode];
|
||||
assertThatBool([mock isRedirection], is(equalToBool(YES)));
|
||||
}
|
||||
|
||||
- (void)testShouldConsiderResponsesInTheFourHundredsClientErrors
|
||||
{
|
||||
RKResponse *response = [[[RKResponse alloc] init] autorelease];
|
||||
id mock = [OCMockObject partialMockForObject:response];
|
||||
NSInteger statusCode = 400;
|
||||
[[[mock stub] andReturnValue:OCMOCK_VALUE(statusCode)] statusCode];
|
||||
assertThatBool([mock isClientError], is(equalToBool(YES)));
|
||||
statusCode = 499;
|
||||
[[[mock stub] andReturnValue:OCMOCK_VALUE(statusCode)] statusCode];
|
||||
assertThatBool([mock isClientError], is(equalToBool(YES)));
|
||||
}
|
||||
|
||||
- (void)testShouldConsiderResponsesInTheFiveHundredsServerErrors
|
||||
{
|
||||
RKResponse *response = [[[RKResponse alloc] init] autorelease];
|
||||
id mock = [OCMockObject partialMockForObject:response];
|
||||
NSInteger statusCode = 500;
|
||||
[[[mock stub] andReturnValue:OCMOCK_VALUE(statusCode)] statusCode];
|
||||
assertThatBool([mock isServerError], is(equalToBool(YES)));
|
||||
statusCode = 599;
|
||||
[[[mock stub] andReturnValue:OCMOCK_VALUE(statusCode)] statusCode];
|
||||
assertThatBool([mock isServerError], is(equalToBool(YES)));
|
||||
}
|
||||
|
||||
- (void)testShouldConsiderATwoHundredResponseOK
|
||||
{
|
||||
RKResponse *response = [[[RKResponse alloc] init] autorelease];
|
||||
id mock = [OCMockObject partialMockForObject:response];
|
||||
NSInteger statusCode = 200;
|
||||
[[[mock stub] andReturnValue:OCMOCK_VALUE(statusCode)] statusCode];
|
||||
assertThatBool([mock isOK], is(equalToBool(YES)));
|
||||
}
|
||||
|
||||
- (void)testShouldConsiderATwoHundredAndOneResponseCreated
|
||||
{
|
||||
RKResponse *response = [[[RKResponse alloc] init] autorelease];
|
||||
id mock = [OCMockObject partialMockForObject:response];
|
||||
NSInteger statusCode = 201;
|
||||
[[[mock stub] andReturnValue:OCMOCK_VALUE(statusCode)] statusCode];
|
||||
assertThatBool([mock isCreated], is(equalToBool(YES)));
|
||||
}
|
||||
|
||||
- (void)testShouldConsiderAFourOhThreeResponseForbidden
|
||||
{
|
||||
RKResponse *response = [[[RKResponse alloc] init] autorelease];
|
||||
id mock = [OCMockObject partialMockForObject:response];
|
||||
NSInteger statusCode = 403;
|
||||
[[[mock stub] andReturnValue:OCMOCK_VALUE(statusCode)] statusCode];
|
||||
assertThatBool([mock isForbidden], is(equalToBool(YES)));
|
||||
}
|
||||
|
||||
- (void)testShouldConsiderAFourOhFourResponseNotFound
|
||||
{
|
||||
RKResponse *response = [[[RKResponse alloc] init] autorelease];
|
||||
id mock = [OCMockObject partialMockForObject:response];
|
||||
NSInteger statusCode = 404;
|
||||
[[[mock stub] andReturnValue:OCMOCK_VALUE(statusCode)] statusCode];
|
||||
assertThatBool([mock isNotFound], is(equalToBool(YES)));
|
||||
}
|
||||
|
||||
- (void)testShouldConsiderAFourOhNineResponseConflict
|
||||
{
|
||||
RKResponse *response = [[[RKResponse alloc] init] autorelease];
|
||||
id mock = [OCMockObject partialMockForObject:response];
|
||||
NSInteger statusCode = 409;
|
||||
[[[mock stub] andReturnValue:OCMOCK_VALUE(statusCode)] statusCode];
|
||||
assertThatBool([mock isConflict], is(equalToBool(YES)));
|
||||
}
|
||||
|
||||
- (void)testShouldConsiderAFourHundredAndTenResponseConflict
|
||||
{
|
||||
RKResponse *response = [[[RKResponse alloc] init] autorelease];
|
||||
id mock = [OCMockObject partialMockForObject:response];
|
||||
NSInteger statusCode = 410;
|
||||
[[[mock stub] andReturnValue:OCMOCK_VALUE(statusCode)] statusCode];
|
||||
assertThatBool([mock isGone], is(equalToBool(YES)));
|
||||
}
|
||||
|
||||
- (void)testShouldConsiderVariousThreeHundredResponsesRedirect
|
||||
{
|
||||
RKResponse *response = [[[RKResponse alloc] init] autorelease];
|
||||
id mock = [OCMockObject partialMockForObject:response];
|
||||
NSInteger statusCode = 301;
|
||||
[[[mock stub] andReturnValue:OCMOCK_VALUE(statusCode)] statusCode];
|
||||
assertThatBool([mock isRedirect], is(equalToBool(YES)));
|
||||
statusCode = 302;
|
||||
[[[mock stub] andReturnValue:OCMOCK_VALUE(statusCode)] statusCode];
|
||||
assertThatBool([mock isRedirect], is(equalToBool(YES)));
|
||||
statusCode = 303;
|
||||
[[[mock stub] andReturnValue:OCMOCK_VALUE(statusCode)] statusCode];
|
||||
assertThatBool([mock isRedirect], is(equalToBool(YES)));
|
||||
statusCode = 307;
|
||||
[[[mock stub] andReturnValue:OCMOCK_VALUE(statusCode)] statusCode];
|
||||
assertThatBool([mock isRedirect], is(equalToBool(YES)));
|
||||
}
|
||||
|
||||
- (void)testShouldConsiderVariousResponsesEmpty
|
||||
{
|
||||
RKResponse *response = [[[RKResponse alloc] init] autorelease];
|
||||
id mock = [OCMockObject partialMockForObject:response];
|
||||
NSInteger statusCode = 201;
|
||||
[[[mock stub] andReturnValue:OCMOCK_VALUE(statusCode)] statusCode];
|
||||
assertThatBool([mock isEmpty], is(equalToBool(YES)));
|
||||
statusCode = 204;
|
||||
[[[mock stub] andReturnValue:OCMOCK_VALUE(statusCode)] statusCode];
|
||||
assertThatBool([mock isEmpty], is(equalToBool(YES)));
|
||||
statusCode = 304;
|
||||
[[[mock stub] andReturnValue:OCMOCK_VALUE(statusCode)] statusCode];
|
||||
assertThatBool([mock isEmpty], is(equalToBool(YES)));
|
||||
}
|
||||
|
||||
- (void)testShouldMakeTheContentTypeHeaderAccessible
|
||||
{
|
||||
RKResponse *response = [[[RKResponse alloc] init] autorelease];
|
||||
id mock = [OCMockObject partialMockForObject:response];
|
||||
NSDictionary *headers = [NSDictionary dictionaryWithObject:@"application/xml" forKey:@"Content-Type"];
|
||||
[[[mock stub] andReturn:headers] allHeaderFields];
|
||||
assertThat([mock contentType], is(equalTo(@"application/xml")));
|
||||
}
|
||||
|
||||
// Should this return a string???
|
||||
- (void)testShouldMakeTheContentLengthHeaderAccessible
|
||||
{
|
||||
RKResponse *response = [[[RKResponse alloc] init] autorelease];
|
||||
id mock = [OCMockObject partialMockForObject:response];
|
||||
NSDictionary *headers = [NSDictionary dictionaryWithObject:@"12345" forKey:@"Content-Length"];
|
||||
[[[mock stub] andReturn:headers] allHeaderFields];
|
||||
assertThat([mock contentLength], is(equalTo(@"12345")));
|
||||
}
|
||||
|
||||
- (void)testShouldMakeTheLocationHeaderAccessible
|
||||
{
|
||||
RKResponse *response = [[[RKResponse alloc] init] autorelease];
|
||||
id mock = [OCMockObject partialMockForObject:response];
|
||||
NSDictionary *headers = [NSDictionary dictionaryWithObject:@"/foo/bar" forKey:@"Location"];
|
||||
[[[mock stub] andReturn:headers] allHeaderFields];
|
||||
assertThat([mock location], is(equalTo(@"/foo/bar")));
|
||||
}
|
||||
|
||||
- (void)testShouldKnowIfItIsAnXMLResponse
|
||||
{
|
||||
RKResponse *response = [[[RKResponse alloc] init] autorelease];
|
||||
id mock = [OCMockObject partialMockForObject:response];
|
||||
NSDictionary *headers = [NSDictionary dictionaryWithObject:@"application/xml" forKey:@"Content-Type"];
|
||||
[[[mock stub] andReturn:headers] allHeaderFields];
|
||||
assertThatBool([mock isXML], is(equalToBool(YES)));
|
||||
}
|
||||
|
||||
- (void)testShouldKnowIfItIsAnJSONResponse
|
||||
{
|
||||
RKResponse *response = [[[RKResponse alloc] init] autorelease];
|
||||
id mock = [OCMockObject partialMockForObject:response];
|
||||
NSDictionary *headers = [NSDictionary dictionaryWithObject:@"application/json" forKey:@"Content-Type"];
|
||||
[[[mock stub] andReturn:headers] allHeaderFields];
|
||||
assertThatBool([mock isJSON], is(equalToBool(YES)));
|
||||
}
|
||||
|
||||
- (void)testShouldReturnParseErrorsWhenParsedBodyFails
|
||||
{
|
||||
RKResponse *response = [[[RKResponse alloc] init] autorelease];
|
||||
id mock = [OCMockObject partialMockForObject:response];
|
||||
[[[mock stub] andReturn:@"sad;sdvjnk;"] bodyAsString];
|
||||
[[[mock stub] andReturn:@"application/json"] MIMEType];
|
||||
NSError *error = nil;
|
||||
id object = [mock parsedBody:&error];
|
||||
assertThat(object, is(nilValue()));
|
||||
assertThat(error, isNot(nilValue()));
|
||||
assertThat([error localizedDescription], is(equalTo(@"Unexpected token, wanted '{', '}', '[', ']', ',', ':', 'true', 'false', 'null', '\"STRING\"', 'NUMBER'.")));
|
||||
}
|
||||
|
||||
- (void)testShouldNotCrashOnFailureToParseBody
|
||||
{
|
||||
RKResponse *response = [[RKResponse new] autorelease];
|
||||
id mockResponse = [OCMockObject partialMockForObject:response];
|
||||
[[[mockResponse stub] andReturn:@"test/fake"] MIMEType];
|
||||
[[[mockResponse stub] andReturn:@"whatever"] bodyAsString];
|
||||
NSError *error = nil;
|
||||
id parsedResponse = [mockResponse parsedBody:&error];
|
||||
assertThat(parsedResponse, is(nilValue()));
|
||||
}
|
||||
|
||||
- (void)testShouldNotCrashWhenParserReturnsNilWithoutAnError
|
||||
{
|
||||
RKResponse *response = [[[RKResponse alloc] init] autorelease];
|
||||
id mockResponse = [OCMockObject partialMockForObject:response];
|
||||
[[[mockResponse stub] andReturn:@""] bodyAsString];
|
||||
[[[mockResponse stub] andReturn:RKMIMETypeJSON] MIMEType];
|
||||
id mockParser = [OCMockObject mockForProtocol:@protocol(RKParser)];
|
||||
id mockRegistry = [OCMockObject partialMockForObject:[RKParserRegistry sharedRegistry]];
|
||||
[[[mockRegistry expect] andReturn:mockParser] parserForMIMEType:RKMIMETypeJSON];
|
||||
NSError *error = nil;
|
||||
[[[mockParser expect] andReturn:nil] objectFromString:@"" error:[OCMArg setTo:error]];
|
||||
id object = [mockResponse parsedBody:&error];
|
||||
[mockRegistry verify];
|
||||
[mockParser verify];
|
||||
[RKParserRegistry setSharedRegistry:nil];
|
||||
assertThat(object, is(nilValue()));
|
||||
assertThat(error, is(nilValue()));
|
||||
}
|
||||
|
||||
- (void)testLoadingNonUTF8Charset
|
||||
{
|
||||
RKClient *client = [RKTestFactory client];
|
||||
RKTestResponseLoader *loader = [RKTestResponseLoader responseLoader];
|
||||
[client get:@"/encoding" delegate:loader];
|
||||
[loader waitForResponse];
|
||||
assertThat([loader.response bodyEncodingName], is(equalTo(@"us-ascii")));
|
||||
assertThatInteger([loader.response bodyEncoding], is(equalToInteger(NSASCIIStringEncoding)));
|
||||
}
|
||||
|
||||
- (void)testFollowRedirect
|
||||
{
|
||||
RKClient *client = [RKTestFactory client];
|
||||
RKTestResponseLoader *loader = [RKTestResponseLoader responseLoader];
|
||||
[client get:@"/redirection" delegate:loader];
|
||||
[loader waitForResponse];
|
||||
assertThatInteger(loader.response.statusCode, is(equalToInteger(200)));
|
||||
|
||||
id body = [loader.response parsedBody:NULL];
|
||||
assertThat([body objectForKey:@"redirected"], is(equalTo([NSNumber numberWithBool:YES])));
|
||||
}
|
||||
|
||||
- (void)testNoFollowRedirect
|
||||
{
|
||||
RKClient *client = [RKTestFactory client];
|
||||
RKTestResponseLoader *loader = [RKTestResponseLoader responseLoader];
|
||||
|
||||
RKRequest *request = [client requestWithResourcePath:@"/redirection"];
|
||||
request.method = RKRequestMethodGET;
|
||||
request.followRedirect = NO;
|
||||
request.delegate = loader;
|
||||
|
||||
[request send];
|
||||
[loader waitForResponse];
|
||||
|
||||
assertThatInteger(loader.response.statusCode, is(equalToInteger(302)));
|
||||
assertThat([loader.response.allHeaderFields objectForKey:@"Location"], is(equalTo(@"/redirection/target")));
|
||||
}
|
||||
|
||||
- (void)testThatLoadingInvalidURLDoesNotCrashApp
|
||||
{
|
||||
NSURL *URL = [[NSURL alloc] initWithString:@"http://localhost:5629"];
|
||||
RKTestResponseLoader *loader = [RKTestResponseLoader responseLoader];
|
||||
RKClient *client = [RKClient clientWithBaseURL:URL];
|
||||
|
||||
RKRequest *request = [client requestWithResourcePath:@"/invalid"];
|
||||
request.method = RKRequestMethodGET;
|
||||
request.delegate = loader;
|
||||
|
||||
[request sendAsynchronously];
|
||||
[loader waitForResponse];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,258 +0,0 @@
|
||||
//
|
||||
// RKURLTest.m
|
||||
// RestKit
|
||||
//
|
||||
// Created by Blake Watters on 6/29/11.
|
||||
// Copyright (c) 2009-2012 RestKit. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
#import "RKTestEnvironment.h"
|
||||
#import "RKURL.h"
|
||||
#import "NSURL+RKAdditions.h"
|
||||
|
||||
@interface RKURLTest : RKTestCase
|
||||
@end
|
||||
|
||||
@implementation RKURLTest
|
||||
|
||||
- (void)testShouldNotExplodeBecauseOfUnicodeCharacters
|
||||
{
|
||||
NSException *failed = nil;
|
||||
@try {
|
||||
[RKURL URLWithBaseURLString:@"http://test.com" resourcePath:@"/places.json?category=Automóviles"];
|
||||
}
|
||||
@catch (NSException *exception) {
|
||||
failed = exception;
|
||||
}
|
||||
@finally {
|
||||
NSAssert((failed == nil), @"No exception should be generated by creating URL with Unicode chars");
|
||||
}
|
||||
}
|
||||
|
||||
- (void)testShouldEscapeQueryParameters
|
||||
{
|
||||
NSDictionary *queryParams = [NSDictionary dictionaryWithObjectsAndKeys:@"What is your #1 e-mail?", @"question", @"john+restkit@gmail.com", @"answer", nil];
|
||||
RKURL *URL = [RKURL URLWithBaseURLString:@"http://restkit.org" resourcePath:@"/test" queryParameters:queryParams];
|
||||
assertThat([URL absoluteString], is(equalTo(@"http://restkit.org/test?answer=john%2Brestkit%40gmail.com&question=What%20is%20your%20%231%20e-mail%3F")));
|
||||
}
|
||||
|
||||
- (void)testShouldHandleNilQueryParameters
|
||||
{
|
||||
RKURL *URL = [RKURL URLWithBaseURLString:@"http://restkit.org" resourcePath:@"/test" queryParameters:nil];
|
||||
assertThat([URL absoluteString], is(equalTo(@"http://restkit.org/test")));
|
||||
}
|
||||
|
||||
- (void)testShouldHandleEmptyQueryParameters
|
||||
{
|
||||
RKURL *URL = [RKURL URLWithBaseURLString:@"http://restkit.org" resourcePath:@"/test" queryParameters:[NSDictionary dictionary]];
|
||||
assertThat([URL absoluteString], is(equalTo(@"http://restkit.org/test")));
|
||||
}
|
||||
|
||||
- (void)testShouldHandleResourcePathWithoutLeadingSlash
|
||||
{
|
||||
RKURL *URL = [RKURL URLWithBaseURLString:@"http://restkit.org" resourcePath:@"test" queryParameters:nil];
|
||||
assertThat([URL absoluteString], is(equalTo(@"http://restkit.org/test")));
|
||||
}
|
||||
|
||||
- (void)testShouldHandleEmptyResourcePath
|
||||
{
|
||||
RKURL *URL = [RKURL URLWithBaseURLString:@"http://restkit.org" resourcePath:@"" queryParameters:nil];
|
||||
assertThat([URL absoluteString], is(equalTo(@"http://restkit.org")));
|
||||
}
|
||||
|
||||
- (void)testShouldHandleBaseURLsWithAPath
|
||||
{
|
||||
RKURL *URL = [RKURL URLWithBaseURLString:@"http://restkit.org/this" resourcePath:@"/test" queryParameters:nil];
|
||||
assertThat([URL absoluteString], is(equalTo(@"http://restkit.org/this/test")));
|
||||
}
|
||||
|
||||
- (void)testShouldSimplifyURLsWithSeveralSlashes
|
||||
{
|
||||
RKURL *URL = [RKURL URLWithBaseURLString:@"http://restkit.org//this//" resourcePath:@"/test" queryParameters:nil];
|
||||
assertThat([URL absoluteString], is(equalTo(@"http://restkit.org/this/test")));
|
||||
}
|
||||
|
||||
- (void)testShouldPreserveTrailingSlash
|
||||
{
|
||||
RKURL *URL = [RKURL URLWithBaseURLString:@"http://restkit.org" resourcePath:@"/test/" queryParameters:nil];
|
||||
assertThat([URL absoluteString], is(equalTo(@"http://restkit.org/test/")));
|
||||
}
|
||||
|
||||
- (void)testShouldReturnTheMIMETypeForURL
|
||||
{
|
||||
NSURL *URL = [NSURL URLWithString:@"http://restkit.org/path/to/resource.xml"];
|
||||
assertThat([URL MIMETypeForPathExtension], is(equalTo(@"application/xml")));
|
||||
}
|
||||
|
||||
- (void)testInitializationFromStringIsEqualToAbsoluteString
|
||||
{
|
||||
RKURL *URL = [RKURL URLWithString:@"http://restkit.org"];
|
||||
assertThat([URL absoluteString], is(equalTo(@"http://restkit.org")));
|
||||
}
|
||||
|
||||
- (void)testInitializationFromStringHasSelfAsBaseURL
|
||||
{
|
||||
RKURL *URL = [RKURL URLWithString:@"http://restkit.org"];
|
||||
assertThat([[URL baseURL] absoluteString], is(equalTo(@"http://restkit.org")));
|
||||
}
|
||||
|
||||
- (void)testInitializationFromStringHasNilResourcePath
|
||||
{
|
||||
RKURL *URL = [RKURL URLWithString:@"http://restkit.org"];
|
||||
assertThat([URL resourcePath], is(nilValue()));
|
||||
}
|
||||
|
||||
- (void)testInitializationFromStringHasNilQueryParameters
|
||||
{
|
||||
RKURL *URL = [RKURL URLWithString:@"http://restkit.org"];
|
||||
assertThat([URL query], is(nilValue()));
|
||||
assertThat([URL queryParameters], is(nilValue()));
|
||||
}
|
||||
|
||||
- (void)testInitializationFromStringIncludingQueryParameters
|
||||
{
|
||||
RKURL *URL = [RKURL URLWithString:@"http://restkit.org/foo?bar=1&this=that"];
|
||||
assertThat([URL queryParameters], hasEntries(@"bar", equalTo(@"1"), @"this", equalTo(@"that"), nil));
|
||||
}
|
||||
|
||||
- (void)testInitializationFromURLandResourcePathIncludingQueryParameters
|
||||
{
|
||||
NSString *resourcePath = @"/bar?another=option";
|
||||
RKURL *URL = [RKURL URLWithBaseURLString:@"http://restkit.org/foo?bar=1&this=that" resourcePath:resourcePath];
|
||||
#if TARGET_OS_IPHONE
|
||||
assertThat([URL absoluteString], is(equalTo(@"http://restkit.org/foo/bar?bar=1&this=that&another=option")));
|
||||
#else
|
||||
assertThat([URL absoluteString], is(equalTo(@"http://restkit.org/foo/bar?bar=1&another=option&this=that")));
|
||||
#endif
|
||||
assertThat([URL queryParameters], hasEntries(@"bar", equalTo(@"1"),
|
||||
@"this", equalTo(@"that"),
|
||||
@"another", equalTo(@"option"), nil));
|
||||
}
|
||||
|
||||
- (void)testInitializationFromNSURL
|
||||
{
|
||||
NSURL *URL = [NSURL URLWithString:@"http://restkit.org"];
|
||||
RKURL *rkURL = [RKURL URLWithBaseURL:URL];
|
||||
assertThat(URL, is(equalTo(rkURL)));
|
||||
}
|
||||
|
||||
- (void)testInitializationFromRKURL
|
||||
{
|
||||
RKURL *URL = [RKURL URLWithString:@"http://restkit.org"];
|
||||
RKURL *rkURL = [RKURL URLWithBaseURL:URL];
|
||||
assertThat(URL, is(equalTo(rkURL)));
|
||||
}
|
||||
|
||||
- (void)testInitializationFromNSURLandAppendingOfResourcePath
|
||||
{
|
||||
RKURL *URL = [RKURL URLWithString:@"http://restkit.org/"];
|
||||
RKURL *rkURL = [RKURL URLWithBaseURL:URL resourcePath:@"/entries"];
|
||||
assertThat([rkURL absoluteString], equalTo(@"http://restkit.org/entries"));
|
||||
}
|
||||
|
||||
- (void)testMergingOfAdditionalQueryParameters
|
||||
{
|
||||
NSURL *URL = [NSURL URLWithString:@"http://restkit.org/search?title=Hacking"];
|
||||
NSDictionary *params = [NSDictionary dictionaryWithObject:@"Computers" forKey:@"genre"];
|
||||
RKURL *newURL = [RKURL URLWithBaseURL:URL resourcePath:nil queryParameters:params];
|
||||
assertThat([newURL queryParameters], hasEntries(@"title", equalTo(@"Hacking"), @"genre", equalTo(@"Computers"), nil));
|
||||
}
|
||||
|
||||
- (void)testReplacementOfExistingResourcePath
|
||||
{
|
||||
RKURL *URL = [RKURL URLWithBaseURLString:@"http://restkit.org/" resourcePath:@"/articles"];
|
||||
RKURL *newURL = [URL URLByReplacingResourcePath:@"/files"];
|
||||
assertThat([newURL absoluteString], equalTo(@"http://restkit.org/files"));
|
||||
assertThat([newURL resourcePath], equalTo(@"/files"));
|
||||
}
|
||||
|
||||
- (void)testReplacementOfNilResourcePath
|
||||
{
|
||||
RKURL *URL = [RKURL URLWithString:@"http://restkit.org/whatever"];
|
||||
assertThat([URL resourcePath], is(nilValue()));
|
||||
RKURL *newURL = [URL URLByReplacingResourcePath:@"/works"];
|
||||
assertThat([newURL resourcePath], is(equalTo(@"/works")));
|
||||
assertThat([newURL absoluteString], is(equalTo(@"http://restkit.org/whatever/works")));
|
||||
}
|
||||
|
||||
- (void)testInterpolationOfResourcePath
|
||||
{
|
||||
RKURL *URL = [RKURL URLWithBaseURLString:@"http://restkit.org" resourcePath:@"/paginate?page=:page&perPage=:per_page"];
|
||||
NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"1", @"page", @"25", @"per_page", nil];
|
||||
RKURL *interpolatedURL = [URL URLByInterpolatingResourcePathWithObject:dictionary];
|
||||
assertThat([interpolatedURL resourcePath], is(equalTo(@"/paginate?page=1&perPage=25")));
|
||||
|
||||
NSDictionary *queryParams = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
@"25", @"perPage",
|
||||
@"1", @"page",
|
||||
nil];
|
||||
assertThat([interpolatedURL resourcePath], is(equalTo(@"/paginate?page=1&perPage=25")));
|
||||
assertThat([interpolatedURL queryParameters], is(equalTo(queryParams)));
|
||||
}
|
||||
|
||||
- (void)testShouldProperlyHandleLongURLParameterValues
|
||||
{
|
||||
NSString *longResourcePath = @"";
|
||||
for (NSUInteger index = 0; index < 1050; index++) {
|
||||
longResourcePath = [longResourcePath stringByAppendingString:@"X"];
|
||||
}
|
||||
assertThatInteger([longResourcePath length], is(equalToInt(1050)));
|
||||
|
||||
RKURL *URL = [RKURL URLWithBaseURLString:[RKTestFactory baseURLString]
|
||||
resourcePath:longResourcePath];
|
||||
assertThat([URL absoluteString], is(equalTo([NSString stringWithFormat:@"%@/%@", [RKTestFactory baseURLString], longResourcePath])));
|
||||
}
|
||||
|
||||
- (void)testThatPathIsPreservedWhenURLIsConstructedFromAnotherRKURL
|
||||
{
|
||||
RKURL *URL = [RKURL URLWithBaseURL:[RKTestFactory baseURL] resourcePath:@"/this/and/that"];
|
||||
RKURL *newURL = [URL URLByAppendingResourcePath:@"/the/other/thing" queryParameters:[NSDictionary dictionaryWithObject:@"up" forKey:@"word"]];
|
||||
assertThat([newURL absoluteString], is(equalTo(@"http://127.0.0.1:4567/this/and/that/the/other/thing?word=up")));
|
||||
}
|
||||
|
||||
- (void)testThatResourcePathIsPreservedWhenURLIsConstructedFromAnotherRKURL
|
||||
{
|
||||
RKURL *URL = [RKURL URLWithBaseURL:[RKTestFactory baseURL] resourcePath:@"/this/and/that"];
|
||||
RKURL *newURL = [URL URLByAppendingResourcePath:@"/the/other/thing" queryParameters:[NSDictionary dictionaryWithObject:@"up" forKey:@"word"]];
|
||||
assertThat([newURL resourcePath], is(equalTo(@"/the/other/thing")));
|
||||
}
|
||||
|
||||
- (void)testThatPathAndQueryParamsArePreservedWhenURLIsConstructedFromAnotherRKURL
|
||||
{
|
||||
RKURL *URL = [RKURL URLWithBaseURL:[RKTestFactory baseURL] resourcePath:@"/this/and/that" queryParameters:[NSDictionary dictionaryWithObject:@"who" forKey:@"where"]];
|
||||
RKURL *newURL = [URL URLByAppendingResourcePath:@"/the/other/thing" queryParameters:[NSDictionary dictionaryWithObject:@"up" forKey:@"word"]];
|
||||
assertThat([newURL absoluteString], is(equalTo(@"http://127.0.0.1:4567/this/and/that/the/other/thing?where=who&word=up")));
|
||||
}
|
||||
|
||||
- (void)testCreationOfMultipleURLsFromASinglePattern
|
||||
{
|
||||
RKURL *patternURL = [RKURL URLWithBaseURLString:@"http://restkit.org" resourcePath:@"/people/:personID"];
|
||||
NSDictionary *person1 = [NSDictionary dictionaryWithObject:@"1" forKey:@"personID"];
|
||||
NSDictionary *person2 = [NSDictionary dictionaryWithObject:@"2" forKey:@"personID"];
|
||||
NSDictionary *person3 = [NSDictionary dictionaryWithObject:@"3" forKey:@"personID"];
|
||||
NSArray *personURLs = [patternURL URLsByInterpolatingResourcePathWithObjects:[NSArray arrayWithObjects:person1, person2, person3, nil]];
|
||||
assertThat(personURLs, hasCountOf(3));
|
||||
assertThat([personURLs valueForKey:@"absoluteString"], hasItems(@"http://restkit.org/people/1", @"http://restkit.org/people/2", @"http://restkit.org/people/3", nil));
|
||||
}
|
||||
|
||||
- (void)testCreationOfMultipleURLsFromInvalidPatternReturnsNil
|
||||
{
|
||||
RKURL *patternURL = [RKURL URLWithBaseURLString:@"http://•!.restkit.org" resourcePath:@"/people/:personID"];
|
||||
NSDictionary *person1 = [NSDictionary dictionaryWithObject:@"1" forKey:@"personID"];
|
||||
NSArray *personURLs = [patternURL URLsByInterpolatingResourcePathWithObjects:[NSArray arrayWithObject:person1]];
|
||||
assertThat(personURLs, is(nilValue()));
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -22,7 +22,7 @@
|
||||
#import "RKDynamicMapping.h"
|
||||
#import "RKDynamicMappingModels.h"
|
||||
|
||||
@interface RKDynamicMappingTest : RKTestCase <RKDynamicMappingDelegate>
|
||||
@interface RKDynamicMappingTest : RKTestCase
|
||||
|
||||
@end
|
||||
|
||||
@@ -30,13 +30,11 @@
|
||||
|
||||
- (void)testShouldPickTheAppropriateMappingBasedOnAnAttributeValue
|
||||
{
|
||||
RKDynamicMapping *dynamicMapping = [RKDynamicMapping dynamicMapping];
|
||||
RKObjectMapping *girlMapping = [RKObjectMapping mappingForClass:[Girl class] usingBlock:^(RKObjectMapping *mapping) {
|
||||
[mapping mapAttributes:@"name", nil];
|
||||
}];
|
||||
RKObjectMapping *boyMapping = [RKObjectMapping mappingForClass:[Boy class] usingBlock:^(RKObjectMapping *mapping) {
|
||||
[mapping mapAttributes:@"name", nil];
|
||||
}];
|
||||
RKDynamicMapping *dynamicMapping = [RKDynamicMapping new];
|
||||
RKObjectMapping *girlMapping = [RKObjectMapping mappingForClass:[Girl class]];
|
||||
[girlMapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
RKObjectMapping *boyMapping = [RKObjectMapping mappingForClass:[Boy class]];
|
||||
[boyMapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
[dynamicMapping setObjectMapping:girlMapping whenValueOfKeyPath:@"type" isEqualTo:@"Girl"];
|
||||
[dynamicMapping setObjectMapping:boyMapping whenValueOfKeyPath:@"type" isEqualTo:@"Boy"];
|
||||
RKObjectMapping *mapping = [dynamicMapping objectMappingForRepresentation:[RKTestFixture parsedObjectWithContentsOfFixture:@"girl.json"]];
|
||||
@@ -49,13 +47,11 @@
|
||||
|
||||
- (void)testShouldMatchOnAnNSNumberAttributeValue
|
||||
{
|
||||
RKDynamicMapping *dynamicMapping = [RKDynamicMapping dynamicMapping];
|
||||
RKObjectMapping *girlMapping = [RKObjectMapping mappingForClass:[Girl class] usingBlock:^(RKObjectMapping *mapping) {
|
||||
[mapping mapAttributes:@"name", nil];
|
||||
}];
|
||||
RKObjectMapping *boyMapping = [RKObjectMapping mappingForClass:[Boy class] usingBlock:^(RKObjectMapping *mapping) {
|
||||
[mapping mapAttributes:@"name", nil];
|
||||
}];
|
||||
RKDynamicMapping *dynamicMapping = [RKDynamicMapping new];
|
||||
RKObjectMapping *girlMapping = [RKObjectMapping mappingForClass:[Girl class]];
|
||||
[girlMapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
RKObjectMapping *boyMapping = [RKObjectMapping mappingForClass:[Boy class]];
|
||||
[boyMapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
[dynamicMapping setObjectMapping:girlMapping whenValueOfKeyPath:@"numeric_type" isEqualTo:[NSNumber numberWithInt:0]];
|
||||
[dynamicMapping setObjectMapping:boyMapping whenValueOfKeyPath:@"numeric_type" isEqualTo:[NSNumber numberWithInt:1]];
|
||||
RKObjectMapping *mapping = [dynamicMapping objectMappingForRepresentation:[RKTestFixture parsedObjectWithContentsOfFixture:@"girl.json"]];
|
||||
@@ -66,30 +62,18 @@
|
||||
assertThat(NSStringFromClass(mapping.objectClass), is(equalTo(@"Boy")));
|
||||
}
|
||||
|
||||
- (void)testShouldPickTheAppropriateMappingBasedOnDelegateCallback
|
||||
{
|
||||
RKDynamicMapping *dynamicMapping = [RKDynamicMapping dynamicMapping];
|
||||
dynamicMapping.delegate = self;
|
||||
RKObjectMapping *mapping = [dynamicMapping objectMappingForRepresentation:[RKTestFixture parsedObjectWithContentsOfFixture:@"girl.json"]];
|
||||
assertThat(mapping, is(notNilValue()));
|
||||
assertThat(NSStringFromClass(mapping.objectClass), is(equalTo(@"Girl")));
|
||||
mapping = [dynamicMapping objectMappingForRepresentation:[RKTestFixture parsedObjectWithContentsOfFixture:@"boy.json"]];
|
||||
assertThat(mapping, is(notNilValue()));
|
||||
assertThat(NSStringFromClass(mapping.objectClass), is(equalTo(@"Boy")));
|
||||
}
|
||||
|
||||
- (void)testShouldPickTheAppropriateMappingBasedOnBlockDelegateCallback
|
||||
{
|
||||
RKDynamicMapping *dynamicMapping = [RKDynamicMapping dynamicMapping];
|
||||
RKDynamicMapping *dynamicMapping = [RKDynamicMapping new];
|
||||
dynamicMapping.objectMappingForDataBlock = ^ RKObjectMapping *(id data) {
|
||||
if ([[data valueForKey:@"type"] isEqualToString:@"Girl"]) {
|
||||
return [RKObjectMapping mappingForClass:[Girl class] usingBlock:^(RKObjectMapping *mapping) {
|
||||
[mapping mapAttributes:@"name", nil];
|
||||
}];
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[Girl class]];
|
||||
[mapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
return mapping;
|
||||
} else if ([[data valueForKey:@"type"] isEqualToString:@"Boy"]) {
|
||||
return [RKObjectMapping mappingForClass:[Boy class] usingBlock:^(RKObjectMapping *mapping) {
|
||||
[mapping mapAttributes:@"name", nil];
|
||||
}];
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[Boy class]];
|
||||
[mapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
return mapping;
|
||||
}
|
||||
|
||||
return nil;
|
||||
@@ -105,7 +89,7 @@
|
||||
- (void)testShouldFailAnAssertionWhenInvokedWithSomethingOtherThanADictionary
|
||||
{
|
||||
NSException *exception = nil;
|
||||
RKDynamicMapping *dynamicMapping = [RKDynamicMapping dynamicMapping];
|
||||
RKDynamicMapping *dynamicMapping = [RKDynamicMapping new];
|
||||
@try {
|
||||
[dynamicMapping objectMappingForRepresentation:(NSDictionary *)[NSArray array]];
|
||||
}
|
||||
@@ -122,13 +106,13 @@
|
||||
- (RKObjectMapping *)objectMappingForData:(id)data
|
||||
{
|
||||
if ([[data valueForKey:@"type"] isEqualToString:@"Girl"]) {
|
||||
return [RKObjectMapping mappingForClass:[Girl class] usingBlock:^(RKObjectMapping *mapping) {
|
||||
[mapping mapAttributes:@"name", nil];
|
||||
}];
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[Girl class]];
|
||||
[mapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
return mapping;
|
||||
} else if ([[data valueForKey:@"type"] isEqualToString:@"Boy"]) {
|
||||
return [RKObjectMapping mappingForClass:[Boy class] usingBlock:^(RKObjectMapping *mapping) {
|
||||
[mapping mapAttributes:@"name", nil];
|
||||
}];
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[Boy class]];
|
||||
[mapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
return mapping;
|
||||
}
|
||||
|
||||
return nil;
|
||||
|
||||
@@ -17,16 +17,16 @@
|
||||
|
||||
- (void)testThatAttributeMappingsWithTheSameSourceAndDestinationKeyPathAreConsideredEqual
|
||||
{
|
||||
RKAttributeMapping *mapping1 = [RKAttributeMapping mappingFromKeyPath:@"this" toKeyPath:@"that"];
|
||||
RKAttributeMapping *mapping2 = [RKAttributeMapping mappingFromKeyPath:@"this" toKeyPath:@"that"];
|
||||
RKAttributeMapping *mapping1 = [RKAttributeMapping attributeMappingFromKeyPath:@"this" toKeyPath:@"that"];
|
||||
RKAttributeMapping *mapping2 = [RKAttributeMapping attributeMappingFromKeyPath:@"this" toKeyPath:@"that"];
|
||||
|
||||
assertThatBool([mapping1 isEqualToMapping:mapping2], is(equalToBool(YES)));
|
||||
}
|
||||
|
||||
- (void)testThatAttributeMappingsWithDifferingKeyPathsAreNotConsideredEqual
|
||||
{
|
||||
RKAttributeMapping *mapping1 = [RKAttributeMapping mappingFromKeyPath:@"this" toKeyPath:@"that"];
|
||||
RKAttributeMapping *mapping2 = [RKAttributeMapping mappingFromKeyPath:@"this" toKeyPath:@"the other"];
|
||||
RKAttributeMapping *mapping1 = [RKAttributeMapping attributeMappingFromKeyPath:@"this" toKeyPath:@"that"];
|
||||
RKAttributeMapping *mapping2 = [RKAttributeMapping attributeMappingFromKeyPath:@"this" toKeyPath:@"the other"];
|
||||
|
||||
assertThatBool([mapping1 isEqualToMapping:mapping2], is(equalToBool(NO)));
|
||||
}
|
||||
|
||||
@@ -105,18 +105,18 @@
|
||||
|
||||
- (RKObjectMappingProvider *)providerForComplexUser
|
||||
{
|
||||
RKObjectMappingProvider *provider = [[RKObjectMappingProvider new] autorelease];
|
||||
NSMutableDictionary *mappingDictionary = [NSMutableDictionary dictionary];
|
||||
RKObjectMapping *userMapping = [RKObjectMapping mappingForClass:[RKTestComplexUser class]];
|
||||
[userMapping addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"firstname" toKeyPath:@"firstname"]];
|
||||
[provider setMapping:userMapping forKeyPath:@"data.STUser"];
|
||||
[userMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"firstname" toKeyPath:@"firstname"]];
|
||||
[mappingsDictionary setObject:userMapping forKey:@"data.STUser"];
|
||||
return provider;
|
||||
}
|
||||
|
||||
- (RKObjectMappingProvider *)errorMappingProvider
|
||||
{
|
||||
RKObjectMappingProvider *provider = [[RKObjectMappingProvider new] autorelease];
|
||||
NSMutableDictionary *mappingDictionary = [NSMutableDictionary dictionary];
|
||||
RKObjectMapping *errorMapping = [RKObjectMapping mappingForClass:[RKErrorMessage class]];
|
||||
[errorMapping addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"" toKeyPath:@"errorMessage"]];
|
||||
[errorMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"" toKeyPath:@"errorMessage"]];
|
||||
errorMapping.rootKeyPath = @"errors";
|
||||
provider.errorMapping = errorMapping;
|
||||
return provider;
|
||||
@@ -265,9 +265,9 @@
|
||||
{
|
||||
RKObjectManager *objectManager = [RKTestFactory objectManager];
|
||||
RKObjectMapping *objectMapping = [RKObjectMapping mappingForClass:[RKObjectLoaderTestResultModel class]];
|
||||
[objectMapping mapKeyPath:@"id" toAttribute:@"ID"];
|
||||
[objectMapping mapKeyPath:@"ends_at" toAttribute:@"endsAt"];
|
||||
[objectMapping mapKeyPath:@"photo_url" toAttribute:@"photoURL"];
|
||||
[objectMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"id" toKeyPath:@"ID"]];
|
||||
[objectMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"ends_at" toKeyPath:@"endsAt"]];
|
||||
[objectMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"photo_url" toKeyPath:@"photoURL"]];
|
||||
[objectManager.mappingProvider setMapping:objectMapping forKeyPath:@"results"];
|
||||
RKTestResponseLoader *loader = [RKTestResponseLoader responseLoader];
|
||||
[objectManager loadObjectsAtResourcePath:@"/JSON/ArrayOfResults.json" delegate:loader];
|
||||
@@ -291,7 +291,7 @@
|
||||
- (void)testShouldAllowYouToPostAnObjectAndHandleAnEmpty204Response
|
||||
{
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[RKTestComplexUser class]];
|
||||
[mapping mapAttributes:@"firstname", @"lastname", @"email", nil];
|
||||
[mapping addAttributeMappingsFromArray:@[@"firstname", @"lastname", @"email"]];
|
||||
RKObjectMapping *serializationMapping = [mapping inverseMapping];
|
||||
|
||||
RKObjectManager *objectManager = [RKTestFactory objectManager];
|
||||
@@ -316,7 +316,7 @@
|
||||
- (void)testShouldAllowYouToPOSTAnObjectAndMapBackNonNestedContent
|
||||
{
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[RKTestComplexUser class]];
|
||||
[mapping mapAttributes:@"firstname", @"lastname", @"email", nil];
|
||||
[mapping addAttributeMappingsFromArray:@[@"firstname", @"lastname", @"email"]];
|
||||
RKObjectMapping *serializationMapping = [mapping inverseMapping];
|
||||
|
||||
RKObjectManager *objectManager = [RKTestFactory objectManager];
|
||||
@@ -344,7 +344,7 @@
|
||||
return;
|
||||
RKLogConfigureByName("RestKit/Network", RKLogLevelTrace);
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[RKTestComplexUser class]];
|
||||
[mapping mapAttributes:@"firstname", @"lastname", @"email", nil];
|
||||
[mapping addAttributeMappingsFromArray:@[@"firstname", @"lastname", @"email"]];
|
||||
RKObjectMapping *serializationMapping = [mapping inverseMapping];
|
||||
|
||||
RKObjectManager *objectManager = [RKTestFactory objectManager];
|
||||
@@ -370,11 +370,11 @@
|
||||
- (void)testShouldAllowYouToPOSTAnObjectOfOneTypeAndGetBackAnother
|
||||
{
|
||||
RKObjectMapping *sourceMapping = [RKObjectMapping mappingForClass:[RKTestComplexUser class]];
|
||||
[sourceMapping mapAttributes:@"firstname", @"lastname", @"email", nil];
|
||||
[sourceMapping addAttributeMappingsFromArray:@[@"firstname", @"lastname", @"email"]];
|
||||
RKObjectMapping *serializationMapping = [sourceMapping inverseMapping];
|
||||
|
||||
RKObjectMapping *targetMapping = [RKObjectMapping mappingForClass:[RKObjectLoaderTestResultModel class]];
|
||||
[targetMapping mapAttributes:@"ID", nil];
|
||||
[targetMapping addAttributeMappingsFromArray:@[@"ID"]];
|
||||
|
||||
RKObjectManager *objectManager = [RKTestFactory objectManager];
|
||||
[objectManager.router.routeSet addRoute:[RKRoute routeWithClass:[RKTestComplexUser class] pathPattern:@"/notNestedUser" method:RKRequestMethodAny]];
|
||||
@@ -407,11 +407,11 @@
|
||||
- (void)testShouldAllowYouToPOSTAnObjectOfOneTypeAndGetBackAnotherViaURLConfiguration
|
||||
{
|
||||
RKObjectMapping *sourceMapping = [RKObjectMapping mappingForClass:[RKTestComplexUser class]];
|
||||
[sourceMapping mapAttributes:@"firstname", @"lastname", @"email", nil];
|
||||
[sourceMapping addAttributeMappingsFromArray:@[@"firstname", @"lastname", @"email"]];
|
||||
RKObjectMapping *serializationMapping = [sourceMapping inverseMapping];
|
||||
|
||||
RKObjectMapping *targetMapping = [RKObjectMapping mappingForClass:[RKObjectLoaderTestResultModel class]];
|
||||
[targetMapping mapAttributes:@"ID", nil];
|
||||
[targetMapping addAttributeMappingsFromArray:@[@"ID"]];
|
||||
|
||||
RKObjectManager *objectManager = [RKTestFactory objectManager];
|
||||
[objectManager.router.routeSet addRoute:[RKRoute routeWithClass:[RKTestComplexUser class] pathPattern:@"/notNestedUser" method:RKRequestMethodAny]];
|
||||
@@ -445,7 +445,7 @@
|
||||
- (void)testShouldAllowYouToPOSTAnObjectAndMapBackNonNestedContentViapostObject
|
||||
{
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[RKTestComplexUser class]];
|
||||
[mapping mapAttributes:@"firstname", @"lastname", @"email", nil];
|
||||
[mapping addAttributeMappingsFromArray:@[@"firstname", @"lastname", @"email"]];
|
||||
RKObjectMapping *serializationMapping = [mapping inverseMapping];
|
||||
|
||||
RKObjectManager *objectManager = [RKTestFactory objectManager];
|
||||
@@ -472,7 +472,7 @@
|
||||
{
|
||||
RKObjectMapping *userMapping = [RKObjectMapping mappingForClass:[RKTestComplexUser class]];
|
||||
userMapping.rootKeyPath = @"data.STUser";
|
||||
[userMapping mapAttributes:@"firstname", nil];
|
||||
[userMapping addAttributeMappingsFromArray:@[@"firstname"]];
|
||||
|
||||
RKTestComplexUser *user = [[RKTestComplexUser new] autorelease];
|
||||
RKObjectManager *objectManager = [RKObjectManager managerWithBaseURL:[RKTestFactory baseURL]];
|
||||
@@ -494,7 +494,7 @@
|
||||
{
|
||||
RKObjectMapping *userMapping = [RKObjectMapping mappingForClass:[RKTestComplexUser class]];
|
||||
userMapping.rootKeyPath = @"data.STUser";
|
||||
[userMapping mapAttributes:@"firstname", nil];
|
||||
[userMapping addAttributeMappingsFromArray:@[@"firstname"]];
|
||||
|
||||
RKTestComplexUser *user = [[RKTestComplexUser new] autorelease];
|
||||
RKObjectManager *objectManager = [RKObjectManager managerWithBaseURL:[RKTestFactory baseURL]];
|
||||
@@ -520,7 +520,7 @@
|
||||
{
|
||||
RKObjectMapping *userMapping = [RKObjectMapping mappingForClass:[RKTestComplexUser class]];
|
||||
userMapping.rootKeyPath = @"data.STUser";
|
||||
[userMapping mapAttributes:@"firstname", nil];
|
||||
[userMapping addAttributeMappingsFromArray:@[@"firstname"]];
|
||||
|
||||
RKTestComplexUser *user = [[RKTestComplexUser new] autorelease];
|
||||
RKObjectManager *objectManager = [RKObjectManager managerWithBaseURL:[RKTestFactory baseURL]];
|
||||
@@ -553,7 +553,7 @@
|
||||
|
||||
RKObjectMapping *userMapping = [RKObjectMapping mappingForClass:[RKTestComplexUser class]];
|
||||
userMapping.rootKeyPath = @"data.STUser";
|
||||
[userMapping mapAttributes:@"firstname", nil];
|
||||
[userMapping addAttributeMappingsFromArray:@[@"firstname"]];
|
||||
RKTestResponseLoader *responseLoader = [RKTestResponseLoader responseLoader];
|
||||
RKObjectLoader *objectLoader = [objectManager loaderWithResourcePath:@"/humans/1234"];
|
||||
objectLoader.delegate = responseLoader;
|
||||
@@ -576,7 +576,7 @@
|
||||
|
||||
RKObjectMapping *userMapping = [RKObjectMapping mappingForClass:[RKTestComplexUser class]];
|
||||
userMapping.rootKeyPath = @"data.STUser";
|
||||
[userMapping mapAttributes:@"firstname", nil];
|
||||
[userMapping addAttributeMappingsFromArray:@[@"firstname"]];
|
||||
RKTestResponseLoader *responseLoader = [RKTestResponseLoader responseLoader];
|
||||
|
||||
RKObjectLoader *objectLoader = [RKObjectLoader loaderWithURL:[objectManager.baseURL URLByAppendingResourcePath:@"/humans/1234"] mappingProvider:objectManager.mappingProvider];
|
||||
@@ -594,7 +594,7 @@
|
||||
RKObjectManager *objectManager = [RKTestFactory objectManager];
|
||||
|
||||
RKObjectMapping *userMapping = [RKObjectMapping mappingForClass:[RKTestComplexUser class]];
|
||||
[userMapping mapAttributes:@"firstname", nil];
|
||||
[userMapping addAttributeMappingsFromArray:@[@"firstname"]];
|
||||
[objectManager.mappingProvider setMapping:userMapping forKeyPath:@"firstUser"];
|
||||
[objectManager.mappingProvider setMapping:userMapping forKeyPath:@"secondUser"];
|
||||
|
||||
@@ -647,7 +647,7 @@
|
||||
objectManager.client.requestQueue.concurrentRequestsLimit = 1;
|
||||
RKObjectMapping *userMapping = [RKObjectMapping mappingForClass:[RKTestComplexUser class]];
|
||||
userMapping.rootKeyPath = @"human";
|
||||
[userMapping mapAttributes:@"name", @"id", nil];
|
||||
[userMapping addAttributeMappingsFromArray:@[@"name", @"id"]];
|
||||
|
||||
// Suspend the Queue to block object mapping
|
||||
[objectManager.mappingQueue setSuspended:YES];
|
||||
@@ -796,7 +796,7 @@
|
||||
|
||||
RKObjectMapping *userMapping = [RKObjectMapping mappingForClass:[RKTestComplexUser class]];
|
||||
userMapping.rootKeyPath = @"data.STUser";
|
||||
[userMapping mapAttributes:@"firstname", nil];
|
||||
[userMapping addAttributeMappingsFromArray:@[@"firstname"]];
|
||||
RKObjectLoader *objectLoader = [objectManager loaderWithResourcePath:@"/humans/1"];
|
||||
objectLoader.objectMapping = userMapping;
|
||||
[objectLoader sendSynchronously];
|
||||
|
||||
@@ -45,36 +45,36 @@
|
||||
NSError *error;
|
||||
[_objectManager.managedObjectStore resetPersistentStores:&error];
|
||||
|
||||
RKObjectMappingProvider *provider = [[RKObjectMappingProvider new] autorelease];
|
||||
NSMutableDictionary *mappingDictionary = [NSMutableDictionary dictionary];
|
||||
|
||||
RKEntityMapping *humanMapping = [RKEntityMapping mappingForEntityForName:@"RKHuman" inManagedObjectStore:_objectManager.managedObjectStore];
|
||||
humanMapping.rootKeyPath = @"human";
|
||||
[humanMapping addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"name" toKeyPath:@"name"]];
|
||||
[humanMapping addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"nick-name" toKeyPath:@"nickName"]];
|
||||
[humanMapping addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"birthday" toKeyPath:@"birthday"]];
|
||||
[humanMapping addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"sex" toKeyPath:@"sex"]];
|
||||
[humanMapping addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"age" toKeyPath:@"age"]];
|
||||
[humanMapping addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"created-at" toKeyPath:@"createdAt"]];
|
||||
[humanMapping addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"updated-at" toKeyPath:@"updatedAt"]];
|
||||
[humanMapping addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"id" toKeyPath:@"railsID"]];
|
||||
[humanMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"name" toKeyPath:@"name"]];
|
||||
[humanMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"nick-name" toKeyPath:@"nickName"]];
|
||||
[humanMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"birthday" toKeyPath:@"birthday"]];
|
||||
[humanMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"sex" toKeyPath:@"sex"]];
|
||||
[humanMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"age" toKeyPath:@"age"]];
|
||||
[humanMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"created-at" toKeyPath:@"createdAt"]];
|
||||
[humanMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"updated-at" toKeyPath:@"updatedAt"]];
|
||||
[humanMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"id" toKeyPath:@"railsID"]];
|
||||
|
||||
RKEntityMapping *catMapping = [RKEntityMapping mappingForEntityForName:@"RKCat" inManagedObjectStore:_objectManager.managedObjectStore];
|
||||
[catMapping addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"name" toKeyPath:@"name"]];
|
||||
[catMapping addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"nick-name" toKeyPath:@"nickName"]];
|
||||
[catMapping addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"birthday" toKeyPath:@"birthday"]];
|
||||
[catMapping addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"sex" toKeyPath:@"sex"]];
|
||||
[catMapping addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"age" toKeyPath:@"age"]];
|
||||
[catMapping addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"created-at" toKeyPath:@"createdAt"]];
|
||||
[catMapping addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"updated-at" toKeyPath:@"updatedAt"]];
|
||||
[catMapping addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"id" toKeyPath:@"railsID"]];
|
||||
[catMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"name" toKeyPath:@"name"]];
|
||||
[catMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"nick-name" toKeyPath:@"nickName"]];
|
||||
[catMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"birthday" toKeyPath:@"birthday"]];
|
||||
[catMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"sex" toKeyPath:@"sex"]];
|
||||
[catMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"age" toKeyPath:@"age"]];
|
||||
[catMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"created-at" toKeyPath:@"createdAt"]];
|
||||
[catMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"updated-at" toKeyPath:@"updatedAt"]];
|
||||
[catMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"id" toKeyPath:@"railsID"]];
|
||||
|
||||
[catMapping addRelationshipMapping:[RKRelationshipMapping mappingFromKeyPath:@"cats" toKeyPath:@"cats" withMapping:catMapping]];
|
||||
[catMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"cats" toKeyPath:@"cats" withMapping:catMapping]];
|
||||
|
||||
[provider setMapping:humanMapping forKeyPath:@"human"];
|
||||
[provider setMapping:humanMapping forKeyPath:@"humans"];
|
||||
[mappingsDictionary setObject:humanMapping forKey:@"human"];
|
||||
[mappingsDictionary setObject:humanMapping forKey:@"humans"];
|
||||
|
||||
RKObjectMapping *humanSerialization = [RKObjectMapping mappingForClass:[NSDictionary class]];
|
||||
[humanSerialization addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"name" toKeyPath:@"name"]];
|
||||
[humanSerialization addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"name" toKeyPath:@"name"]];
|
||||
[provider setSerializationMapping:humanSerialization forClass:[RKHuman class]];
|
||||
_objectManager.mappingProvider = provider;
|
||||
[_objectManager.router.routeSet addRoute:[RKRoute routeWithClass:[RKHuman class] pathPattern:@"/humans" method:RKRequestMethodPOST]];
|
||||
@@ -111,7 +111,7 @@
|
||||
RKHuman *temporaryHuman = [NSEntityDescription insertNewObjectForEntityForName:@"RKHuman" inManagedObjectContext:_objectManager.managedObjectStore.primaryManagedObjectContext];
|
||||
temporaryHuman.name = @"My Name";
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[NSMutableDictionary class]];
|
||||
[mapping mapAttributes:@"name", nil];
|
||||
[mapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
|
||||
RKTestResponseLoader *loader = [RKTestResponseLoader responseLoader];
|
||||
NSString *resourcePath = @"/humans/fail";
|
||||
@@ -131,7 +131,7 @@
|
||||
RKHuman *temporaryHuman = [[RKHuman alloc] initWithEntity:[NSEntityDescription entityForName:@"RKHuman" inManagedObjectContext:_objectManager.managedObjectStore.primaryManagedObjectContext] insertIntoManagedObjectContext:_objectManager.managedObjectStore.primaryManagedObjectContext];
|
||||
temporaryHuman.name = @"My Name";
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[NSMutableDictionary class]];
|
||||
[mapping mapAttributes:@"name", nil];
|
||||
[mapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
|
||||
// Save it to suppress deletion
|
||||
[_objectManager.managedObjectStore.primaryManagedObjectContext save:nil];
|
||||
@@ -190,7 +190,7 @@
|
||||
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[RKObjectMapperTestModel class]];
|
||||
mapping.rootKeyPath = @"human";
|
||||
[mapping mapAttributes:@"name", @"age", nil];
|
||||
[mapping addAttributeMappingsFromArray:@[@"name", @"age"]];
|
||||
[manager.mappingProvider setMapping:mapping forKeyPath:@"human"];
|
||||
[manager.mappingProvider setSerializationMapping:mapping forClass:[RKObjectMapperTestModel class]];
|
||||
|
||||
@@ -213,7 +213,7 @@
|
||||
[objectManager.router.routeSet addRoute:[RKRoute routeWithClass:[RKObjectMapperTestModel class] pathPattern:@"/humans/1" method:RKRequestMethodAny]];
|
||||
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[RKObjectMapperTestModel class]];
|
||||
[mapping mapAttributes:@"name", @"age", nil];
|
||||
[mapping addAttributeMappingsFromArray:@[@"name", @"age"]];
|
||||
[objectManager.mappingProvider registerMapping:mapping withRootKeyPath:@"human"];
|
||||
|
||||
RKTestResponseLoader *responseLoader = [RKTestResponseLoader responseLoader];
|
||||
@@ -236,7 +236,7 @@
|
||||
[objectManager.router.routeSet addRoute:[RKRoute routeWithClass:[RKObjectMapperTestModel class] pathPattern:@"/humans/1" method:RKRequestMethodAny]];
|
||||
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[RKObjectMapperTestModel class]];
|
||||
[mapping mapAttributes:@"name", @"age", nil];
|
||||
[mapping addAttributeMappingsFromArray:@[@"name", @"age"]];
|
||||
[objectManager.mappingProvider registerMapping:mapping withRootKeyPath:@"human"];
|
||||
|
||||
RKTestResponseLoader *responseLoader = [RKTestResponseLoader responseLoader];
|
||||
@@ -259,7 +259,7 @@
|
||||
{
|
||||
RKObjectManager *objectManager = [RKTestFactory objectManager];
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[RKObjectMapperTestModel class]];
|
||||
[mapping mapAttributes:@"name", @"age", nil];
|
||||
[mapping addAttributeMappingsFromArray:@[@"name", @"age"]];
|
||||
[objectManager.mappingProvider registerMapping:mapping withRootKeyPath:@"human"];
|
||||
|
||||
RKTestResponseLoader *responseLoader = [[RKTestResponseLoader responseLoader] retain];
|
||||
@@ -277,7 +277,7 @@
|
||||
RKObjectManager *objectManager = [RKTestFactory objectManager];
|
||||
[objectManager.router.routeSet addRoute:[RKRoute routeWithClass:[RKObjectMapperTestModel class] pathPattern:@"/humans/2" method:RKRequestMethodAny]];
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[RKObjectMapperTestModel class]];
|
||||
[mapping mapAttributes:@"name", @"age", nil];
|
||||
[mapping addAttributeMappingsFromArray:@[@"name", @"age"]];
|
||||
[objectManager.mappingProvider registerMapping:mapping withRootKeyPath:@"human"];
|
||||
|
||||
RKTestResponseLoader *responseLoader = [RKTestResponseLoader responseLoader];
|
||||
@@ -297,7 +297,7 @@
|
||||
{
|
||||
RKObjectManager *objectManager = [RKTestFactory objectManager];
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[RKObjectMapperTestModel class]];
|
||||
[mapping mapAttributes:@"name", @"age", nil];
|
||||
[mapping addAttributeMappingsFromArray:@[@"name", @"age"]];
|
||||
[objectManager.mappingProvider registerMapping:mapping withRootKeyPath:@"human"];
|
||||
|
||||
RKTestResponseLoader *responseLoader = [RKTestResponseLoader responseLoader];
|
||||
@@ -318,7 +318,7 @@
|
||||
RKObjectManager *objectManager = [RKTestFactory objectManager];
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[RKObjectMapperTestModel class]];
|
||||
mapping.rootKeyPath = @"human";
|
||||
[mapping mapAttributes:@"name", @"age", nil];
|
||||
[mapping addAttributeMappingsFromArray:@[@"name", @"age"]];
|
||||
|
||||
RKTestResponseLoader *responseLoader = [RKTestResponseLoader responseLoader];
|
||||
RKObjectMapperTestModel *human = [[RKObjectMapperTestModel new] autorelease];
|
||||
@@ -339,7 +339,7 @@
|
||||
RKObjectManager *objectManager = [RKTestFactory objectManager];
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[RKObjectMapperTestModel class]];
|
||||
mapping.rootKeyPath = @"human";
|
||||
[mapping mapAttributes:@"name", @"age", nil];
|
||||
[mapping addAttributeMappingsFromArray:@[@"name", @"age"]];
|
||||
|
||||
RKTestResponseLoader *responseLoader = [RKTestResponseLoader responseLoader];
|
||||
RKObjectMapperTestModel *human = [[RKObjectMapperTestModel new] autorelease];
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -77,7 +77,7 @@
|
||||
- (void)testShouldNotUpdateEqualURLProperties
|
||||
{
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[TestMappable class]];
|
||||
[mapping mapAttributes:@"url", nil];
|
||||
[mapping addAttributeMappingsFromArray:@[@"url"]];
|
||||
NSURL *url1 = [NSURL URLWithString:@"http://www.restkit.org"];
|
||||
NSURL *url2 = [NSURL URLWithString:@"http://www.restkit.org"];
|
||||
assertThatBool(url1 == url2, is(equalToBool(NO)));
|
||||
@@ -86,7 +86,8 @@
|
||||
NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:url2, @"url", nil];
|
||||
|
||||
RKMappingOperation *operation = [[RKMappingOperation alloc] initWithSourceObject:dictionary destinationObject:object mapping:mapping];
|
||||
BOOL success = [operation performMapping:nil];
|
||||
[operation start];
|
||||
BOOL success = (operation.error == nil);
|
||||
assertThatBool(success, is(equalToBool(YES)));
|
||||
assertThatBool(object.url == url1, is(equalToBool(YES)));
|
||||
[operation release];
|
||||
@@ -95,14 +96,15 @@
|
||||
- (void)testShouldSuccessfullyMapBoolsToStrings
|
||||
{
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[TestMappable class]];
|
||||
[mapping mapAttributes:@"boolString", nil];
|
||||
[mapping addAttributeMappingsFromArray:@[@"boolString"]];
|
||||
TestMappable *object = [[[TestMappable alloc] init] autorelease];
|
||||
|
||||
id<RKSerialization> parser = [[RKParserRegistry sharedRegistry] parserForMIMEType:@"application/json"];
|
||||
id data = [parser objectFromString:@"{\"boolString\":true}" error:nil];
|
||||
NSData *data = [@"{\"boolString\":true}" dataUsingEncoding:NSUTF8StringEncoding];
|
||||
id deserializedObject = [RKMIMETypeSerialization objectFromData:data MIMEType:RKMIMETypeJSON error:nil];
|
||||
|
||||
RKMappingOperation *operation = [[RKMappingOperation alloc] initWithSourceObject:data destinationObject:object mapping:mapping];
|
||||
BOOL success = [operation performMapping:nil];
|
||||
RKMappingOperation *operation = [[RKMappingOperation alloc] initWithSourceObject:deserializedObject destinationObject:object mapping:mapping];
|
||||
[operation start];
|
||||
BOOL success = (operation.error == nil);
|
||||
assertThatBool(success, is(equalToBool(YES)));
|
||||
assertThat(object.boolString, is(equalTo(@"true")));
|
||||
[operation release];
|
||||
@@ -111,14 +113,15 @@
|
||||
- (void)testShouldSuccessfullyMapTrueBoolsToNSNumbers
|
||||
{
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[TestMappable class]];
|
||||
[mapping mapAttributes:@"boolNumber", nil];
|
||||
[mapping addAttributeMappingsFromArray:@[@"boolNumber"]];
|
||||
TestMappable *object = [[[TestMappable alloc] init] autorelease];
|
||||
|
||||
id<RKSerialization> parser = [[RKParserRegistry sharedRegistry] parserForMIMEType:@"application/json"];
|
||||
id data = [parser objectFromString:@"{\"boolNumber\":true}" error:nil];
|
||||
NSData *data = [@"{\"boolNumber\":true}" dataUsingEncoding:NSUTF8StringEncoding];
|
||||
id deserializedObject = [RKMIMETypeSerialization objectFromData:data MIMEType:RKMIMETypeJSON error:nil];
|
||||
|
||||
RKMappingOperation *operation = [[RKMappingOperation alloc] initWithSourceObject:data destinationObject:object mapping:mapping];
|
||||
BOOL success = [operation performMapping:nil];
|
||||
RKMappingOperation *operation = [[RKMappingOperation alloc] initWithSourceObject:deserializedObject destinationObject:object mapping:mapping];
|
||||
[operation start];
|
||||
BOOL success = (operation.error == nil);
|
||||
assertThatBool(success, is(equalToBool(YES)));
|
||||
assertThatInt([object.boolNumber intValue], is(equalToInt(1)));
|
||||
[operation release];
|
||||
@@ -127,14 +130,15 @@
|
||||
- (void)testShouldSuccessfullyMapFalseBoolsToNSNumbers
|
||||
{
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[TestMappable class]];
|
||||
[mapping mapAttributes:@"boolNumber", nil];
|
||||
[mapping addAttributeMappingsFromArray:@[@"boolNumber"]];
|
||||
TestMappable *object = [[[TestMappable alloc] init] autorelease];
|
||||
|
||||
NSData *data = [@"{\"boolNumber\":false}" dataUsingEncoding:NSUTF8StringEncoding];
|
||||
id deserializedObject = [RKMIMETypeSerialization objectFromData:data MIMEType:RKMIMETypeJSON error:nil];
|
||||
|
||||
id<RKSerialization> parser = [[RKParserRegistry sharedRegistry] parserForMIMEType:@"application/json"];
|
||||
id data = [parser objectFromString:@"{\"boolNumber\":false}" error:nil];
|
||||
|
||||
RKMappingOperation *operation = [[RKMappingOperation alloc] initWithSourceObject:data destinationObject:object mapping:mapping];
|
||||
BOOL success = [operation performMapping:nil];
|
||||
RKMappingOperation *operation = [[RKMappingOperation alloc] initWithSourceObject:deserializedObject destinationObject:object mapping:mapping];
|
||||
[operation start];
|
||||
BOOL success = (operation.error == nil);
|
||||
assertThatBool(success, is(equalToBool(YES)));
|
||||
assertThatInt([object.boolNumber intValue], is(equalToInt(0)));
|
||||
[operation release];
|
||||
@@ -143,14 +147,15 @@
|
||||
- (void)testShouldSuccessfullyMapNumbersToStrings
|
||||
{
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[TestMappable class]];
|
||||
[mapping mapKeyPath:@"number" toAttribute:@"boolString"];
|
||||
[mapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"number" toKeyPath:@"boolString"]];
|
||||
TestMappable *object = [[[TestMappable alloc] init] autorelease];
|
||||
|
||||
id<RKSerialization> parser = [[RKParserRegistry sharedRegistry] parserForMIMEType:@"application/json"];
|
||||
id data = [parser objectFromString:@"{\"number\":123}" error:nil];
|
||||
NSData *data = [@"{\"number\":123}" dataUsingEncoding:NSUTF8StringEncoding];
|
||||
id deserializedObject = [RKMIMETypeSerialization objectFromData:data MIMEType:RKMIMETypeJSON error:nil];
|
||||
|
||||
RKMappingOperation *operation = [[RKMappingOperation alloc] initWithSourceObject:data destinationObject:object mapping:mapping];
|
||||
BOOL success = [operation performMapping:nil];
|
||||
RKMappingOperation *operation = [[RKMappingOperation alloc] initWithSourceObject:deserializedObject destinationObject:object mapping:mapping];
|
||||
[operation start];
|
||||
BOOL success = (operation.error == nil);
|
||||
assertThatBool(success, is(equalToBool(YES)));
|
||||
assertThat(object.boolString, is(equalTo(@"123")));
|
||||
[operation release];
|
||||
@@ -159,13 +164,13 @@
|
||||
- (void)testShouldSuccessfullyMapArraysToOrderedSets
|
||||
{
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[TestMappable class]];
|
||||
[mapping mapKeyPath:@"numbers" toAttribute:@"orderedSet"];
|
||||
[mapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"numbers" toKeyPath:@"orderedSet"]];
|
||||
TestMappable *object = [[[TestMappable alloc] init] autorelease];
|
||||
|
||||
NSData *data = [@"{\"numbers\":[1, 2, 3]}" dataUsingEncoding:NSUTF8StringEncoding];
|
||||
id deserializedObject = [RKMIMETypeSerialization objectFromData:data MIMEType:RKMIMETypeJSON error:nil];
|
||||
|
||||
id<RKSerialization> parser = [[RKParserRegistry sharedRegistry] parserForMIMEType:@"application/json"];
|
||||
id data = [parser objectFromString:@"{\"numbers\":[1, 2, 3]}" error:nil];
|
||||
|
||||
RKMappingOperation *operation = [[RKMappingOperation alloc] initWithSourceObject:data destinationObject:object mapping:mapping];
|
||||
RKMappingOperation *operation = [[RKMappingOperation alloc] initWithSourceObject:deserializedObject destinationObject:object mapping:mapping];
|
||||
BOOL success = [operation performMapping:nil];
|
||||
assertThatBool(success, is(equalToBool(YES)));
|
||||
NSOrderedSet *expectedSet = [NSOrderedSet orderedSetWithObjects:[NSNumber numberWithInt:1], [NSNumber numberWithInt:2], [NSNumber numberWithInt:3], nil];
|
||||
@@ -176,7 +181,7 @@
|
||||
- (void)testShouldSuccessfullyMapOrderedSetsToArrays
|
||||
{
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[TestMappable class]];
|
||||
[mapping mapKeyPath:@"orderedSet" toAttribute:@"array"];
|
||||
[mapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"orderedSet" toKeyPath:@"array"]];
|
||||
TestMappable *object = [[[TestMappable alloc] init] autorelease];
|
||||
|
||||
TestMappable *data = [[[TestMappable alloc] init] autorelease];
|
||||
@@ -193,7 +198,7 @@
|
||||
- (void)testShouldFailTheMappingOperationIfKeyValueValidationSetsAnError
|
||||
{
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[TestMappable class]];
|
||||
[mapping mapAttributes:@"boolString", nil];
|
||||
[mapping addAttributeMappingsFromArray:@[@"boolString"]];
|
||||
TestMappable *object = [[[TestMappable alloc] init] autorelease];
|
||||
NSDictionary *dictionary = [NSDictionary dictionaryWithObject:@"FAIL" forKey:@"boolString"];
|
||||
RKMappingOperation *operation = [[RKMappingOperation alloc] initWithSourceObject:dictionary destinationObject:object mapping:mapping];
|
||||
@@ -207,7 +212,7 @@
|
||||
- (void)testShouldNotSetTheAttributeIfKeyValueValidationReturnsNo
|
||||
{
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[TestMappable class]];
|
||||
[mapping mapAttributes:@"boolString", nil];
|
||||
[mapping addAttributeMappingsFromArray:@[@"boolString"]];
|
||||
TestMappable *object = [[[TestMappable alloc] init] autorelease];
|
||||
object.boolString = @"should not change";
|
||||
NSDictionary *dictionary = [NSDictionary dictionaryWithObject:@"REJECT" forKey:@"boolString"];
|
||||
@@ -222,7 +227,7 @@
|
||||
- (void)testModifyingValueWithinKeyValueValidationIsRespected
|
||||
{
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[TestMappable class]];
|
||||
[mapping mapAttributes:@"boolString", nil];
|
||||
[mapping addAttributeMappingsFromArray:@[@"boolString"]];
|
||||
TestMappable *object = [[[TestMappable alloc] init] autorelease];
|
||||
NSDictionary *dictionary = [NSDictionary dictionaryWithObject:@"MODIFY" forKey:@"boolString"];
|
||||
RKMappingOperation *operation = [[RKMappingOperation alloc] initWithSourceObject:dictionary destinationObject:object mapping:mapping];
|
||||
@@ -238,7 +243,7 @@
|
||||
- (void)testShouldMapAUTCDateWithoutChangingTheTimeZone
|
||||
{
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[TestMappable class]];
|
||||
[mapping mapAttributes:@"date", nil];
|
||||
[mapping addAttributeMappingsFromArray:@[@"date"]];
|
||||
TestMappable *object = [[[TestMappable alloc] init] autorelease];
|
||||
NSDictionary *dictionary = [NSDictionary dictionaryWithObject:@"2011-07-07T04:35:28Z" forKey:@"date"];
|
||||
RKMappingOperation *operation = [[RKMappingOperation alloc] initWithSourceObject:dictionary destinationObject:object mapping:mapping];
|
||||
@@ -253,7 +258,7 @@
|
||||
- (void)testShouldMapAUnixTimestampStringAppropriately
|
||||
{
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[TestMappable class]];
|
||||
[mapping mapAttributes:@"date", nil];
|
||||
[mapping addAttributeMappingsFromArray:@[@"date"]];
|
||||
TestMappable *object = [[[TestMappable alloc] init] autorelease];
|
||||
NSDictionary *dictionary = [NSDictionary dictionaryWithObject:@"457574400" forKey:@"date"];
|
||||
RKMappingOperation *operation = [[RKMappingOperation alloc] initWithSourceObject:dictionary destinationObject:object mapping:mapping];
|
||||
@@ -268,7 +273,7 @@
|
||||
- (void)testShouldMapASimpleDateStringAppropriately
|
||||
{
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[TestMappable class]];
|
||||
[mapping mapAttributes:@"date", nil];
|
||||
[mapping addAttributeMappingsFromArray:@[@"date"]];
|
||||
TestMappable *object = [[[TestMappable alloc] init] autorelease];
|
||||
NSDictionary *dictionary = [NSDictionary dictionaryWithObject:@"08/09/2011" forKey:@"date"];
|
||||
RKMappingOperation *operation = [[RKMappingOperation alloc] initWithSourceObject:dictionary destinationObject:object mapping:mapping];
|
||||
@@ -283,7 +288,7 @@
|
||||
- (void)testShouldMapAISODateStringAppropriately
|
||||
{
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[TestMappable class]];
|
||||
[mapping mapAttributes:@"date", nil];
|
||||
[mapping addAttributeMappingsFromArray:@[@"date"]];
|
||||
TestMappable *object = [[[TestMappable alloc] init] autorelease];
|
||||
NSDictionary *dictionary = [NSDictionary dictionaryWithObject:@"2011-08-09T00:00Z" forKey:@"date"];
|
||||
RKMappingOperation *operation = [[RKMappingOperation alloc] initWithSourceObject:dictionary destinationObject:object mapping:mapping];
|
||||
@@ -302,7 +307,7 @@
|
||||
dateFormatter.dateFormat = @"MM-dd-yyyy";
|
||||
dateFormatter.timeZone = EDTTimeZone;
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[TestMappable class]];
|
||||
[mapping mapAttributes:@"date", nil];
|
||||
[mapping addAttributeMappingsFromArray:@[@"date"]];
|
||||
mapping.dateFormatters = [NSArray arrayWithObject:dateFormatter];
|
||||
TestMappable *object = [[[TestMappable alloc] init] autorelease];
|
||||
NSDictionary *dictionary = [NSDictionary dictionaryWithObject:@"11-27-1982" forKey:@"date"];
|
||||
@@ -319,7 +324,7 @@
|
||||
- (void)testShouldMapADateToAStringUsingThePreferredDateFormatter
|
||||
{
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[TestMappable class]];
|
||||
[mapping mapKeyPath:@"date" toAttribute:@"boolString"];
|
||||
[mapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"date" toKeyPath:@"boolString"]];
|
||||
NSDateFormatter *dateFormatter = [[NSDateFormatter new] autorelease];
|
||||
dateFormatter.dateFormat = @"MM-dd-yyyy";
|
||||
dateFormatter.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
|
||||
@@ -337,7 +342,7 @@
|
||||
- (void)testShouldGenerateAnUnknownKeyPathExceptionWhenIgnoreUnknownKeyPathsIsNO
|
||||
{
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[NSMutableDictionary class]];
|
||||
[mapping mapAttributes:@"invalid", @"boolString", nil];
|
||||
[mapping addAttributeMappingsFromArray:@[@"invalid", @"boolString"]];
|
||||
mapping.ignoreUnknownKeyPaths = NO;
|
||||
TestMappable *object = [[[TestMappable alloc] init] autorelease];
|
||||
object.boolString = @"test";
|
||||
@@ -361,7 +366,7 @@
|
||||
- (void)testShouldOptionallyIgnoreUnknownKeyPathAttributes
|
||||
{
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[NSMutableDictionary class]];
|
||||
[mapping mapAttributes:@"invalid", @"boolString", nil];
|
||||
[mapping addAttributeMappingsFromArray:@[@"invalid", @"boolString"]];
|
||||
mapping.ignoreUnknownKeyPaths = YES;
|
||||
TestMappable *object = [[[TestMappable alloc] init] autorelease];
|
||||
object.boolString = @"test";
|
||||
@@ -386,8 +391,8 @@
|
||||
- (void)testShouldOptionallyIgnoreUnknownKeyPathRelationships
|
||||
{
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[NSMutableDictionary class]];
|
||||
[mapping mapAttributes:@"boolString", nil];
|
||||
[mapping mapRelationship:@"invalid" withMapping:[RKObjectMapping mappingForClass:[TestMappable class]]];
|
||||
[mapping addAttributeMappingsFromArray:@[@"boolString"]];
|
||||
[mapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"invalid" toKeyPath:@"invalid" withMapping:[RKObjectMapping mappingForClass:[TestMappable class]]]];
|
||||
mapping.ignoreUnknownKeyPaths = YES;
|
||||
TestMappable *object = [[[TestMappable alloc] init] autorelease];
|
||||
object.boolString = @"test";
|
||||
@@ -415,10 +420,10 @@
|
||||
// Use keyPath to traverse to the collection and target a hasMany
|
||||
id data = [RKTestFixture parsedObjectWithContentsOfFixture:@"ArrayOfNestedDictionaries.json"];
|
||||
RKObjectMapping *objectMapping = [RKObjectMapping mappingForClass:[RKMappableObject class]];
|
||||
[objectMapping mapKeyPath:@"name" toAttribute:@"stringTest"];
|
||||
[objectMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"name" toKeyPath:@"stringTest"]];
|
||||
RKObjectMapping *relationshipMapping = [RKObjectMapping mappingForClass:[RKMappableAssociation class]];
|
||||
[relationshipMapping mapKeyPath:@"title" toAttribute:@"testString"];
|
||||
[objectMapping mapKeyPath:@"mediaGroups.contents" toRelationship:@"hasMany" withMapping:relationshipMapping];
|
||||
[relationshipMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"title" toKeyPath:@"testString"]];
|
||||
[objectMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"mediaGroups.contents" toKeyPath:@"hasMany" withMapping:relationshipMapping]];;
|
||||
RKMappableObject *targetObject = [[RKMappableObject new] autorelease];
|
||||
RKLogToComponentWithLevelWhileExecutingBlock(lcl_cRestKitObjectMapping, RKLogLevelDebug, ^ {
|
||||
RKMappingOperation *operation = [[RKMappingOperation alloc] initWithSourceObject:data
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
RKManagedObjectStore *managedObjectStore = [RKTestFactory managedObjectStore];
|
||||
RKEntityMapping *humanMapping = [RKEntityMapping mappingForEntityForName:@"RKHuman" inManagedObjectStore:managedObjectStore];
|
||||
assertThat(humanMapping, isNot(equalTo(nil)));
|
||||
[humanMapping mapAttributes:@"name", nil];
|
||||
[humanMapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
[_objectManager.mappingProvider addObjectMapping:humanMapping];
|
||||
RKMapping *returnedMapping = [_objectManager.mappingProvider objectMappingForClass:[RKHuman class]];
|
||||
assertThat(returnedMapping, isNot(equalTo(nil)));
|
||||
@@ -63,7 +63,7 @@
|
||||
RKManagedObjectStore *managedObjectStore = [RKTestFactory managedObjectStore];
|
||||
RKEntityMapping *catMapping = [RKEntityMapping mappingForEntityForName:@"RKCat" inManagedObjectStore:managedObjectStore];
|
||||
assertThat(catMapping, isNot(equalTo(nil)));
|
||||
[catMapping mapAttributes:@"name", nil];
|
||||
[catMapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
[_objectManager.mappingProvider setMapping:catMapping forKeyPath:@"cat"];
|
||||
RKMapping *returnedMapping = [_objectManager.mappingProvider mappingForKeyPath:@"cat"];
|
||||
assertThat(returnedMapping, isNot(equalTo(nil)));
|
||||
@@ -76,7 +76,7 @@
|
||||
RKObjectMappingProvider *mappingProvider = [RKObjectMappingProvider mappingProvider];
|
||||
RKEntityMapping *catMapping = [RKEntityMapping mappingForEntityForName:@"RKCat" inManagedObjectStore:managedObjectStore];
|
||||
assertThat(catMapping, isNot(equalTo(nil)));
|
||||
[catMapping mapAttributes:@"name", nil];
|
||||
[catMapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
[mappingProvider setMapping:catMapping forKeyPath:@"cat"];
|
||||
RKMapping *returnedMapping = [mappingProvider mappingForKeyPath:@"cat"];
|
||||
assertThat(returnedMapping, isNot(equalTo(nil)));
|
||||
|
||||
@@ -30,9 +30,9 @@
|
||||
- (void)testShouldNotCrashWhenAsObjectIsInvokedOnAnEmptyResult
|
||||
{
|
||||
NSException *exception = nil;
|
||||
RKMappingResult *result = [RKMappingResult mappingResultWithDictionary:[NSDictionary dictionary]];
|
||||
RKMappingResult *result = [[RKMappingResult alloc] initWithDictionary:[NSDictionary dictionary]];
|
||||
@try {
|
||||
[result asObject];
|
||||
[result firstObject];
|
||||
}
|
||||
@catch (NSException *e) {
|
||||
exception = e;
|
||||
@@ -44,15 +44,15 @@
|
||||
|
||||
- (void)testShouldReturnNilForAnEmptyCollectionCoercedToAsObject
|
||||
{
|
||||
RKMappingResult *result = [RKMappingResult mappingResultWithDictionary:[NSDictionary dictionary]];
|
||||
assertThat([result asObject], is(equalTo(nil)));
|
||||
RKMappingResult *result = [[RKMappingResult alloc] initWithDictionary:[NSDictionary dictionary]];
|
||||
assertThat([result firstObject], is(equalTo(nil)));
|
||||
}
|
||||
|
||||
- (void)testShouldReturnTheFirstObjectInTheCollectionWhenCoercedToAsObject
|
||||
{
|
||||
NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"one", @"one", @"two", @"two", nil];
|
||||
RKMappingResult *result = [RKMappingResult mappingResultWithDictionary:dictionary];
|
||||
assertThat([result asObject], is(equalTo(@"one")));
|
||||
RKMappingResult *result = [[RKMappingResult alloc] initWithDictionary:dictionary];
|
||||
assertThat([result firstObject], is(equalTo(@"one")));
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -49,9 +49,9 @@
|
||||
- (void)testThatTwoMappingsForTheSameObjectClassContainingIdenticalAttributeMappingsAreConsideredEqual
|
||||
{
|
||||
RKObjectMapping *mapping1 = [RKObjectMapping mappingForClass:[NSString class]];
|
||||
[mapping1 mapKeyPath:@"this" toAttribute:@"that"];
|
||||
[mapping1 addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"this" toKeyPath:@"that"]];
|
||||
RKObjectMapping *mapping2 = [RKObjectMapping mappingForClass:[NSString class]];
|
||||
[mapping2 mapKeyPath:@"this" toAttribute:@"that"];
|
||||
[mapping2 addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"this" toKeyPath:@"that"]];
|
||||
|
||||
assertThatBool([mapping1 isEqualToMapping:mapping2], is(equalToBool(YES)));
|
||||
}
|
||||
@@ -59,9 +59,9 @@
|
||||
- (void)testThatTwoMappingsForTheSameObjectClassContainingDifferingAttributeMappingsAreNotConsideredEqual
|
||||
{
|
||||
RKObjectMapping *mapping1 = [RKObjectMapping mappingForClass:[NSString class]];
|
||||
[mapping1 mapKeyPath:@"this" toAttribute:@"that"];
|
||||
[mapping1 addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"this" toKeyPath:@"that"]];
|
||||
RKObjectMapping *mapping2 = [RKObjectMapping mappingForClass:[NSString class]];
|
||||
[mapping2 mapKeyPath:@"different" toAttribute:@"that"];
|
||||
[mapping2 addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"different" toKeyPath:@"that"]];
|
||||
|
||||
assertThatBool([mapping1 isEqualToMapping:mapping2], is(equalToBool(NO)));
|
||||
}
|
||||
@@ -72,9 +72,9 @@
|
||||
RKObjectMapping *relationshipMapping2 = [RKObjectMapping mappingForClass:[NSSet class]];
|
||||
|
||||
RKObjectMapping *mapping1 = [RKObjectMapping mappingForClass:[NSString class]];
|
||||
[mapping1 mapKeyPath:@"this" toRelationship:@"that" withMapping:relationshipMapping1];
|
||||
[mapping1 addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"this" toKeyPath:@"that" withMapping:relationshipMapping1]];;
|
||||
RKObjectMapping *mapping2 = [RKObjectMapping mappingForClass:[NSString class]];
|
||||
[mapping2 mapKeyPath:@"this" toRelationship:@"that" withMapping:relationshipMapping2];
|
||||
[mapping2 addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"this" toKeyPath:@"that" withMapping:relationshipMapping2]];;
|
||||
|
||||
assertThatBool([mapping1 isEqualToMapping:mapping2], is(equalToBool(YES)));
|
||||
}
|
||||
@@ -85,9 +85,9 @@
|
||||
RKObjectMapping *relationshipMapping2 = [RKObjectMapping mappingForClass:[NSNumber class]];
|
||||
|
||||
RKObjectMapping *mapping1 = [RKObjectMapping mappingForClass:[NSString class]];
|
||||
[mapping1 mapKeyPath:@"this" toRelationship:@"that" withMapping:relationshipMapping1];
|
||||
[mapping1 addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"this" toKeyPath:@"that" withMapping:relationshipMapping1]];;
|
||||
RKObjectMapping *mapping2 = [RKObjectMapping mappingForClass:[NSString class]];
|
||||
[mapping2 mapKeyPath:@"this" toRelationship:@"that" withMapping:relationshipMapping2];
|
||||
[mapping2 addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"this" toKeyPath:@"that" withMapping:relationshipMapping2]];;
|
||||
|
||||
assertThatBool([mapping1 isEqualToMapping:mapping2], is(equalToBool(NO)));
|
||||
}
|
||||
@@ -98,9 +98,9 @@
|
||||
RKObjectMapping *relationshipMapping2 = [RKObjectMapping mappingForClass:[NSSet class]];
|
||||
|
||||
RKObjectMapping *mapping1 = [RKObjectMapping mappingForClass:[NSString class]];
|
||||
[mapping1 mapKeyPath:@"this" toRelationship:@"that" withMapping:relationshipMapping1];
|
||||
[mapping1 addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"this" toKeyPath:@"that" withMapping:relationshipMapping1]];;
|
||||
RKObjectMapping *mapping2 = [RKObjectMapping mappingForClass:[NSString class]];
|
||||
[mapping2 mapKeyPath:@"this" toRelationship:@"different" withMapping:relationshipMapping2];
|
||||
[mapping2 addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"this" toKeyPath:@"different" withMapping:relationshipMapping2]];;
|
||||
|
||||
assertThatBool([mapping1 isEqualToMapping:mapping2], is(equalToBool(NO)));
|
||||
}
|
||||
|
||||
@@ -159,12 +159,12 @@ static NSString * const RKObjectPaginatorTestResourcePathPattern = @"/paginate?p
|
||||
- (RKObjectMappingProvider *)paginationMappingProvider
|
||||
{
|
||||
RKObjectMapping *paginationMapping = [RKObjectMapping mappingForClass:[RKObjectPaginator class]];
|
||||
[paginationMapping mapKeyPath:@"current_page" toAttribute:@"currentPage"];
|
||||
[paginationMapping mapKeyPath:@"per_page" toAttribute:@"perPage"];
|
||||
[paginationMapping mapKeyPath:@"total_entries" toAttribute:@"objectCount"];
|
||||
[paginationMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"current_page" toKeyPath:@"currentPage"]];
|
||||
[paginationMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"per_page" toKeyPath:@"perPage"]];
|
||||
[paginationMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"total_entries" toKeyPath:@"objectCount"]];
|
||||
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[RKObjectMapperTestModel class]];
|
||||
[mapping mapAttributes:@"name", @"age", nil];
|
||||
[mapping addAttributeMappingsFromArray:@[@"name", @"age"]];
|
||||
RKObjectMappingProvider *mappingProvider = [RKObjectMappingProvider mappingProvider];
|
||||
mappingProvider.paginationMapping = paginationMapping;
|
||||
[mappingProvider setObjectMapping:mapping forKeyPath:@"entries"];
|
||||
|
||||
@@ -19,7 +19,8 @@
|
||||
//
|
||||
|
||||
#import "RKTestEnvironment.h"
|
||||
#import "RKObjectSerializer.h"
|
||||
#import "RKObjectParameterization.h"
|
||||
#import "RKMIMETypeSerialization.h"
|
||||
#import "RKMappableObject.h"
|
||||
|
||||
@interface RKObjectSerializerTest : RKTestCase {
|
||||
@@ -33,32 +34,31 @@
|
||||
{
|
||||
NSDictionary *object = [NSDictionary dictionaryWithObjectsAndKeys:@"value1", @"key1", @"value2", @"key2", nil];
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[NSDictionary class]];
|
||||
[mapping addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"key1" toKeyPath:@"key1-form-name"]];
|
||||
[mapping addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"key2" toKeyPath:@"key2-form-name"]];
|
||||
RKObjectSerializer *serializer = [RKObjectSerializer serializerWithObject:object mapping:mapping];
|
||||
[mapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"key1" toKeyPath:@"key1-form-name"]];
|
||||
[mapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"key2" toKeyPath:@"key2-form-name"]];
|
||||
NSError *error = nil;
|
||||
id<RKRequestSerializable> serialization = [serializer serializationForMIMEType:@"application/x-www-form-urlencoded" error:&error];
|
||||
NSString *data = [[[NSString alloc] initWithData:[serialization HTTPBody] encoding:NSUTF8StringEncoding] autorelease];
|
||||
data = [data stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
||||
RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:mapping objectClass:[NSDictionary class] rootKeyPath:nil];
|
||||
|
||||
// URL Encode
|
||||
NSDictionary *parameters = [RKObjectParameterization parametersWithObject:object requestDescriptor:requestDescriptor error:&error];
|
||||
NSData *data = [RKMIMETypeSerialization dataFromObject:parameters MIMEType:RKMIMETypeFormURLEncoded error:&error];
|
||||
NSString *string = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
||||
assertThat(error, is(nilValue()));
|
||||
assertThat(data, is(equalTo(@"key2-form-name=value2&key1-form-name=value1")));
|
||||
assertThat(string, is(equalTo(@"key2-form-name=value2&key1-form-name=value1")));
|
||||
}
|
||||
|
||||
- (void)testShouldSerializeADateToFormEncodedData
|
||||
{
|
||||
NSDictionary *object = [NSDictionary dictionaryWithObjectsAndKeys:@"value1", @"key1", [NSDate dateWithTimeIntervalSince1970:0], @"date", nil];
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[NSDictionary class]];
|
||||
[mapping addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"key1" toKeyPath:@"key1-form-name"]];
|
||||
[mapping addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"date" toKeyPath:@"date-form-name"]];
|
||||
RKObjectSerializer *serializer = [RKObjectSerializer serializerWithObject:object mapping:mapping];
|
||||
NSError *error = nil;
|
||||
id<RKRequestSerializable> serialization = [serializer serializationForMIMEType:@"application/x-www-form-urlencoded" error:&error];
|
||||
|
||||
NSString *data = [[[NSString alloc] initWithData:[serialization HTTPBody] encoding:NSUTF8StringEncoding] autorelease];
|
||||
data = [data stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
||||
|
||||
[mapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"key1" toKeyPath:@"key1-form-name"]];
|
||||
[mapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"date" toKeyPath:@"date-form-name"]];
|
||||
|
||||
NSError *error;
|
||||
RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:mapping objectClass:[NSDictionary class] rootKeyPath:nil];
|
||||
NSDictionary *parameters = [RKObjectParameterization parametersWithObject:object requestDescriptor:requestDescriptor error:&error];
|
||||
assertThat(error, is(nilValue()));
|
||||
assertThat(data, is(equalTo(@"key1-form-name=value1&date-form-name=1970-01-01 00:00:00 +0000")));
|
||||
assertThat(parameters[@"date-form-name"], is(equalTo(@"key1-form-name=value1&date-form-name=1970-01-01 00:00:00 +0000")));
|
||||
}
|
||||
|
||||
- (void)testShouldSerializeADateToAStringUsingThePreferredDateFormatter
|
||||
@@ -69,53 +69,53 @@
|
||||
dateFormatter.dateFormat = @"MM/dd/yyyy";
|
||||
dateFormatter.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
|
||||
mapping.preferredDateFormatter = dateFormatter;
|
||||
[mapping addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"key1" toKeyPath:@"key1-form-name"]];
|
||||
[mapping addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"date" toKeyPath:@"date-form-name"]];
|
||||
RKObjectSerializer *serializer = [RKObjectSerializer serializerWithObject:object mapping:mapping];
|
||||
NSError *error = nil;
|
||||
id<RKRequestSerializable> serialization = [serializer serializationForMIMEType:@"application/x-www-form-urlencoded" error:&error];
|
||||
|
||||
NSString *data = [[[NSString alloc] initWithData:[serialization HTTPBody] encoding:NSUTF8StringEncoding] autorelease];
|
||||
data = [data stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
||||
|
||||
[mapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"key1" toKeyPath:@"key1-form-name"]];
|
||||
[mapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"date" toKeyPath:@"date-form-name"]];
|
||||
|
||||
NSError *error;
|
||||
RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:mapping objectClass:[NSDictionary class] rootKeyPath:nil];
|
||||
NSDictionary *parameters = [RKObjectParameterization parametersWithObject:object requestDescriptor:requestDescriptor error:&error];
|
||||
|
||||
NSData *data = [RKMIMETypeSerialization dataFromObject:parameters MIMEType:RKMIMETypeFormURLEncoded error:&error];
|
||||
NSString *string = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
||||
assertThat(error, is(nilValue()));
|
||||
assertThat(data, is(equalTo(@"key1-form-name=value1&date-form-name=01/01/1970")));
|
||||
assertThat(string, is(equalTo(@"key1-form-name=value1&date-form-name=01/01/1970")));
|
||||
}
|
||||
|
||||
- (void)testShouldSerializeADateToJSON
|
||||
{
|
||||
NSDictionary *object = [NSDictionary dictionaryWithObjectsAndKeys:@"value1", @"key1", [NSDate dateWithTimeIntervalSince1970:0], @"date", nil];
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[NSDictionary class]];
|
||||
[mapping addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"key1" toKeyPath:@"key1-form-name"]];
|
||||
[mapping addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"date" toKeyPath:@"date-form-name"]];
|
||||
RKObjectSerializer *serializer = [RKObjectSerializer serializerWithObject:object mapping:mapping];
|
||||
[mapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"key1" toKeyPath:@"key1-form-name"]];
|
||||
[mapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"date" toKeyPath:@"date-form-name"]];
|
||||
|
||||
NSError *error = nil;
|
||||
id<RKRequestSerializable> serialization = [serializer serializationForMIMEType:@"application/json" error:&error];
|
||||
|
||||
NSString *data = [[[NSString alloc] initWithData:[serialization HTTPBody] encoding:NSUTF8StringEncoding] autorelease];
|
||||
data = [data stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
||||
NSError *error;
|
||||
RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:mapping objectClass:[NSDictionary class] rootKeyPath:nil];
|
||||
NSDictionary *parameters = [RKObjectParameterization parametersWithObject:object requestDescriptor:requestDescriptor error:&error];
|
||||
|
||||
NSData *data = [RKMIMETypeSerialization dataFromObject:parameters MIMEType:RKMIMETypeJSON error:&error];
|
||||
NSString *string = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
||||
|
||||
assertThat(error, is(nilValue()));
|
||||
assertThat(data, is(equalTo(@"{\"key1-form-name\":\"value1\",\"date-form-name\":\"1970-01-01 00:00:00 +0000\"}")));
|
||||
assertThat(string, is(equalTo(@"{\"key1-form-name\":\"value1\",\"date-form-name\":\"1970-01-01 00:00:00 +0000\"}")));
|
||||
}
|
||||
|
||||
- (void)testShouldSerializeNSDecimalNumberAttributesToJSON
|
||||
{
|
||||
NSDictionary *object = [NSDictionary dictionaryWithObjectsAndKeys:@"value1", @"key1", [NSDecimalNumber decimalNumberWithString:@"18274191731731.4557723623"], @"number", nil];
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[NSDictionary class]];
|
||||
[mapping addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"key1" toKeyPath:@"key1-form-name"]];
|
||||
[mapping addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"number" toKeyPath:@"number-form-name"]];
|
||||
RKObjectSerializer *serializer = [RKObjectSerializer serializerWithObject:object mapping:mapping];
|
||||
|
||||
NSError *error = nil;
|
||||
id<RKRequestSerializable> serialization = [serializer serializationForMIMEType:@"application/json" error:&error];
|
||||
|
||||
NSString *data = [[[NSString alloc] initWithData:[serialization HTTPBody] encoding:NSUTF8StringEncoding] autorelease];
|
||||
data = [data stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
||||
[mapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"key1" toKeyPath:@"key1-form-name"]];
|
||||
[mapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"number" toKeyPath:@"number-form-name"]];
|
||||
|
||||
NSError *error;
|
||||
RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:mapping objectClass:[NSDictionary class] rootKeyPath:nil];
|
||||
NSDictionary *parameters = [RKObjectParameterization parametersWithObject:object requestDescriptor:requestDescriptor error:&error];
|
||||
|
||||
NSData *data = [RKMIMETypeSerialization dataFromObject:parameters MIMEType:RKMIMETypeJSON error:&error];
|
||||
NSString *string = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
||||
|
||||
assertThat(error, is(nilValue()));
|
||||
assertThat(data, is(equalTo(@"{\"key1-form-name\":\"value1\",\"number-form-name\":\"18274191731731.4557723623\"}")));
|
||||
assertThat(string, is(equalTo(@"{\"key1-form-name\":\"value1\",\"number-form-name\":\"18274191731731.4557723623\"}")));
|
||||
}
|
||||
|
||||
- (void)testShouldSerializeRelationshipsToo
|
||||
@@ -128,22 +128,23 @@
|
||||
nil];
|
||||
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[NSMutableDictionary class]];
|
||||
[mapping addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"key1" toKeyPath:@"key1-form-name"]];
|
||||
[mapping addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"key2" toKeyPath:@"key2-form-name"]];
|
||||
[mapping addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"relationship1.relatioship1Key1" toKeyPath:@"relationship1-form-name[r1k1]"]];
|
||||
[mapping addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"relationship2.subKey1" toKeyPath:@"relationship2-form-name[subKey1]"]];
|
||||
[mapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"key1" toKeyPath:@"key1-form-name"]];
|
||||
[mapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"key2" toKeyPath:@"key2-form-name"]];
|
||||
[mapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"relationship1.relatioship1Key1" toKeyPath:@"relationship1-form-name[r1k1]"]];
|
||||
[mapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"relationship2.subKey1" toKeyPath:@"relationship2-form-name[subKey1]"]];
|
||||
|
||||
RKObjectSerializer *serializer = [RKObjectSerializer serializerWithObject:object mapping:mapping];
|
||||
NSError *error = nil;
|
||||
id<RKRequestSerializable> serialization = [serializer serializationForMIMEType:@"application/x-www-form-urlencoded" error:&error];
|
||||
NSString *data = [[[NSString alloc] initWithData:[serialization HTTPBody] encoding:NSUTF8StringEncoding] autorelease];
|
||||
data = [data stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
||||
NSError *error;
|
||||
RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:mapping objectClass:[NSDictionary class] rootKeyPath:nil];
|
||||
NSDictionary *parameters = [RKObjectParameterization parametersWithObject:object requestDescriptor:requestDescriptor error:&error];
|
||||
|
||||
NSData *data = [RKMIMETypeSerialization dataFromObject:parameters MIMEType:RKMIMETypeFormURLEncoded error:&error];
|
||||
NSString *string = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
||||
|
||||
assertThat(error, is(nilValue()));
|
||||
#if TARGET_OS_IPHONE
|
||||
assertThat(data, is(equalTo(@"key1-form-name=value1&relationship1-form-name[r1k1][]=relationship1Value1&relationship1-form-name[r1k1][]=relationship1Value2&key2-form-name=value2&relationship2-form-name[subKey1]=subValue1")));
|
||||
assertThat(string, is(equalTo(@"key1-form-name=value1&relationship1-form-name[r1k1][]=relationship1Value1&relationship1-form-name[r1k1][]=relationship1Value2&key2-form-name=value2&relationship2-form-name[subKey1]=subValue1")));
|
||||
#else
|
||||
assertThat(data, is(equalTo(@"relationship1-form-name[r1k1][]=relationship1Value1&relationship1-form-name[r1k1][]=relationship1Value2&key2-form-name=value2&key1-form-name=value1&relationship2-form-name[subKey1]=subValue1")));
|
||||
assertThat(string, is(equalTo(@"relationship1-form-name[r1k1][]=relationship1Value1&relationship1-form-name[r1k1][]=relationship1Value2&key2-form-name=value2&key1-form-name=value1&relationship2-form-name[subKey1]=subValue1")));
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -151,28 +152,31 @@
|
||||
{
|
||||
NSDictionary *object = [NSDictionary dictionaryWithObjectsAndKeys:@"value1", @"key1", @"value2", @"key2", nil];
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[NSDictionary class]];
|
||||
[mapping addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"key1" toKeyPath:@"key1-form-name"]];
|
||||
[mapping addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"key2" toKeyPath:@"key2-form-name"]];
|
||||
RKObjectSerializer *serializer = [RKObjectSerializer serializerWithObject:object mapping:mapping];
|
||||
NSError *error = nil;
|
||||
id<RKRequestSerializable> serialization = [serializer serializationForMIMEType:@"application/json" error:&error];
|
||||
NSString *data = [[[NSString alloc] initWithData:[serialization HTTPBody] encoding:NSUTF8StringEncoding] autorelease];
|
||||
data = [data stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
||||
[mapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"key1" toKeyPath:@"key1-form-name"]];
|
||||
[mapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"key2" toKeyPath:@"key2-form-name"]];
|
||||
|
||||
NSError *error;
|
||||
RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:mapping objectClass:[NSDictionary class] rootKeyPath:nil];
|
||||
NSDictionary *parameters = [RKObjectParameterization parametersWithObject:object requestDescriptor:requestDescriptor error:&error];
|
||||
|
||||
NSData *data = [RKMIMETypeSerialization dataFromObject:parameters MIMEType:RKMIMETypeJSON error:&error];
|
||||
NSString *string = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
||||
|
||||
assertThat(error, is(nilValue()));
|
||||
assertThat(data, is(equalTo(@"{\"key2-form-name\":\"value2\",\"key1-form-name\":\"value1\"}")));
|
||||
assertThat(string, is(equalTo(@"{\"key2-form-name\":\"value2\",\"key1-form-name\":\"value1\"}")));
|
||||
}
|
||||
|
||||
- (void)testShouldSetReturnNilIfItDoesNotFindAnythingToSerialize
|
||||
{
|
||||
NSDictionary *object = [NSDictionary dictionaryWithObjectsAndKeys:@"value1", @"key1", @"value2", @"key2", nil];
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[NSDictionary class]];
|
||||
[mapping addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"key12123" toKeyPath:@"key1-form-name"]];
|
||||
RKObjectSerializer *serializer = [RKObjectSerializer serializerWithObject:object mapping:mapping];
|
||||
NSError *error = nil;
|
||||
id<RKRequestSerializable> serialization = [serializer serializationForMIMEType:@"application/json" error:&error];
|
||||
[mapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"key12123" toKeyPath:@"key1-form-name"]];
|
||||
|
||||
NSError *error;
|
||||
RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:mapping objectClass:[NSDictionary class] rootKeyPath:nil];
|
||||
NSDictionary *parameters = [RKObjectParameterization parametersWithObject:object requestDescriptor:requestDescriptor error:&error];
|
||||
|
||||
assertThat(serialization, is(nilValue()));
|
||||
assertThat(parameters, is(nilValue()));
|
||||
}
|
||||
|
||||
- (void)testShouldSerializeNestedObjectsContainingDatesToJSON
|
||||
@@ -185,25 +189,23 @@
|
||||
|
||||
// Setup object mappings
|
||||
RKObjectMapping *objectMapping = [RKObjectMapping mappingForClass:[NSMutableDictionary class]];
|
||||
[objectMapping mapAttributes:@"stringTest", nil];
|
||||
[objectMapping addAttributeMappingsFromArray:@[ @"stringTest" ]];
|
||||
RKObjectMapping *relationshipMapping = [RKObjectMapping mappingForClass:[NSMutableDictionary class]];
|
||||
[relationshipMapping mapAttributes:@"date", nil];
|
||||
[objectMapping mapRelationship:@"hasOne" withMapping:relationshipMapping];
|
||||
|
||||
// Serialize
|
||||
RKObjectSerializer *serializer = [RKObjectSerializer serializerWithObject:object mapping:objectMapping];
|
||||
NSError *error = nil;
|
||||
id<RKRequestSerializable> serialization = [serializer serializationForMIMEType:@"application/json" error:&error];
|
||||
assertThat(error, is(nilValue()));
|
||||
|
||||
NSString *data = [[[NSString alloc] initWithData:[serialization HTTPBody] encoding:NSUTF8StringEncoding] autorelease];
|
||||
data = [data stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
||||
[relationshipMapping addAttributeMappingsFromArray:@[ @"date" ]];
|
||||
[objectMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"hasOne" toKeyPath:@"hasOne" withMapping:relationshipMapping]];
|
||||
|
||||
NSError *error;
|
||||
RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:objectMapping objectClass:[NSDictionary class] rootKeyPath:nil];
|
||||
NSDictionary *parameters = [RKObjectParameterization parametersWithObject:object requestDescriptor:requestDescriptor error:&error];
|
||||
|
||||
NSData *data = [RKMIMETypeSerialization dataFromObject:parameters MIMEType:RKMIMETypeJSON error:&error];
|
||||
NSString *string = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
||||
|
||||
// Encodes differently on iOS / OS X
|
||||
#if TARGET_OS_IPHONE
|
||||
assertThat(data, is(equalTo(@"{\"stringTest\":\"The string\",\"hasOne\":{\"date\":\"1970-01-01 00:00:00 +0000\"}}")));
|
||||
assertThat(string, is(equalTo(@"{\"stringTest\":\"The string\",\"hasOne\":{\"date\":\"1970-01-01 00:00:00 +0000\"}}")));
|
||||
#else
|
||||
assertThat(data, is(equalTo(@"{\"hasOne\":{\"date\":\"1970-01-01 00:00:00 +0000\"},\"stringTest\":\"The string\"}")));
|
||||
assertThat(string, is(equalTo(@"{\"hasOne\":{\"date\":\"1970-01-01 00:00:00 +0000\"},\"stringTest\":\"The string\"}")));
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -211,16 +213,15 @@
|
||||
{
|
||||
NSDictionary *object = [NSDictionary dictionaryWithObjectsAndKeys:@"value1", @"key1", @"value2", @"key2", nil];
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[NSDictionary class]];
|
||||
[mapping addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"key1" toKeyPath:@"key1-form-name"]];
|
||||
[mapping addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"key2" toKeyPath:@"key2-form-name"]];
|
||||
RKObjectSerializer *serializer = [[RKObjectSerializer alloc] initWithObject:object mapping:mapping rootKeyPath:@"stuff"];
|
||||
NSError *error = nil;
|
||||
id<RKRequestSerializable> serialization = [serializer serializationForMIMEType:@"application/x-www-form-urlencoded" error:&error];
|
||||
NSString *data = [[[NSString alloc] initWithData:[serialization HTTPBody] encoding:NSUTF8StringEncoding] autorelease];
|
||||
data = [data stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
||||
|
||||
assertThat(error, is(nilValue()));
|
||||
assertThat(data, is(equalTo(@"stuff[key2-form-name]=value2&stuff[key1-form-name]=value1")));
|
||||
[mapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"key1" toKeyPath:@"key1-form-name"]];
|
||||
[mapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"key2" toKeyPath:@"key2-form-name"]];
|
||||
|
||||
NSError *error;
|
||||
RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:mapping objectClass:[NSDictionary class] rootKeyPath:@"stuff"];
|
||||
NSDictionary *parameters = [RKObjectParameterization parametersWithObject:object requestDescriptor:requestDescriptor error:&error];
|
||||
|
||||
assertThat(parameters[@"stuff"][@"key2-form-name"], is(equalTo(@"value2")));
|
||||
assertThat(parameters[@"stuff"][@"key1-form-name"], is(equalTo(@"value1")));
|
||||
}
|
||||
|
||||
- (void)testShouldSerializeToManyRelationships
|
||||
@@ -233,38 +234,36 @@
|
||||
|
||||
// Setup object mappings
|
||||
RKObjectMapping *objectMapping = [RKObjectMapping mappingForClass:[NSMutableDictionary class]];
|
||||
[objectMapping mapAttributes:@"stringTest", nil];
|
||||
[objectMapping addAttributeMappingsFromArray:@[@"stringTest"]];
|
||||
RKObjectMapping *relationshipMapping = [RKObjectMapping mappingForClass:[NSMutableDictionary class]];
|
||||
[relationshipMapping mapAttributes:@"date", nil];
|
||||
[objectMapping mapRelationship:@"hasMany" withMapping:relationshipMapping];
|
||||
[relationshipMapping addAttributeMappingsFromArray:@[@"date"]];
|
||||
[objectMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"hasMany" toKeyPath:@"hasMany" withMapping:relationshipMapping]];
|
||||
|
||||
// Serialize
|
||||
RKObjectSerializer *serializer = [RKObjectSerializer serializerWithObject:object mapping:objectMapping];
|
||||
NSError *error = nil;
|
||||
id<RKRequestSerializable> serialization = [serializer serializationForMIMEType:@"application/json" error:&error];
|
||||
assertThat(error, is(nilValue()));
|
||||
|
||||
NSString *data = [[[NSString alloc] initWithData:[serialization HTTPBody] encoding:NSUTF8StringEncoding] autorelease];
|
||||
data = [data stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
||||
assertThat(data, is(equalTo(@"{\"hasMany\":[{\"date\":\"1970-01-01 00:00:00 +0000\"}],\"stringTest\":\"The string\"}")));
|
||||
NSError *error;
|
||||
RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:objectMapping objectClass:[NSDictionary class] rootKeyPath:nil];
|
||||
NSDictionary *parameters = [RKObjectParameterization parametersWithObject:object requestDescriptor:requestDescriptor error:&error];
|
||||
|
||||
NSData *data = [RKMIMETypeSerialization dataFromObject:parameters MIMEType:RKMIMETypeJSON error:&error];
|
||||
NSString *string = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
||||
assertThat(string, is(equalTo(@"{\"hasMany\":[{\"date\":\"1970-01-01 00:00:00 +0000\"}],\"stringTest\":\"The string\"}")));
|
||||
}
|
||||
|
||||
- (void)testShouldSerializeAnNSNumberContainingABooleanToTrueFalseIfRequested
|
||||
{
|
||||
NSDictionary *object = [NSDictionary dictionaryWithObjectsAndKeys:@"value1", @"key1", [NSNumber numberWithBool:YES], @"boolean", nil];
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[NSDictionary class]];
|
||||
RKAttributeMapping *attributeMapping = [RKAttributeMapping mappingFromKeyPath:@"boolean" toKeyPath:@"boolean-value"];
|
||||
[mapping addAttributeMapping:attributeMapping];
|
||||
RKObjectSerializer *serializer = [RKObjectSerializer serializerWithObject:object mapping:mapping];
|
||||
|
||||
NSError *error = nil;
|
||||
id<RKRequestSerializable> serialization = [serializer serializationForMIMEType:@"application/json" error:&error];
|
||||
|
||||
NSString *data = [[[NSString alloc] initWithData:[serialization HTTPBody] encoding:NSUTF8StringEncoding] autorelease];
|
||||
data = [data stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
||||
RKAttributeMapping *attributeMapping = [RKAttributeMapping attributeMappingFromKeyPath:@"boolean" toKeyPath:@"boolean-value"];
|
||||
[mapping addPropertyMapping:attributeMapping];
|
||||
|
||||
NSError *error;
|
||||
RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:mapping objectClass:[NSDictionary class] rootKeyPath:nil];
|
||||
NSDictionary *parameters = [RKObjectParameterization parametersWithObject:object requestDescriptor:requestDescriptor error:&error];
|
||||
NSData *data = [RKMIMETypeSerialization dataFromObject:parameters MIMEType:RKMIMETypeJSON error:&error];
|
||||
NSString *string = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
||||
|
||||
assertThat(error, is(nilValue()));
|
||||
assertThat(data, is(equalTo(@"{\"boolean-value\":true}")));
|
||||
assertThat(string, is(equalTo(@"{\"boolean-value\":true}")));
|
||||
}
|
||||
|
||||
- (void)testShouldSerializeANSOrderedSetToJSON
|
||||
@@ -273,18 +272,17 @@
|
||||
[NSOrderedSet orderedSetWithObjects:@"setElementOne", @"setElementTwo", @"setElementThree", nil], @"set",
|
||||
nil];
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[NSDictionary class]];
|
||||
[mapping addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"key1" toKeyPath:@"key1-form-name"]];
|
||||
[mapping addAttributeMapping:[RKAttributeMapping mappingFromKeyPath:@"set" toKeyPath:@"set-form-name"]];
|
||||
RKObjectSerializer *serializer = [RKObjectSerializer serializerWithObject:object mapping:mapping];
|
||||
|
||||
NSError *error = nil;
|
||||
id<RKRequestSerializable> serialization = [serializer serializationForMIMEType:@"application/json" error:&error];
|
||||
|
||||
NSString *data = [[[NSString alloc] initWithData:[serialization HTTPBody] encoding:NSUTF8StringEncoding] autorelease];
|
||||
data = [data stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
||||
[mapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"key1" toKeyPath:@"key1-form-name"]];
|
||||
[mapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@"set" toKeyPath:@"set-form-name"]];
|
||||
|
||||
NSError *error;
|
||||
RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:mapping objectClass:[NSDictionary class] rootKeyPath:nil];
|
||||
NSDictionary *parameters = [RKObjectParameterization parametersWithObject:object requestDescriptor:requestDescriptor error:&error];
|
||||
NSData *data = [RKMIMETypeSerialization dataFromObject:parameters MIMEType:RKMIMETypeJSON error:&error];
|
||||
NSString *string = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
||||
|
||||
assertThat(error, is(nilValue()));
|
||||
assertThat(data, is(equalTo(@"{\"key1-form-name\":\"value1\",\"set-form-name\":[\"setElementOne\",\"setElementTwo\",\"setElementThree\"]}")));
|
||||
assertThat(string, is(equalTo(@"{\"key1-form-name\":\"value1\",\"set-form-name\":[\"setElementOne\",\"setElementTwo\",\"setElementThree\"]}")));
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -16,16 +16,16 @@
|
||||
|
||||
- (void)testThatRelationshipMappingsWithTheSameSourceAndDestinationKeyPathAreConsideredEqual
|
||||
{
|
||||
RKRelationshipMapping *mapping1 = [RKRelationshipMapping mappingFromKeyPath:@"this" toKeyPath:@"that" withMapping:nil];
|
||||
RKRelationshipMapping *mapping2 = [RKRelationshipMapping mappingFromKeyPath:@"this" toKeyPath:@"that" withMapping:nil];
|
||||
RKRelationshipMapping *mapping1 = [RKRelationshipMapping relationshipMappingFromKeyPath:@"this" toKeyPath:@"that" withMapping:nil];
|
||||
RKRelationshipMapping *mapping2 = [RKRelationshipMapping relationshipMappingFromKeyPath:@"this" toKeyPath:@"that" withMapping:nil];
|
||||
|
||||
assertThatBool([mapping1 isEqualToMapping:mapping2], is(equalToBool(YES)));
|
||||
}
|
||||
|
||||
- (void)testThatRelationshipMappingsWithDifferingKeyPathsAreNotConsideredEqual
|
||||
{
|
||||
RKRelationshipMapping *mapping1 = [RKRelationshipMapping mappingFromKeyPath:@"this" toKeyPath:@"that" withMapping:nil];
|
||||
RKRelationshipMapping *mapping2 = [RKRelationshipMapping mappingFromKeyPath:@"this" toKeyPath:@"the other" withMapping:nil];
|
||||
RKRelationshipMapping *mapping1 = [RKRelationshipMapping relationshipMappingFromKeyPath:@"this" toKeyPath:@"that" withMapping:nil];
|
||||
RKRelationshipMapping *mapping2 = [RKRelationshipMapping relationshipMappingFromKeyPath:@"this" toKeyPath:@"the other" withMapping:nil];
|
||||
|
||||
assertThatBool([mapping1 isEqualToMapping:mapping2], is(equalToBool(NO)));
|
||||
}
|
||||
@@ -35,8 +35,8 @@
|
||||
RKObjectMapping *relationshipMapping1 = [RKObjectMapping mappingForClass:[NSSet class]];
|
||||
RKObjectMapping *relationshipMapping2 = [RKObjectMapping mappingForClass:[NSSet class]];
|
||||
|
||||
RKRelationshipMapping *mapping1 = [RKRelationshipMapping mappingFromKeyPath:@"this" toKeyPath:@"that" withMapping:relationshipMapping1];
|
||||
RKRelationshipMapping *mapping2 = [RKRelationshipMapping mappingFromKeyPath:@"this" toKeyPath:@"that" withMapping:relationshipMapping2];
|
||||
RKRelationshipMapping *mapping1 = [RKRelationshipMapping relationshipMappingFromKeyPath:@"this" toKeyPath:@"that" withMapping:relationshipMapping1];
|
||||
RKRelationshipMapping *mapping2 = [RKRelationshipMapping relationshipMappingFromKeyPath:@"this" toKeyPath:@"that" withMapping:relationshipMapping2];
|
||||
|
||||
assertThatBool([mapping1 isEqualToMapping:mapping2], is(equalToBool(YES)));
|
||||
}
|
||||
@@ -46,8 +46,8 @@
|
||||
RKObjectMapping *relationshipMapping1 = [RKObjectMapping mappingForClass:[NSSet class]];
|
||||
RKObjectMapping *relationshipMapping2 = [RKObjectMapping mappingForClass:[NSNumber class]];
|
||||
|
||||
RKRelationshipMapping *mapping1 = [RKRelationshipMapping mappingFromKeyPath:@"this" toKeyPath:@"that" withMapping:relationshipMapping1];
|
||||
RKRelationshipMapping *mapping2 = [RKRelationshipMapping mappingFromKeyPath:@"this" toKeyPath:@"that" withMapping:relationshipMapping2];
|
||||
RKRelationshipMapping *mapping1 = [RKRelationshipMapping relationshipMappingFromKeyPath:@"this" toKeyPath:@"that" withMapping:relationshipMapping1];
|
||||
RKRelationshipMapping *mapping2 = [RKRelationshipMapping relationshipMappingFromKeyPath:@"this" toKeyPath:@"that" withMapping:relationshipMapping2];
|
||||
|
||||
assertThatBool([mapping1 isEqualToMapping:mapping2], is(equalToBool(NO)));
|
||||
}
|
||||
@@ -57,8 +57,8 @@
|
||||
RKObjectMapping *relationshipMapping1 = [RKObjectMapping mappingForClass:[NSSet class]];
|
||||
RKObjectMapping *relationshipMapping2 = [RKObjectMapping mappingForClass:nil];
|
||||
|
||||
RKRelationshipMapping *mapping1 = [RKRelationshipMapping mappingFromKeyPath:@"this" toKeyPath:@"that" withMapping:relationshipMapping1];
|
||||
RKRelationshipMapping *mapping2 = [RKRelationshipMapping mappingFromKeyPath:@"this" toKeyPath:@"that" withMapping:relationshipMapping2];
|
||||
RKRelationshipMapping *mapping1 = [RKRelationshipMapping relationshipMappingFromKeyPath:@"this" toKeyPath:@"that" withMapping:relationshipMapping1];
|
||||
RKRelationshipMapping *mapping2 = [RKRelationshipMapping relationshipMappingFromKeyPath:@"this" toKeyPath:@"that" withMapping:relationshipMapping2];
|
||||
|
||||
assertThatBool([mapping1 isEqualToMapping:mapping2], is(equalToBool(NO)));
|
||||
}
|
||||
@@ -68,8 +68,8 @@
|
||||
RKObjectMapping *relationshipMapping1 = [RKObjectMapping mappingForClass:nil];
|
||||
RKObjectMapping *relationshipMapping2 = [RKObjectMapping mappingForClass:nil];
|
||||
|
||||
RKRelationshipMapping *mapping1 = [RKRelationshipMapping mappingFromKeyPath:@"this" toKeyPath:@"that" withMapping:relationshipMapping1];
|
||||
RKRelationshipMapping *mapping2 = [RKRelationshipMapping mappingFromKeyPath:@"this" toKeyPath:@"that" withMapping:relationshipMapping2];
|
||||
RKRelationshipMapping *mapping1 = [RKRelationshipMapping relationshipMappingFromKeyPath:@"this" toKeyPath:@"that" withMapping:relationshipMapping1];
|
||||
RKRelationshipMapping *mapping2 = [RKRelationshipMapping relationshipMappingFromKeyPath:@"this" toKeyPath:@"that" withMapping:relationshipMapping2];
|
||||
|
||||
assertThatBool([mapping1 isEqualToMapping:mapping2], is(equalToBool(YES)));
|
||||
}
|
||||
|
||||
@@ -19,76 +19,89 @@
|
||||
//
|
||||
|
||||
#import "RKTestEnvironment.h"
|
||||
#import "RKParserRegistry.h"
|
||||
#import "RKJSONParserJSONKit.h"
|
||||
#import "RKXMLParserXMLReader.h"
|
||||
#import "RKMIMETypeSerialization.h"
|
||||
#import "RKNSJSONSerialization.h"
|
||||
|
||||
@interface RKParserRegistryTest : RKTestCase {
|
||||
@interface RKMIMETypeSerialization ()
|
||||
@property (nonatomic, strong) NSMutableArray *registrations;
|
||||
|
||||
+ (RKMIMETypeSerialization *)sharedSerialization;
|
||||
- (void)addRegistrationsForKnownSerializations;
|
||||
@end
|
||||
|
||||
@interface RKParserRegistryTest : RKTestCase
|
||||
@end
|
||||
|
||||
@interface RKTestSerialization : NSObject <RKSerialization>
|
||||
@end
|
||||
|
||||
@implementation RKTestSerialization
|
||||
|
||||
+ (id)objectFromData:(NSData *)data error:(NSError **)error
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
+ (NSData *)dataFromObject:(id)object error:(NSError **)error
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation RKParserRegistryTest
|
||||
|
||||
- (void)testShouldEnableRegistrationFromMIMETypeToParserClasses
|
||||
- (void)setUp
|
||||
{
|
||||
RKParserRegistry *registry = [[RKParserRegistry new] autorelease];
|
||||
[registry setParserClass:[RKJSONParserJSONKit class] forMIMEType:RKMIMETypeJSON];
|
||||
Class parserClass = [registry parserClassForMIMEType:RKMIMETypeJSON];
|
||||
assertThat(NSStringFromClass(parserClass), is(equalTo(@"RKJSONParserJSONKit")));
|
||||
[RKMIMETypeSerialization sharedSerialization].registrations = [NSMutableArray array];
|
||||
}
|
||||
|
||||
- (void)testShouldInstantiateParserObjects
|
||||
- (void)testShouldEnableRegistrationFromMIMETypeToParserClasses
|
||||
{
|
||||
RKParserRegistry *registry = [[RKParserRegistry new] autorelease];
|
||||
[registry setParserClass:[RKJSONParserJSONKit class] forMIMEType:RKMIMETypeJSON];
|
||||
id<RKSerialization> parser = [registry parserForMIMEType:RKMIMETypeJSON];
|
||||
assertThat(parser, is(instanceOf([RKJSONParserJSONKit class])));
|
||||
[RKMIMETypeSerialization registerClass:[RKNSJSONSerialization class] forMIMEType:RKMIMETypeJSON];
|
||||
Class parserClass = [RKMIMETypeSerialization serializationClassForMIMEType:RKMIMETypeJSON];
|
||||
assertThat(NSStringFromClass(parserClass), is(equalTo(@"RKNSJSONSerialization")));
|
||||
}
|
||||
|
||||
- (void)testShouldAutoconfigureBasedOnReflection
|
||||
{
|
||||
RKParserRegistry *registry = [[RKParserRegistry new] autorelease];
|
||||
[registry autoconfigure];
|
||||
id<RKSerialization> parser = [registry parserForMIMEType:RKMIMETypeJSON];
|
||||
assertThat(parser, is(instanceOf([RKJSONParserJSONKit class])));
|
||||
parser = [registry parserForMIMEType:RKMIMETypeXML];
|
||||
assertThat(parser, is(instanceOf([RKXMLParserXMLReader class])));
|
||||
[[RKMIMETypeSerialization sharedSerialization] addRegistrationsForKnownSerializations];
|
||||
Class parserClass = [RKMIMETypeSerialization serializationClassForMIMEType:RKMIMETypeJSON];
|
||||
assertThat(NSStringFromClass(parserClass), is(equalTo(@"RKNSJSONSerialization")));
|
||||
}
|
||||
|
||||
- (void)testRetrievalOfExactStringMatchForMIMEType
|
||||
{
|
||||
RKParserRegistry *registry = [[RKParserRegistry new] autorelease];
|
||||
[registry setParserClass:[RKJSONParserJSONKit class] forMIMEType:RKMIMETypeJSON];
|
||||
id<RKSerialization> parser = [registry parserForMIMEType:RKMIMETypeJSON];
|
||||
assertThat(parser, is(instanceOf([RKJSONParserJSONKit class])));
|
||||
[RKMIMETypeSerialization registerClass:[RKNSJSONSerialization class] forMIMEType:RKMIMETypeJSON];
|
||||
Class parserClass = [RKMIMETypeSerialization serializationClassForMIMEType:RKMIMETypeJSON];
|
||||
assertThat(NSStringFromClass(parserClass), is(equalTo(@"RKNSJSONSerialization")));
|
||||
}
|
||||
|
||||
- (void)testRetrievalOfRegularExpressionMatchForMIMEType
|
||||
{
|
||||
RKParserRegistry *registry = [[RKParserRegistry new] autorelease];
|
||||
NSError *error = nil;
|
||||
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"application/xml\\+\\w+" options:0 error:&error];
|
||||
[registry setParserClass:[RKJSONParserJSONKit class] forMIMETypeRegularExpression:regex];
|
||||
id<RKSerialization> parser = [registry parserForMIMEType:@"application/xml+whatever"];
|
||||
assertThat(parser, is(instanceOf([RKJSONParserJSONKit class])));
|
||||
|
||||
[RKMIMETypeSerialization registerClass:[RKNSJSONSerialization class] forMIMEType:regex];
|
||||
Class serializationClass = [RKMIMETypeSerialization serializationClassForMIMEType:@"application/xml+whatever"];
|
||||
assertThat(NSStringFromClass(serializationClass), is(equalTo(@"RKNSJSONSerialization")));
|
||||
}
|
||||
|
||||
- (void)testRetrievalOfExactStringMatchIsFavoredOverRegularExpression
|
||||
{
|
||||
RKParserRegistry *registry = [[RKParserRegistry new] autorelease];
|
||||
NSError *error = nil;
|
||||
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"application/xml\\+\\w+" options:0 error:&error];
|
||||
[registry setParserClass:[RKJSONParserJSONKit class] forMIMETypeRegularExpression:regex];
|
||||
[registry setParserClass:[RKXMLParserXMLReader class] forMIMEType:@"application/xml+whatever"];
|
||||
|
||||
[RKMIMETypeSerialization registerClass:[RKNSJSONSerialization class] forMIMEType:regex];
|
||||
[RKMIMETypeSerialization registerClass:[RKTestSerialization class] forMIMEType:@"application/xml+whatever"];
|
||||
|
||||
// Exact match
|
||||
id<RKSerialization> exactParser = [registry parserForMIMEType:@"application/xml+whatever"];
|
||||
assertThat(exactParser, is(instanceOf([RKXMLParserXMLReader class])));
|
||||
Class exactMatch = [RKMIMETypeSerialization serializationClassForMIMEType:@"application/xml+whatever"];
|
||||
assertThat(exactMatch, is(equalTo([RKTestSerialization class])));
|
||||
|
||||
// Fallback to regex
|
||||
id<RKSerialization> regexParser = [registry parserForMIMEType:@"application/xml+different"];
|
||||
assertThat(regexParser, is(instanceOf([RKJSONParserJSONKit class])));
|
||||
Class regexMatch = [RKMIMETypeSerialization serializationClassForMIMEType:@"application/xml+different"];
|
||||
assertThat(regexMatch, is(equalTo([RKNSJSONSerialization class])));
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
//
|
||||
// NSArray+RKAdditionsTest.m
|
||||
// RestKit
|
||||
//
|
||||
// Created by Blake Watters on 4/10/12.
|
||||
// Copyright (c) 2012 RestKit. All rights reserved.
|
||||
//
|
||||
|
||||
#import "RKTestEnvironment.h"
|
||||
#import "NSArray+RKAdditions.h"
|
||||
#import "RKTestUser.h"
|
||||
|
||||
@interface NSArray_RKAdditionsTest : RKTestCase
|
||||
@end
|
||||
|
||||
@implementation NSArray_RKAdditionsTest
|
||||
|
||||
#pragma mark - sectionsGroupedByKeyPath Tests
|
||||
|
||||
- (void)testReturnsEmptyArrayWhenGroupingEmptyArray
|
||||
{
|
||||
NSArray *objects = [NSArray array];
|
||||
assertThat([objects sectionsGroupedByKeyPath:@"whatever"], is(empty()));
|
||||
}
|
||||
|
||||
- (void)testReturnsSingleSectionWhenGroupingSingleObject
|
||||
{
|
||||
RKTestUser *user = [RKTestUser new];
|
||||
user.name = @"Blake";
|
||||
user.country = @"USA";
|
||||
NSArray *users = [NSArray arrayWithObject:user];
|
||||
|
||||
NSArray *sections = [users sectionsGroupedByKeyPath:@"country"];
|
||||
assertThat(sections, hasCountOf(1));
|
||||
}
|
||||
|
||||
- (void)testReturnsTwoSectionsWhenGroupingThreeObjectsWithTwoUniqueValues
|
||||
{
|
||||
RKTestUser *user1 = [RKTestUser new];
|
||||
user1.name = @"Blake";
|
||||
user1.country = @"USA";
|
||||
|
||||
RKTestUser *user2 = [RKTestUser new];
|
||||
user2.name = @"Colin";
|
||||
user2.country = @"USA";
|
||||
|
||||
RKTestUser *user3 = [RKTestUser new];
|
||||
user3.name = @"Pepe";
|
||||
user3.country = @"Spain";
|
||||
|
||||
NSArray *users = [NSArray arrayWithObjects:user1, user2, user3, nil];
|
||||
|
||||
NSArray *sections = [users sectionsGroupedByKeyPath:@"country"];
|
||||
assertThat(sections, hasCountOf(2));
|
||||
assertThat([sections objectAtIndex:0], contains(user1, user2, nil));
|
||||
assertThat([sections objectAtIndex:1], contains(user3, nil));
|
||||
}
|
||||
|
||||
- (void)testCreationOfSingleSectionForNullValues
|
||||
{
|
||||
RKTestUser *user1 = [RKTestUser new];
|
||||
user1.name = @"Blake";
|
||||
user1.country = @"USA";
|
||||
|
||||
RKTestUser *user2 = [RKTestUser new];
|
||||
user2.name = @"Expatriate";
|
||||
user2.country = nil;
|
||||
|
||||
RKTestUser *user3 = [RKTestUser new];
|
||||
user3.name = @"John Doe";
|
||||
user3.country = nil;
|
||||
|
||||
RKTestUser *user4 = [RKTestUser new];
|
||||
user4.name = @"Pepe";
|
||||
user4.country = @"Spain";
|
||||
|
||||
NSArray *users = [NSArray arrayWithObjects:user1, user2, user3, user4, nil];
|
||||
|
||||
NSArray *sections = [users sectionsGroupedByKeyPath:@"country"];
|
||||
assertThat(sections, hasCountOf(3));
|
||||
assertThat([sections objectAtIndex:0], contains(user1, nil));
|
||||
assertThat([sections objectAtIndex:1], contains(user2, user3, nil));
|
||||
assertThat([sections objectAtIndex:2], contains(user4, nil));
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -19,29 +19,22 @@
|
||||
//
|
||||
|
||||
#import "RKTestEnvironment.h"
|
||||
#import "NSDictionary+RKRequestSerialization.h"
|
||||
#import "NSDictionary+RKAdditions.h"
|
||||
#import "RKURLEncodedSerialization.h"
|
||||
|
||||
@interface NSDictionary_RKRequestSerializationTest : RKTestCase {
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
// TODO: Moves to RKURLEncodedSerializationTest.m
|
||||
@implementation NSDictionary_RKRequestSerializationTest
|
||||
|
||||
- (void)testShouldHaveKeysAndValuesDictionaryInitializer
|
||||
{
|
||||
NSDictionary *dictionary1 = [NSDictionary dictionaryWithObjectsAndKeys:@"value", @"key", @"value2", @"key2", nil];
|
||||
NSDictionary *dictionary2 = [NSDictionary dictionaryWithKeysAndObjects:@"key", @"value", @"key2", @"value2", nil];
|
||||
assertThat(dictionary2, is(equalTo(dictionary1)));
|
||||
}
|
||||
|
||||
- (void)testShouldEncodeUnicodeStrings
|
||||
{
|
||||
NSString *unicode = [NSString stringWithFormat:@"%CNo ser ni%Co, ser b%Cfalo%C%C", (unichar)0x00A1, (unichar)0x00F1, (unichar)0x00FA, (unichar)0x2026, (unichar)0x0021];
|
||||
NSDictionary *dictionary = [NSDictionary dictionaryWithObject:unicode forKey:@"utf8"];
|
||||
NSString *validUnicode = @"utf8=%C2%A1No%20ser%20ni%C3%B1o%2C%20ser%20b%C3%BAfalo%E2%80%A6%21";
|
||||
assertThat([dictionary stringWithURLEncodedEntries], is(equalTo(validUnicode)));
|
||||
assertThat(RKURLEncodedStringFromDictionaryWithEncoding(dictionary, NSUTF8StringEncoding), is(equalTo(validUnicode)));
|
||||
}
|
||||
|
||||
- (void)testShouldEncodeURLStrings
|
||||
@@ -49,7 +42,7 @@
|
||||
NSString *url = @"http://some.server.com/path/action?subject=\"That thing I sent\"&email=\"me@me.com\"";
|
||||
NSDictionary *dictionary = [NSDictionary dictionaryWithObject:url forKey:@"url"];
|
||||
NSString *validURL = @"url=http%3A%2F%2Fsome.server.com%2Fpath%2Faction%3Fsubject%3D%22That%20thing%20I%20sent%22%26email%3D%22me%40me.com%22";
|
||||
assertThat([dictionary stringWithURLEncodedEntries], is(equalTo(validURL)));
|
||||
assertThat(RKURLEncodedStringFromDictionaryWithEncoding(dictionary, NSUTF8StringEncoding), is(equalTo(validURL)));
|
||||
}
|
||||
|
||||
- (void)testShouldEncodeArrays
|
||||
@@ -57,7 +50,7 @@
|
||||
NSArray *array = [NSArray arrayWithObjects:@"item1", @"item2", nil];
|
||||
NSDictionary *dictionary = [NSDictionary dictionaryWithObject:array forKey:@"anArray"];
|
||||
NSString *validArray = @"anArray[]=item1&anArray[]=item2";
|
||||
assertThat([dictionary stringWithURLEncodedEntries], is(equalTo(validArray)));
|
||||
assertThat(RKURLEncodedStringFromDictionaryWithEncoding(dictionary, NSUTF8StringEncoding), is(equalTo(validArray)));
|
||||
}
|
||||
|
||||
- (void)testShouldEncodeDictionaries
|
||||
@@ -65,19 +58,19 @@
|
||||
NSDictionary *subDictionary = [NSDictionary dictionaryWithObject:@"value1" forKey:@"key1"];
|
||||
NSDictionary *dictionary = [NSDictionary dictionaryWithObject:subDictionary forKey:@"aDictionary"];
|
||||
NSString *validDictionary = @"aDictionary[key1]=value1";
|
||||
assertThat([dictionary stringWithURLEncodedEntries], is(equalTo(validDictionary)));
|
||||
assertThat(RKURLEncodedStringFromDictionaryWithEncoding(dictionary, NSUTF8StringEncoding), is(equalTo(validDictionary)));
|
||||
}
|
||||
|
||||
- (void)testShouldEncodeArrayOfDictionaries
|
||||
{
|
||||
NSDictionary *dictA = [NSDictionary dictionaryWithKeysAndObjects:@"a", @"x", @"b", @"y", nil];
|
||||
NSDictionary *dictB = [NSDictionary dictionaryWithKeysAndObjects:@"a", @"1", @"b", @"2", nil];
|
||||
NSDictionary *dictA = @{@"a": @"x", @"b": @"y"};
|
||||
NSDictionary *dictB = @{@"a": @"1", @"b": @"2"};
|
||||
|
||||
NSArray *array = [NSArray arrayWithObjects:dictA, dictB, nil];
|
||||
NSDictionary *dictRoot = [NSDictionary dictionaryWithKeysAndObjects:@"root", array, nil];
|
||||
NSDictionary *dictRoot = @{@"root" : array};
|
||||
|
||||
NSString *validString = @"root[][a]=x&root[][b]=y&root[][a]=1&root[][b]=2";
|
||||
assertThat([dictRoot stringWithURLEncodedEntries], is(equalTo(validString)));
|
||||
assertThat(RKURLEncodedStringFromDictionaryWithEncoding(dictRoot, NSUTF8StringEncoding), is(equalTo(validString)));
|
||||
}
|
||||
|
||||
- (void)testShouldEncodeRecursiveArrays
|
||||
@@ -87,7 +80,7 @@
|
||||
NSArray *recursiveArray1 = [NSArray arrayWithObject:recursiveArray2];
|
||||
NSDictionary *dictionary = [NSDictionary dictionaryWithObject:recursiveArray1 forKey:@"recursiveArray"];
|
||||
NSString *validRecursion = @"recursiveArray[]=%28%0A%20%20%20%20%20%20%20%20%28%0A%20%20%20%20%20%20%20%20item1%2C%0A%20%20%20%20%20%20%20%20item2%0A%20%20%20%20%29%0A%29";
|
||||
assertThat([dictionary stringWithURLEncodedEntries], is(equalTo(validRecursion)));
|
||||
assertThat(RKURLEncodedStringFromDictionaryWithEncoding(dictionary, NSUTF8StringEncoding), is(equalTo(validRecursion)));
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -19,8 +19,9 @@
|
||||
//
|
||||
|
||||
#import "RKTestEnvironment.h"
|
||||
#import "NSString+RKAdditions.h"
|
||||
#import "RKPathUtilities.h"
|
||||
#import "RKObjectMapperTestModel.h"
|
||||
#import "RKURLEncodedSerialization.h"
|
||||
|
||||
@interface NSStringRestKitTest : RKTestCase
|
||||
|
||||
@@ -28,27 +29,12 @@
|
||||
|
||||
@implementation NSStringRestKitTest
|
||||
|
||||
- (void)testShouldAppendQueryParameters
|
||||
{
|
||||
NSString *resourcePath = @"/controller/objects/";
|
||||
NSDictionary *queryParams = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
@"ascend", @"sortOrder",
|
||||
@"name", @"groupBy", nil];
|
||||
NSString *resultingPath = [resourcePath stringByAppendingQueryParameters:queryParams];
|
||||
assertThat(resultingPath, isNot(equalTo(nil)));
|
||||
NSString *expectedPath1 = @"/controller/objects/?sortOrder=ascend&groupBy=name";
|
||||
NSString *expectedPath2 = @"/controller/objects/?groupBy=name&sortOrder=ascend";
|
||||
BOOL isValidPath = ( [resultingPath isEqualToString:expectedPath1] ||
|
||||
[resultingPath isEqualToString:expectedPath2] );
|
||||
assertThatBool(isValidPath, is(equalToBool(YES)));
|
||||
}
|
||||
|
||||
- (void)testShouldInterpolateObjects
|
||||
{
|
||||
RKObjectMapperTestModel *person = [[[RKObjectMapperTestModel alloc] init] autorelease];
|
||||
person.name = @"CuddleGuts";
|
||||
person.age = [NSNumber numberWithInt:6];
|
||||
NSString *interpolatedPath = [@"/people/:name/:age" interpolateWithObject:person];
|
||||
NSString *interpolatedPath = RKPathFromPatternWithObject(@"/people/:name/:age", person);
|
||||
assertThat(interpolatedPath, isNot(equalTo(nil)));
|
||||
NSString *expectedPath = @"/people/CuddleGuts/6";
|
||||
assertThat(interpolatedPath, is(equalTo(expectedPath)));
|
||||
@@ -59,39 +45,32 @@
|
||||
RKObjectMapperTestModel *person = [[[RKObjectMapperTestModel alloc] init] autorelease];
|
||||
person.name = @"CuddleGuts";
|
||||
person.age = [NSNumber numberWithInt:6];
|
||||
NSString *interpolatedPath = [@"/people/(name)/(age)" interpolateWithObject:person];
|
||||
NSString *interpolatedPath = RKPathFromPatternWithObject(@"/people/(name)/(age)", person);
|
||||
assertThat(interpolatedPath, isNot(equalTo(nil)));
|
||||
NSString *expectedPath = @"/people/CuddleGuts/6";
|
||||
assertThat(interpolatedPath, is(equalTo(expectedPath)));
|
||||
}
|
||||
|
||||
// TODO: Moves to RKURLEncodedSerializationTest.m
|
||||
- (void)testShouldParseQueryParameters
|
||||
{
|
||||
NSString *resourcePath = @"/views/thing/?keyA=valA&keyB=valB";
|
||||
NSDictionary *queryParams = [resourcePath queryParametersUsingEncoding:NSASCIIStringEncoding];
|
||||
assertThat(queryParams, isNot(empty()));
|
||||
assertThat(queryParams, hasCountOf(2));
|
||||
assertThat(queryParams, hasEntries(@"keyA", @"valA", @"keyB", @"valB", nil));
|
||||
NSDictionary *queryParameters = RKDictionaryFromURLEncodedStringWithEncoding(resourcePath, NSUTF8StringEncoding);
|
||||
assertThat(queryParameters, isNot(empty()));
|
||||
assertThat(queryParameters, hasCountOf(2));
|
||||
assertThat(queryParameters, hasEntries(@"keyA", @"valA", @"keyB", @"valB", nil));
|
||||
}
|
||||
|
||||
- (void)testReturningTheMIMETypeForAPathWithXMLExtension
|
||||
{
|
||||
NSString *MIMEType = [@"/path/to/file.xml" MIMETypeForPathExtension];
|
||||
NSString *MIMEType = RKMIMETypeFromPathExtension(@"/path/to/file.xml");
|
||||
assertThat(MIMEType, is(equalTo(@"application/xml")));
|
||||
}
|
||||
|
||||
- (void)testReturningTheMIMETypeForAPathWithJSONExtension
|
||||
{
|
||||
NSString *MIMEType = [@"/path/to/file.json" MIMETypeForPathExtension];
|
||||
NSString *MIMEType = RKMIMETypeFromPathExtension(@"/path/to/file.json");
|
||||
assertThat(MIMEType, is(equalTo(@"application/json")));
|
||||
}
|
||||
|
||||
- (void)testShouldKnowIfTheReceiverContainsAnIPAddress
|
||||
{
|
||||
assertThatBool([@"127.0.0.1" isIPAddress], equalToBool(YES));
|
||||
assertThatBool([@"173.45.234.197" isIPAddress], equalToBool(YES));
|
||||
assertThatBool([@"google.com" isIPAddress], equalToBool(NO));
|
||||
assertThatBool([@"just some random text" isIPAddress], equalToBool(NO));
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -17,13 +17,12 @@
|
||||
|
||||
- (void)testShouldInstantiateAFormatterWithDefaultGMTTimeZone
|
||||
{
|
||||
RKDotNetDateFormatter *formatter = [RKDotNetDateFormatter dotNetDateFormatter];
|
||||
RKDotNetDateFormatter *formatter = [RKDotNetDateFormatter new];
|
||||
NSTimeZone *timeZone = [NSTimeZone timeZoneWithAbbreviation:@"UTC"];
|
||||
assertThat(formatter, isNot(equalTo(nil)));
|
||||
assertThat(formatter.timeZone, is(equalTo(timeZone)));
|
||||
}
|
||||
|
||||
|
||||
- (void)testShouldInstantiateAFormatterWithATimeZone
|
||||
{
|
||||
NSTimeZone *timeZoneCST = [NSTimeZone timeZoneWithAbbreviation:@"CST"];
|
||||
@@ -35,7 +34,7 @@
|
||||
- (void)testShouldCreateADateFromDotNetThatWithAnOffset
|
||||
{
|
||||
NSString *dotNetString = @"/Date(1000212360000-0400)/";
|
||||
RKDotNetDateFormatter *formatter = [RKDotNetDateFormatter dotNetDateFormatter];
|
||||
RKDotNetDateFormatter *formatter = [RKDotNetDateFormatter new];
|
||||
NSDate *date = [formatter dateFromString:dotNetString];
|
||||
assertThat([date description], is(equalTo(@"2001-09-11 12:46:00 +0000")));
|
||||
}
|
||||
@@ -43,7 +42,7 @@
|
||||
- (void)testShouldCreateADateFromDotNetWithoutAnOffset
|
||||
{
|
||||
NSString *dotNetString = @"/Date(1112715000000)/";
|
||||
RKDotNetDateFormatter *formatter = [RKDotNetDateFormatter dotNetDateFormatter];
|
||||
RKDotNetDateFormatter *formatter = [RKDotNetDateFormatter new];
|
||||
NSDate *date = [formatter dateFromString:dotNetString];
|
||||
assertThat([date description], is(equalTo(@"2005-04-05 15:30:00 +0000")));
|
||||
}
|
||||
@@ -51,14 +50,14 @@
|
||||
- (void)testShouldCreateADateFromDotNetBefore1970WithoutAnOffset
|
||||
{
|
||||
NSString *dotNetString = @"/Date(-864000000000)/";
|
||||
RKDotNetDateFormatter *formatter = [RKDotNetDateFormatter dotNetDateFormatter];
|
||||
RKDotNetDateFormatter *formatter = [RKDotNetDateFormatter new];
|
||||
NSDate *date = [formatter dateFromString:dotNetString];
|
||||
assertThat([date description], is(equalTo(@"1942-08-16 00:00:00 +0000")));
|
||||
}
|
||||
|
||||
- (void)testShouldFailToCreateADateFromInvalidStrings
|
||||
{
|
||||
RKDotNetDateFormatter *formatter = [RKDotNetDateFormatter dotNetDateFormatter];
|
||||
RKDotNetDateFormatter *formatter = [RKDotNetDateFormatter new];
|
||||
NSDate *date = [formatter dateFromString:nil];
|
||||
assertThat(date, is(equalTo(nil)));
|
||||
date = [formatter dateFromString:@"(null)"];
|
||||
@@ -79,7 +78,7 @@
|
||||
|
||||
- (void)testShouldCreateADotNetStringFromADateBefore1970WithoutAnOffset
|
||||
{
|
||||
RKDotNetDateFormatter *formatter = [RKDotNetDateFormatter dotNetDateFormatter];
|
||||
RKDotNetDateFormatter *formatter = [RKDotNetDateFormatter new];
|
||||
NSDate *referenceDate = [NSDate dateWithTimeIntervalSince1970:-1000212360];
|
||||
NSString *string = [formatter stringFromDate:referenceDate];
|
||||
assertThat(string, is(equalTo(@"/Date(-1000212360000+0000)/")));
|
||||
@@ -87,7 +86,7 @@
|
||||
|
||||
- (void)testShouldCreateADateWithGetObjectValueForString
|
||||
{
|
||||
RKDotNetDateFormatter *formatter = [RKDotNetDateFormatter dotNetDateFormatter];
|
||||
RKDotNetDateFormatter *formatter = [RKDotNetDateFormatter new];
|
||||
NSString *dotNetString = @"/Date(1000212360000-0400)/";
|
||||
|
||||
NSDate *date = nil;
|
||||
@@ -108,7 +107,7 @@
|
||||
}
|
||||
|
||||
- (void)testShouldCreateADotNetStringWithStringForObjectValueFromADateBefore1970WithoutAnOffset {
|
||||
RKDotNetDateFormatter *formatter = [RKDotNetDateFormatter dotNetDateFormatter];
|
||||
RKDotNetDateFormatter *formatter = [RKDotNetDateFormatter new];
|
||||
NSDate *referenceDate = [NSDate dateWithTimeIntervalSince1970:-1000212360];
|
||||
NSString *string = [formatter stringForObjectValue:referenceDate];
|
||||
assertThat(string, is(equalTo(@"/Date(-1000212360000+0000)/")));
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
//
|
||||
// RKJSONParserJSONKitTest.m
|
||||
// RestKit
|
||||
//
|
||||
// Created by Blake Watters on 7/6/11.
|
||||
// Copyright (c) 2009-2012 RestKit. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
#import "RKTestEnvironment.h"
|
||||
#import "RKJSONParserJSONKit.h"
|
||||
|
||||
@interface RKJSONParserJSONKitTest : RKTestCase
|
||||
|
||||
@end
|
||||
|
||||
@implementation RKJSONParserJSONKitTest
|
||||
|
||||
- (void)testShouldParseEmptyResults
|
||||
{
|
||||
NSError *error = nil;
|
||||
RKJSONParserJSONKit *parser = [[RKJSONParserJSONKit new] autorelease];
|
||||
id parsingResult = [parser objectFromString:nil error:&error];
|
||||
assertThat(parsingResult, is(equalTo(nil)));
|
||||
assertThat(error, is(equalTo(nil)));
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,40 +0,0 @@
|
||||
//
|
||||
// RKMutableBlockDictionaryTest.m
|
||||
// RestKit
|
||||
//
|
||||
// Created by Blake Watters on 8/22/11.
|
||||
// Copyright (c) 2009-2012 RestKit. All rights reserved.
|
||||
//
|
||||
|
||||
#import "RKTestEnvironment.h"
|
||||
#import "RKMutableBlockDictionary.h"
|
||||
|
||||
@interface RKMutableBlockDictionaryTest : RKTestCase
|
||||
|
||||
@end
|
||||
|
||||
@implementation RKMutableBlockDictionaryTest
|
||||
|
||||
- (void)testLetYouAssignABlockToTheDictionary
|
||||
{
|
||||
RKMutableBlockDictionary *blockDictionary = [[RKMutableBlockDictionary new] autorelease];
|
||||
[blockDictionary setValueWithBlock:^id{ return @"Value from the block!"; } forKey:@"theKey"];
|
||||
assertThat([blockDictionary valueForKey:@"theKey"], is(equalTo(@"Value from the block!")));
|
||||
}
|
||||
|
||||
- (void)testLetYouUseKVC
|
||||
{
|
||||
RKMutableBlockDictionary *blockDictionary = [[RKMutableBlockDictionary new] autorelease];
|
||||
[blockDictionary setValue:@"a value" forKey:@"a key"];
|
||||
assertThat([blockDictionary valueForKey:@"a key"], is(equalTo(@"a value")));
|
||||
}
|
||||
|
||||
- (void)testLetYouAccessABlockValueUsingAKeyPath
|
||||
{
|
||||
RKMutableBlockDictionary *blockDictionary = [[RKMutableBlockDictionary new] autorelease];
|
||||
[blockDictionary setValueWithBlock:^id{ return @"Value from the block!"; } forKey:@"theKey"];
|
||||
NSDictionary *otherDictionary = [NSDictionary dictionaryWithObject:blockDictionary forKey:@"dictionary"];
|
||||
assertThat([otherDictionary valueForKeyPath:@"dictionary.theKey"], is(equalTo(@"Value from the block!")));
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -93,7 +93,7 @@
|
||||
NSDictionary *person = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
@"CuddleGuts", @"name", [NSNumber numberWithInt:6], @"age", nil];
|
||||
RKPathMatcher *matcher = [RKPathMatcher matcherWithPattern:@"/people/:name/:age"];
|
||||
NSString *interpolatedPath = [matcher pathFromObject:person];
|
||||
NSString *interpolatedPath = [matcher pathFromObject:person addingEscapes:YES];
|
||||
assertThat(interpolatedPath, isNot(equalTo(nil)));
|
||||
NSString *expectedPath = @"/people/CuddleGuts/6";
|
||||
assertThat(interpolatedPath, is(equalTo(expectedPath)));
|
||||
@@ -104,7 +104,7 @@
|
||||
NSDictionary *person = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
@"CuddleGuts", @"name", [NSNumber numberWithInt:6], @"age", nil];
|
||||
RKPathMatcher *matcher = [RKPathMatcher matcherWithPattern:@"/people/(name)/(age)"];
|
||||
NSString *interpolatedPath = [matcher pathFromObject:person];
|
||||
NSString *interpolatedPath = [matcher pathFromObject:person addingEscapes:YES];
|
||||
assertThat(interpolatedPath, isNot(equalTo(nil)));
|
||||
NSString *expectedPath = @"/people/CuddleGuts/6";
|
||||
assertThat(interpolatedPath, is(equalTo(expectedPath)));
|
||||
@@ -115,7 +115,7 @@
|
||||
NSDictionary *person = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
@"JUICE|BOX&121", @"password", @"Joe Bob Briggs", @"name", [NSNumber numberWithInt:15], @"group", nil];
|
||||
RKPathMatcher *matcher = [RKPathMatcher matcherWithPattern:@"/people/:group/:name?password=:password"];
|
||||
NSString *interpolatedPath = [matcher pathFromObject:person];
|
||||
NSString *interpolatedPath = [matcher pathFromObject:person addingEscapes:YES];
|
||||
assertThat(interpolatedPath, isNot(equalTo(nil)));
|
||||
NSString *expectedPath = @"/people/15/Joe%20Bob%20Briggs?password=JUICE%7CBOX%26121";
|
||||
assertThat(interpolatedPath, is(equalTo(expectedPath)));
|
||||
@@ -136,11 +136,10 @@
|
||||
{
|
||||
NSDictionary *arguments = [NSDictionary dictionaryWithObjectsAndKeys:@"Resources", @"filename", nil];
|
||||
RKPathMatcher *matcher = [RKPathMatcher matcherWithPattern:@"/directory/:filename\\.json"];
|
||||
NSString *interpolatedPath = [matcher pathFromObject:arguments];
|
||||
NSString *interpolatedPath = [matcher pathFromObject:arguments addingEscapes:YES];
|
||||
assertThat(interpolatedPath, isNot(equalTo(nil)));
|
||||
NSString *expectedPath = @"/directory/Resources.json";
|
||||
assertThat(interpolatedPath, is(equalTo(expectedPath)));
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@@ -1,248 +0,0 @@
|
||||
//
|
||||
// RKXMLParserTest.m
|
||||
// RestKit
|
||||
//
|
||||
// Created by Jeremy Ellison on 3/29/11.
|
||||
// Copyright (c) 2009-2012 RestKit. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
#import "RKTestEnvironment.h"
|
||||
#import "RKXMLParserXMLReader.h"
|
||||
|
||||
// See Tests/Fixtures/XML/tab_data.xml
|
||||
@interface RKTestTabData : NSObject {
|
||||
NSString *_title;
|
||||
NSString *_summary;
|
||||
}
|
||||
|
||||
@property (nonatomic, retain) NSString *title;
|
||||
@property (nonatomic, retain) NSString *summary;
|
||||
|
||||
@end
|
||||
|
||||
@implementation RKTestTabData
|
||||
|
||||
@synthesize title = _title;
|
||||
@synthesize summary = _summary;
|
||||
|
||||
@end
|
||||
|
||||
@interface RKXMLParserTest : RKTestCase {
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation RKXMLParserTest
|
||||
|
||||
- (void)testShouldMapASingleXMLObjectPayloadToADictionary
|
||||
{
|
||||
NSString *data = @"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<hash>\n <float type=\"float\">2.4</float>\n <string>string</string>\n <number type=\"integer\">1</number>\n</hash>\n";
|
||||
NSError *error = [[NSError alloc] init];
|
||||
RKXMLParserXMLReader *parser = [[RKXMLParserXMLReader new] autorelease];
|
||||
id result = [parser objectFromString:data error:&error];
|
||||
assertThat(result, is(instanceOf([NSDictionary class])));
|
||||
assertThatFloat([[[result valueForKeyPath:@"hash.float"] valueForKey:@"text"] floatValue], is(equalToFloat(2.4f)));
|
||||
assertThatInt([[[result valueForKeyPath:@"hash.number"] valueForKey:@"text"] intValue], is(equalToInt(1)));
|
||||
assertThat([result valueForKeyPath:@"hash.string"], is(equalTo(@"string")));
|
||||
}
|
||||
|
||||
- (void)testShouldMapMultipleObjectsToAnArray
|
||||
{
|
||||
NSString *data = @"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<records type=\"array\">\n <record>\n <float type=\"float\">2.4</float>\n <string>string</string>\n <number type=\"integer\">1</number>\n </record>\n <record>\n <another-number type=\"integer\">1</another-number>\n </record>\n</records>\n";
|
||||
NSError *error = [[NSError alloc] init];
|
||||
RKXMLParserXMLReader *parser = [[RKXMLParserXMLReader new] autorelease];
|
||||
id result = [parser objectFromString:data error:&error];
|
||||
NSArray *records = (NSArray *)[result valueForKeyPath:@"records.record"];
|
||||
assertThatUnsignedInteger([records count], is(equalToInt(2)));
|
||||
id result1 = [records objectAtIndex:0];
|
||||
assertThat(result, is(instanceOf([NSDictionary class])));
|
||||
assertThatFloat([[[result1 valueForKeyPath:@"float"] valueForKey:@"text"] floatValue], is(equalToFloat(2.4f)));
|
||||
assertThatInt([[[result1 valueForKeyPath:@"number"] valueForKey:@"text"] intValue], is(equalToInt(1)));
|
||||
assertThat([result1 valueForKeyPath:@"string"], is(equalTo(@"string")));
|
||||
id result2 = [records objectAtIndex:1];
|
||||
assertThatInt([[[result2 valueForKeyPath:@"another-number"] valueForKey:@"text"] intValue], is(equalToInt(1)));
|
||||
}
|
||||
|
||||
- (void)testShouldMapXML
|
||||
{
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[RKTestTabData class]];
|
||||
[mapping mapAttributes:@"title", @"summary", nil];
|
||||
RKObjectMappingProvider *provider = [[RKObjectMappingProvider alloc] init];
|
||||
id data = [RKTestFixture parsedObjectWithContentsOfFixture:@"tab_data.xml"];
|
||||
assertThat([data valueForKeyPath:@"tabdata.item"], is(instanceOf([NSArray class])));
|
||||
[provider setMapping:mapping forKeyPath:@"tabdata.item"];
|
||||
RKObjectMapper *mapper = [RKObjectMapper mapperWithObject:data mappingProvider:provider];
|
||||
RKMappingResult *result = [mapper performMapping];
|
||||
assertThatUnsignedInteger([[result asCollection] count], is(equalToInt(2)));
|
||||
assertThatUnsignedInteger([[data valueForKeyPath:@"tabdata.title"] count], is(equalToInt(2)));
|
||||
assertThatUnsignedInteger([[data valueForKeyPath:@"tabdata.item"] count], is(equalToInt(2)));
|
||||
}
|
||||
|
||||
- (void)testShouldParseXMLWithAttributes
|
||||
{
|
||||
NSString *XML = [RKTestFixture stringWithContentsOfFixture:@"container_attributes.xml"];
|
||||
NSError *error = [[NSError alloc] init];
|
||||
RKXMLParserXMLReader *parser = [[RKXMLParserXMLReader new] autorelease];
|
||||
NSDictionary *result = [parser objectFromString:XML error:&error];
|
||||
assertThat(result, is(instanceOf([NSDictionary class])));
|
||||
NSArray *elements = [[result objectForKey:@"elements"] objectForKey:@"element"];
|
||||
assertThat(elements, isNot(nilValue()));
|
||||
assertThat(elements, is(instanceOf([NSArray class])));
|
||||
assertThat(elements, hasCountOf(2));
|
||||
NSDictionary *firstElement = [elements objectAtIndex:0];
|
||||
assertThat([firstElement objectForKey:@"attribute"], is(equalTo(@"1")));
|
||||
assertThat([firstElement objectForKey:@"subelement"], is(equalTo(@"text")));
|
||||
NSDictionary *secondElement = [elements objectAtIndex:1];
|
||||
assertThat([secondElement objectForKey:@"attribute"], is(equalTo(@"2")));
|
||||
assertThat([secondElement objectForKey:@"subelement"], is(equalTo(@"text2")));
|
||||
}
|
||||
|
||||
- (void)testShouldParseXMLWithAttributesInTextNodes
|
||||
{
|
||||
NSString *XML = [RKTestFixture stringWithContentsOfFixture:@"attributes_without_text_content.xml"];
|
||||
NSError *error = [[NSError alloc] init];
|
||||
RKXMLParserXMLReader *parser = [[RKXMLParserXMLReader new] autorelease];
|
||||
NSDictionary *result = [parser objectFromString:XML error:&error];
|
||||
NSDictionary *exchangeRate = [result objectForKey:@"exchange_rate"];
|
||||
assertThat(exchangeRate, is(notNilValue()));
|
||||
assertThat([exchangeRate objectForKey:@"type"], is(equalTo(@"XML_RATE_TYPE_EBNK_MIDDLE")));
|
||||
assertThat([exchangeRate objectForKey:@"valid_from"], is(equalTo(@"2011-08-03 00:00:00.0")));
|
||||
assertThat([exchangeRate objectForKey:@"name"], nilValue()); // This is to test for bug in parsing
|
||||
NSArray *currency = [exchangeRate objectForKey:@"currency"];
|
||||
assertThat(currency, hasCountOf(3));
|
||||
NSDictionary *firstCurrency = [currency objectAtIndex:0];
|
||||
assertThat(firstCurrency, is(instanceOf([NSDictionary class])));
|
||||
assertThat([firstCurrency objectForKey:@"name"], is(equalTo(@"AUD")));
|
||||
assertThat([firstCurrency objectForKey:@"quota"], is(equalTo(@"1")));
|
||||
assertThat([firstCurrency objectForKey:@"rate"], is(equalTo(@"18.416")));
|
||||
|
||||
NSDictionary *secondCurrency = [currency objectAtIndex:1];
|
||||
assertThat(secondCurrency, is(instanceOf([NSDictionary class])));
|
||||
assertThat([secondCurrency objectForKey:@"name"], is(equalTo(@"HRK")));
|
||||
assertThat([secondCurrency objectForKey:@"quota"], is(equalTo(@"1")));
|
||||
assertThat([secondCurrency objectForKey:@"rate"], is(equalTo(@"3.25017")));
|
||||
|
||||
NSDictionary *thirdCurrency = [currency objectAtIndex:2];
|
||||
assertThat(thirdCurrency, is(instanceOf([NSDictionary class])));
|
||||
assertThat([thirdCurrency objectForKey:@"name"], is(equalTo(@"DKK")));
|
||||
assertThat([thirdCurrency objectForKey:@"quota"], is(equalTo(@"1")));
|
||||
assertThat([thirdCurrency objectForKey:@"rate"], is(equalTo(@"3.251")));
|
||||
}
|
||||
|
||||
- (void)testShouldNotCrashWhileParsingOrdersXML
|
||||
{
|
||||
NSString *XML = [RKTestFixture stringWithContentsOfFixture:@"orders.xml"];
|
||||
NSError *error = [[NSError alloc] init];
|
||||
RKXMLParserXMLReader *parser = [[RKXMLParserXMLReader new] autorelease];
|
||||
NSException *exception = nil;
|
||||
@try {
|
||||
[parser objectFromString:XML error:&error];;
|
||||
}
|
||||
@catch (NSException *e) {
|
||||
exception = e;
|
||||
}
|
||||
@finally {
|
||||
assertThat(exception, is(nilValue()));
|
||||
}
|
||||
}
|
||||
|
||||
- (void)testShouldParseXMLWithCDATA
|
||||
{
|
||||
NSString *XML = [RKTestFixture stringWithContentsOfFixture:@"zend.xml"];
|
||||
NSError *error = [[NSError alloc] init];
|
||||
RKXMLParserXMLReader *parser = [[RKXMLParserXMLReader new] autorelease];
|
||||
NSDictionary *output = [parser objectFromString:XML error:&error];
|
||||
NSArray *map = [output valueForKeyPath:@"Api.getList.map"];
|
||||
assertThat(map, isNot(nilValue()));
|
||||
assertThat(map, hasCountOf(4));
|
||||
assertThat([[map objectAtIndex:0] valueForKey:@"title"], is(equalTo(@"Main World Map")));
|
||||
assertThat([[map objectAtIndex:1] valueForKey:@"title"], is(equalTo(@"Section Map: Narshe Village")));
|
||||
assertThat([[map objectAtIndex:2] valueForKey:@"subtitle"], is(equalTo(@"Kary lives here.")));
|
||||
}
|
||||
|
||||
- (void)testShouldConsiderASingleCloseTagAnEmptyContainer
|
||||
{
|
||||
NSString *XML = @"<users />";
|
||||
NSError *error = [[NSError alloc] init];
|
||||
RKXMLParserXMLReader *parser = [[RKXMLParserXMLReader new] autorelease];
|
||||
NSDictionary *output = [parser objectFromString:XML error:&error];
|
||||
NSDictionary *users = [output valueForKey:@"users"];
|
||||
NSLog(@"%@", output);
|
||||
assertThat(users, is(notNilValue()));
|
||||
assertThatBool([users isKindOfClass:[NSDictionary class]], is(equalToBool(YES)));
|
||||
}
|
||||
|
||||
- (void)testShouldParseRelativelyComplexXML
|
||||
{
|
||||
NSString *XML = [RKTestFixture stringWithContentsOfFixture:@"national_weather_service.xml"];
|
||||
NSError *error = [[NSError alloc] init];
|
||||
RKXMLParserXMLReader *parser = [[RKXMLParserXMLReader new] autorelease];
|
||||
NSException *exception = nil;
|
||||
@try {
|
||||
[parser objectFromString:XML error:&error];
|
||||
}
|
||||
@catch (NSException *e) {
|
||||
exception = e;
|
||||
}
|
||||
@finally {
|
||||
assertThat(exception, is(nilValue()));
|
||||
}
|
||||
}
|
||||
|
||||
- (void)testShouldParseXMLElementsAndAttributesProperly
|
||||
{
|
||||
|
||||
NSString *XML = [RKTestFixture stringWithContentsOfFixture:@"channels.xml"];
|
||||
NSError *error = [[NSError alloc] init];
|
||||
RKXMLParserXMLReader *parser = [[RKXMLParserXMLReader new] autorelease];
|
||||
NSDictionary *result = [parser objectFromString:XML error:&error];
|
||||
|
||||
NSLog(@"result : %@", result);
|
||||
|
||||
NSDictionary *channel = [[result objectForKey:@"Channels"] objectForKey:@"Channel"];
|
||||
assertThat(channel, is(notNilValue()));
|
||||
|
||||
// Check to see if the Channel attributes are properly parsed
|
||||
assertThat([channel objectForKey:@"Identifier"], is(equalTo(@"1172")));
|
||||
assertThat([channel objectForKey:@"Title"], is(equalTo(@"MySpecialTitle")));
|
||||
assertThat([channel objectForKey:@"Position"], is(equalTo(@"2234")));
|
||||
|
||||
NSLog(@"channel: %@", channel);
|
||||
|
||||
// Check to see if the Channel elements are properly parsed
|
||||
assertThat([channel objectForKey:@"Languages"], is(equalTo(@"it")));
|
||||
|
||||
assertThat([[channel objectForKey:@"Stream"] objectForKey:@"text"], is(equalTo(@"MySpecialTitle")));
|
||||
assertThat([[channel objectForKey:@"Stream"] objectForKey:@"Identifier"], is(equalTo(@"MySpecialTitle")));
|
||||
assertThat([[channel objectForKey:@"Stream"] objectForKey:@"Index"], is(equalTo(@"0")));
|
||||
|
||||
assertThat([[[channel objectForKey:@"Program"] objectAtIndex:0] objectForKey:@"Identifier"], is(equalTo(@"42883461")));
|
||||
assertThat([[[channel objectForKey:@"Program"] objectAtIndex:0] objectForKey:@"Start"], is(equalTo(@"2011-12-19 20:00:00Z")));
|
||||
assertThat([[[channel objectForKey:@"Program"] objectAtIndex:0] objectForKey:@"End"], is(equalTo(@"2011-12-19 21:00:00Z")));
|
||||
assertThat([[[channel objectForKey:@"Program"] objectAtIndex:0] objectForKey:@"Title"], is(equalTo(@"Program Title 1")));
|
||||
|
||||
assertThat([[[channel objectForKey:@"Program"] objectAtIndex:1] objectForKey:@"Identifier"], is(equalTo(@"42883471")));
|
||||
assertThat([[[channel objectForKey:@"Program"] objectAtIndex:1] objectForKey:@"Start"], is(equalTo(@"2011-12-19 21:00:00Z")));
|
||||
assertThat([[[channel objectForKey:@"Program"] objectAtIndex:1] objectForKey:@"End"], is(equalTo(@"2011-12-19 23:00:00Z")));
|
||||
assertThat([[[channel objectForKey:@"Program"] objectAtIndex:1] objectForKey:@"Title"], is(equalTo(@"Program Title")));
|
||||
|
||||
assertThat([[channel objectForKey:@"Image"] objectAtIndex:0], is(equalTo(@"http://domain.com/Images/MySpecialTitle.png")));
|
||||
assertThat([[[channel objectForKey:@"Image"] objectAtIndex:1] objectForKey:@"text"], is(equalTo(@"http://domain.com/Images/65x35/2234.png")));
|
||||
assertThat([[[channel objectForKey:@"Image"] objectAtIndex:1] objectForKey:@"Width"], is(equalTo(@"65")));
|
||||
assertThat([[[channel objectForKey:@"Image"] objectAtIndex:1] objectForKey:@"Height"], is(equalTo(@"35")));
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -20,7 +20,6 @@
|
||||
|
||||
|
||||
#import "RKHuman.h"
|
||||
#import "NSDictionary+RKAdditions.h"
|
||||
|
||||
@implementation RKHuman
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
//
|
||||
|
||||
#import "RKMappableObject.h"
|
||||
#import "NSDictionary+RKAdditions.h"
|
||||
|
||||
@implementation RKMappableObject
|
||||
|
||||
|
||||
Reference in New Issue
Block a user