make installationIdentification KVO'able

This commit is contained in:
Stephan Diederich 2013-09-06 17:24:01 +02:00
parent 96304ac639
commit 6f64b8e5d6
3 changed files with 29 additions and 1 deletions

View File

@ -81,10 +81,11 @@ typedef void(^tValidationCompletion)(BOOL validated, NSError *error);
* to provide better error reporting & analytics. If authenticator is configured to login
* (@see BITAuthenticatorValidationType), this identifier is retrieved from HockeyApp. In case
* it is disabled, it returns the vendorIdentifier provided by UIKit.
* KVO'able
*
* @return a string identifying this app installation
*/
- (NSString *) installationIdentification;
@property (nonatomic, readonly) NSString *installationIdentification;
#pragma mark - Authentication
/**

View File

@ -328,11 +328,13 @@ static NSString* const kBITAuthenticatorLastAuthenticatedVersionKey = @"BITAuthe
#pragma mark - Property overrides
- (void)setAuthenticationToken:(NSString *)authenticationToken {
if(![self.authenticationToken isEqualToString:authenticationToken]) {
[self willChangeValueForKey:@"installationIdentification"];
if(nil == authenticationToken) {
[self removeKeyFromKeychain:kBITAuthenticatorAuthTokenKey];
} else {
[self addStringValueToKeychain:authenticationToken forKey:kBITAuthenticatorAuthTokenKey];
}
[self didChangeValueForKey:@"installationIdentification"];
}
}

View File

@ -27,11 +27,14 @@
- (NSString*) uniqueIdentifier {return @"reallyUnique";}
@end
static void *kInstallationIdentification = &kInstallationIdentification;
@interface BITAuthenticatorTests : SenTestCase
@end
@implementation BITAuthenticatorTests {
BITAuthenticator *_sut;
BOOL _KVOCalled;
}
- (void)setUp {
@ -190,6 +193,28 @@
assertThat(_sut.authenticationToken, equalTo(nil));
}
- (void) testThatKVOWorksOnApplicationIdentification {
//this will prepare everything and show the viewcontroller
[_sut authenticateWithCompletion:nil];
[_sut addObserver:self forKeyPath:@"installationIdentification"
options:0
context:kInstallationIdentification];
//fake delegate call from the viewcontroller
[_sut authenticationViewControllerDidCancel:nil];
assertThatBool(_KVOCalled, equalToBool(YES));
[_sut removeObserver:self forKeyPath:@"installationIdentification"];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if(kInstallationIdentification == context) {
_KVOCalled = YES;
} else {
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
}
#pragma mark - validation tests
- (void) testThatValidationWithoutTokenWantsToShowTheAuthenticationViewController {
id delegateMock = mockProtocol(@protocol(BITAuthenticatorDelegate));