Skip to content

Commit

Permalink
Merge pull request appsquickly#16 from BrynCooke/master
Browse files Browse the repository at this point in the history
Fix bug in injectProperties when dealing with subclassing
  • Loading branch information
jasperblues committed May 9, 2013
2 parents f07c821 + 8b27b5f commit 63297c4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Source/Factory/TyphoonComponentFactory.m
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ - (void)injectProperties:(id)instance {
Class class = [instance class];
for (TyphoonDefinition* definition in _registry)
{
if(definition.type == class || [definition.type isSubclassOfClass:class])
if(definition.type == class || [class isSubclassOfClass:definition.type])
{
[self injectPropertyDependenciesOn:instance withDefinition:definition];
}
Expand Down
26 changes: 26 additions & 0 deletions Tests/Factory/TyphoonComponentFactoryTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,30 @@ - (void)test_injectProperties

}

- (void)test_injectProperties_subclassing
{
[_componentFactory register:[TyphoonDefinition withClass:[Knight class] properties:^(TyphoonDefinition* definition)
{
[definition injectProperty:@selector(quest)];
}]];
[_componentFactory register:[TyphoonDefinition withClass:[CavalryMan class] properties:^(TyphoonDefinition* definition)
{
[definition injectProperty:@selector(hitRatio) withValueAsText:@"3.0"];
}]];
[_componentFactory register:[TyphoonDefinition withClass:[CampaignQuest class] key:@"quest"]];

CavalryMan* cavelryMan = [[CavalryMan alloc] init];
[_componentFactory injectProperties:cavelryMan];

assertThat(cavelryMan.quest, notNilValue());
assertThatFloat(cavelryMan.hitRatio, equalToFloat(3.0f));

Knight* knight = [[Knight alloc] init];
[_componentFactory injectProperties:knight];

assertThat(knight.quest, notNilValue());

}


@end

0 comments on commit 63297c4

Please sign in to comment.