Files
RestKit/Tests/Logic/ObjectMapping/RKObjectRelationshipMappingTest.m
Blake Watters d926e240f8 Introduce RKPropertyMapping abstract superclass for RKAttributeMapping and RKRelationshipMapping.
Add primitives for working with attribute, relationship, and property mapping objects.
2012-08-28 14:14:20 -04:00

78 lines
3.6 KiB
Objective-C

//
// RKRelationshipMappingTest.m
// RestKit
//
// Created by Blake Watters on 6/8/12.
// Copyright (c) 2012 RestKit. All rights reserved.
//
#import "RKTestEnvironment.h"
@interface RKRelationshipMappingTest : RKTestCase
@end
@implementation RKRelationshipMappingTest
- (void)testThatRelationshipMappingsWithTheSameSourceAndDestinationKeyPathAreConsideredEqual
{
RKRelationshipMapping *mapping1 = [RKRelationshipMapping mappingFromKeyPath:@"this" toKeyPath:@"that" withMapping:nil];
RKRelationshipMapping *mapping2 = [RKRelationshipMapping mappingFromKeyPath:@"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];
assertThatBool([mapping1 isEqualToMapping:mapping2], is(equalToBool(NO)));
}
- (void)testThatTwoMappingsWithEqualRelationshipMappingsAreConsideredEqual
{
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];
assertThatBool([mapping1 isEqualToMapping:mapping2], is(equalToBool(YES)));
}
- (void)testThatTwoMappingsWithDifferingRelationshipMappingClassesAreNotConsideredEqual
{
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];
assertThatBool([mapping1 isEqualToMapping:mapping2], is(equalToBool(NO)));
}
- (void)testThatTwoMappingsWhereOneHasANilObjectClassNotConsideredEqual
{
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];
assertThatBool([mapping1 isEqualToMapping:mapping2], is(equalToBool(NO)));
}
- (void)testThatTwoMappingsWhereBothHaveANilObjectClassNotConsideredEqual
{
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];
assertThatBool([mapping1 isEqualToMapping:mapping2], is(equalToBool(YES)));
}
@end