Skip to content

Commit

Permalink
Add test to verify that non-trivial keypaths work
Browse files Browse the repository at this point in the history
  • Loading branch information
kristopherjohnson committed Mar 24, 2012
1 parent ab8ca74 commit 231d651
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions KJSimpleBindingTests/KJBindingManagerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,20 @@ @interface TestModel : NSObject
@property (nonatomic, copy) NSString *stringValue;
@property (nonatomic, copy) NSString *stringValue2;
@property (nonatomic) NSInteger numericValue;
@property (nonatomic, retain) TestModel *submodel;
@end

@implementation TestModel

@synthesize stringValue;
@synthesize stringValue2;
@synthesize numericValue;
@synthesize submodel;

- (void)dealloc {
[stringValue release];
[stringValue2 release];
[submodel release];
[super dealloc];
}

Expand Down Expand Up @@ -263,4 +266,22 @@ - (void)testValueTransform {
STAssertEqualObjects(@"22", observer.text, nil);
}

- (void)testSubjectKeyPath {
TestModel *topModel = [[[TestModel alloc] init] autorelease];
TestModel *subModel = [[[TestModel alloc] init] autorelease];

topModel.submodel = subModel;

TestObserver *observer = [[[TestObserver alloc] init] autorelease];

// Bind to topModel, but use a key path to actually bind to its submodel's stringValue
[bindingManager bindObserver:observer keyPath:@"text"
toSubject:topModel keyPath:@"submodel.stringValue"];
[bindingManager enable];

subModel.stringValue = @"Submodel value";

STAssertEqualObjects(@"Submodel value", observer.text, nil);
}

@end

0 comments on commit 231d651

Please sign in to comment.