Skip to content
This repository has been archived by the owner on Dec 5, 2019. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/ApplyKeyValueChangeDictionaryFix'
Browse files Browse the repository at this point in the history
  • Loading branch information
jspahrsummers committed Apr 13, 2012
2 parents 42af47e + c2f500f commit c7e8b8c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Proton/NSObject+KeyValueCodingAdditions.m
Expand Up @@ -57,7 +57,7 @@ - (void)applyKeyValueChangeDictionary:(NSDictionary *)changes toKeyPath:(NSStrin
}];
}

if (convertToSet) {
if (convertToSet && ![newCollection isKindOfClass:[NSSet class]]) {
return [NSSet setWithArray:newCollection];
} else {
return newCollection;
Expand Down
15 changes: 15 additions & 0 deletions ProtonTests/PRONSObjectAdditionsTests.m
Expand Up @@ -568,6 +568,21 @@ @interface ErrorTestClass : NSObject
[object applyKeyValueChangeDictionary:changes toKeyPath:keyPath mappingNewObjectsUsingBlock:mappingBlock];
});

it(@"should apply 'insertion' change with mapping using a set", ^{
NSSet *insertedObjects = [NSSet setWithObjects:@"quux", [NSNull null], nil];

NSDictionary *changes = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithUnsignedInteger:NSKeyValueChangeInsertion], NSKeyValueChangeKindKey,
insertedObjects, NSKeyValueChangeNewKey,
nil
];

expectedSet = [set mutableCopy];
[expectedSet unionSet:[insertedObjects mapUsingBlock:mappingBlock]];

[object applyKeyValueChangeDictionary:changes toKeyPath:keyPath mappingNewObjectsUsingBlock:mappingBlock];
});

it(@"should apply 'removal' change with mapping", ^{
NSSet *removedObjects = [NSSet setWithObjects:@"foo", @"fizz", [NSNull null], nil];

Expand Down

0 comments on commit c7e8b8c

Please sign in to comment.