Permalink
Browse files

Add BuildUpdater

  • Loading branch information...
1 parent 7c891b9 commit 3fd3f990068f089fd86ff9df13a9d22a432c50f5 @henrikhodne henrikhodne committed Dec 2, 2012
Showing with 146 additions and 12 deletions.
  1. +18 −2 Travis CI.xcodeproj/project.pbxproj
  2. +5 −10 src/AppDelegate.m
  3. +19 −0 src/BuildUpdater.h
  4. +47 −0 src/BuildUpdater.m
  5. +57 −0 test/BuildUpdaterTests.m
@@ -31,6 +31,11 @@
2E72AF4F166AB20C00F2631C /* EventConverter.m in Sources */ = {isa = PBXBuildFile; fileRef = 2E72AF4D166AB20C00F2631C /* EventConverter.m */; };
2E72AF52166AB21E00F2631C /* EventConverterTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 2E72AF51166AB21E00F2631C /* EventConverterTests.m */; };
2E72AF53166AB6C800F2631C /* Notification.m in Sources */ = {isa = PBXBuildFile; fileRef = 2E75988A164DF68100B87810 /* Notification.m */; };
+ 2E72AF5E166AEA6500F2631C /* BuildUpdater.m in Sources */ = {isa = PBXBuildFile; fileRef = 2E72AF5D166AEA6500F2631C /* BuildUpdater.m */; };
+ 2E72AF5F166AEA6500F2631C /* BuildUpdater.m in Sources */ = {isa = PBXBuildFile; fileRef = 2E72AF5D166AEA6500F2631C /* BuildUpdater.m */; };
+ 2E72AF63166AEA9F00F2631C /* BuildUpdaterTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 2E72AF62166AEA9F00F2631C /* BuildUpdaterTests.m */; };
+ 2E72AF64166AED1400F2631C /* TravisAPI.m in Sources */ = {isa = PBXBuildFile; fileRef = 2E00CCB3164EE10000A30635 /* TravisAPI.m */; };
+ 2E72AF65166AED2700F2631C /* TravisHTTPClient.m in Sources */ = {isa = PBXBuildFile; fileRef = 2E00CCB6164EE18000A30635 /* TravisHTTPClient.m */; };
2E75988B164DF68100B87810 /* Notification.m in Sources */ = {isa = PBXBuildFile; fileRef = 2E75988A164DF68100B87810 /* Notification.m */; };
2E90F156164E389F009CAA25 /* Travis CI.icns in Resources */ = {isa = PBXBuildFile; fileRef = 2E90F155164E389F009CAA25 /* Travis CI.icns */; };
2E90F15A164E49BB009CAA25 /* NotificationDisplayer.m in Sources */ = {isa = PBXBuildFile; fileRef = 2E90F159164E49BB009CAA25 /* NotificationDisplayer.m */; };
@@ -137,6 +142,9 @@
2E72AF4C166AB20C00F2631C /* EventConverter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EventConverter.h; sourceTree = "<group>"; };
2E72AF4D166AB20C00F2631C /* EventConverter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EventConverter.m; sourceTree = "<group>"; };
2E72AF51166AB21E00F2631C /* EventConverterTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EventConverterTests.m; sourceTree = "<group>"; };
+ 2E72AF5C166AEA6500F2631C /* BuildUpdater.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BuildUpdater.h; sourceTree = "<group>"; };
+ 2E72AF5D166AEA6500F2631C /* BuildUpdater.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BuildUpdater.m; sourceTree = "<group>"; };
+ 2E72AF62166AEA9F00F2631C /* BuildUpdaterTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BuildUpdaterTests.m; sourceTree = "<group>"; };
2E759889164DF68100B87810 /* Notification.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = Notification.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
2E75988A164DF68100B87810 /* Notification.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = Notification.m; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
2E90F155164E389F009CAA25 /* Travis CI.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = "Travis CI.icns"; sourceTree = "<group>"; };
@@ -301,6 +309,7 @@
2E00CCC4164F974900A30635 /* TravisToolbarTests */ = {
isa = PBXGroup;
children = (
+ 2E72AF62166AEA9F00F2631C /* BuildUpdaterTests.m */,
2E72AF51166AB21E00F2631C /* EventConverterTests.m */,
2E72AF40166A7F4600F2631C /* EventFilterTests.m */,
2EBA8CF5164FAD4A005C033E /* FilterPreferencesTests.m */,
@@ -342,10 +351,12 @@
children = (
2E72AF391669DA5F00F2631C /* BuildEventStream.h */,
2E72AF3A1669DA6000F2631C /* BuildEventStream.m */,
- 2E72AF3C166A7BE000F2631C /* EventFilter.h */,
- 2E72AF3D166A7BE000F2631C /* EventFilter.m */,
+ 2E72AF5C166AEA6500F2631C /* BuildUpdater.h */,
+ 2E72AF5D166AEA6500F2631C /* BuildUpdater.m */,
2E72AF4C166AB20C00F2631C /* EventConverter.h */,
2E72AF4D166AB20C00F2631C /* EventConverter.m */,
+ 2E72AF3C166A7BE000F2631C /* EventFilter.h */,
+ 2E72AF3D166A7BE000F2631C /* EventFilter.m */,
);
name = Pipeline;
sourceTree = "<group>";
@@ -544,6 +555,8 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
+ 2E72AF65166AED2700F2631C /* TravisHTTPClient.m in Sources */,
+ 2E72AF64166AED1400F2631C /* TravisAPI.m in Sources */,
2E72AF53166AB6C800F2631C /* Notification.m in Sources */,
2E72AF44166A812200F2631C /* BuildEvent.m in Sources */,
2E72AF43166A800400F2631C /* EventFilter.m in Sources */,
@@ -555,6 +568,8 @@
2E72AF41166A7F4600F2631C /* EventFilterTests.m in Sources */,
2E72AF4F166AB20C00F2631C /* EventConverter.m in Sources */,
2E72AF52166AB21E00F2631C /* EventConverterTests.m in Sources */,
+ 2E72AF5F166AEA6500F2631C /* BuildUpdater.m in Sources */,
+ 2E72AF63166AEA9F00F2631C /* BuildUpdaterTests.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -576,6 +591,7 @@
2E72AF3B1669DA6000F2631C /* BuildEventStream.m in Sources */,
2E72AF3E166A7BE100F2631C /* EventFilter.m in Sources */,
2E72AF4E166AB20C00F2631C /* EventConverter.m in Sources */,
+ 2E72AF5E166AEA6500F2631C /* BuildUpdater.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
@@ -18,13 +18,14 @@
#import "BuildEventStream.h"
#import "EventFilter.h"
#import "EventConverter.h"
+#import "BuildUpdater.h"
@interface AppDelegate () <NSUserNotificationCenterDelegate>
@property (strong) NSStatusItem *statusItem;
@property (strong) BuildEventStream *buildEventStream;
@property (strong) EventFilter *eventFilter;
@property (strong) EventConverter *eventConverter;
-@property (strong) RACSignal *updatedBuilds;
+@property (strong) BuildUpdater *buildUpdater;
@end
@implementation AppDelegate
@@ -37,15 +38,9 @@ - (void)applicationDidFinishLaunching:(NSNotification *)notification {
[self setBuildEventStream:[BuildEventStream buildEventStream]];
[self setEventFilter:[EventFilter eventFilterWithInputStream:[[self buildEventStream] eventStream] filterPreferences:[FilterPreferences filterWithPreferences:[Preferences sharedPreferences]]]];
-
- [self setUpdatedBuilds:[[[self eventFilter] outputStream] flattenMap:^(BuildEvent *event) {
- return [[[TravisAPI standardAPI] fetchBuildWithID:[event buildID] forRepository:[event name]] map:^(NSDictionary *build) {
- [event updateBuildInfo:build];
- return event;
- }];
- }]];
-
- [self setEventConverter:[EventConverter eventConverterWithInputStream:[self updatedBuilds]]];
+ [self setBuildUpdater:[BuildUpdater buildUpdaterWithInputStream:[[self eventFilter] outputStream] API:[TravisAPI standardAPI]]];
+ [self setEventConverter:[EventConverter eventConverterWithInputStream:[[self buildUpdater] outputStream]]];
+
[[[self eventConverter] outputStream] subscribeNext:^(Notification *notification) {
[[NotificationDisplayer sharedNotificationDisplayer] deliverNotification:notification];
}];
View
@@ -0,0 +1,19 @@
+//
+// BuildUpdater.h
+// Travis CI
+//
+// Created by Henrik Hodne on 12/1/12.
+// Copyright (c) 2012 Travis CI GmbH. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@class RACSignal;
+@class TravisAPI;
+
+@interface BuildUpdater : NSObject
+@property (nonatomic, strong, readonly) RACSignal *outputStream;
+
++ (BuildUpdater *)buildUpdaterWithInputStream:(RACSignal *)inputStream API:(TravisAPI *)API;
+
+@end
View
@@ -0,0 +1,47 @@
+//
+// BuildUpdater.m
+// Travis CI
+//
+// Created by Henrik Hodne on 12/1/12.
+// Copyright (c) 2012 Travis CI GmbH. All rights reserved.
+//
+
+#import "BuildUpdater.h"
+#import <ReactiveCocoa/ReactiveCocoa.h>
+#import <libextobjc/EXTScope.h>
+#import "TravisAPI.h"
+#import "BuildEvent.h"
+
+@interface BuildUpdater ()
+@property (nonatomic, strong, readonly) RACSignal *inputStream;
+@property (nonatomic, strong, readonly) TravisAPI *API;
+@end
+
+@implementation BuildUpdater
+
+- (RACSignal *)outputStream {
+ @weakify(self);
+ return [[self inputStream] flattenMap:^(BuildEvent *event) {
+ @strongify(self);
+ return [[[self API] fetchBuildWithID:[event buildID] forRepository:[event name]] map:^(NSDictionary *build) {
+ [event updateBuildInfo:build];
+ return event;
+ }];
+ }];
+}
+
++ (BuildUpdater *)buildUpdaterWithInputStream:(RACSignal *)inputStream API:(TravisAPI *)API {
+ return [[self alloc] initWithInputStream:inputStream API:API];
+}
+
+- (id)initWithInputStream:(RACSignal *)inputStream API:(TravisAPI *)API {
+ self = [super init];
+ if (self == nil) return nil;
+
+ _inputStream = inputStream;
+ _API = API;
+
+ return self;
+}
+
+@end
View
@@ -0,0 +1,57 @@
+//
+// BuildUpdaterTests.m
+// Travis CI
+//
+// Created by Henrik Hodne on 12/1/12.
+// Copyright (c) 2012 Travis CI GmbH. All rights reserved.
+//
+
+#import <SenTestingKit/SenTestingKit.h>
+
+#define HC_SHORTHAND
+#import <OCHamcrest/OCHamcrest.h>
+
+#define MOCKITO_SHORTHAND
+#import <OCMockito/OCMockito.h>
+
+#import "BuildUpdater.h"
+#import "BuildEvent.h"
+#import "TravisAPI.h"
+#import <ReactiveCocoa/ReactiveCocoa.h>
+
+@interface BuildUpdaterTests : SenTestCase
+@end
+
+@implementation BuildUpdaterTests {
+ TravisAPI *_mockAPI;
+ RACSubject *_inputStream;
+ BuildUpdater *_buildUpdater;
+ id<RACSubscriber> _outputStream;
+}
+
+- (void)setUp {
+ _mockAPI = mock([TravisAPI class]);
+ _inputStream = [RACSubject subject];
+ _buildUpdater = [BuildUpdater buildUpdaterWithInputStream:_inputStream API:_mockAPI];
+
+ _outputStream = mockProtocol(@protocol(RACSubscriber));
+ [[_buildUpdater outputStream] subscribe:_outputStream];
+
+ RACReplaySubject *APIResponseSubject = [RACReplaySubject subject];
+ [given([_mockAPI fetchBuildWithID:@(1234) forRepository:@"travis-ci/travis-ci"]) willReturn:APIResponseSubject];
+ [APIResponseSubject sendNext:@{ @"id": @(1234), @"number": @(15) }];
+ [APIResponseSubject sendCompleted];
+}
+
+- (void)testBuildUpdaterUpdatesBuild {
+ BuildEvent *buildEvent = [[BuildEvent alloc] initWithEventData:@{ @"build": @{ @"id": @(1234) }, @"repository": @{ @"slug": @"travis-ci/travis-ci" } }];
+ [_inputStream sendNext:buildEvent];
+
+ [verify(_outputStream) sendNext:allOf(
+ hasProperty(@"buildID", @(1234)),
+ hasProperty(@"buildNumber", @(15)),
+ nil
+ )];
+}
+
+@end

0 comments on commit 3fd3f99

Please sign in to comment.