aboutsummaryrefslogtreecommitdiffstats
path: root/Frameworks/PostgresKit
diff options
context:
space:
mode:
Diffstat (limited to 'Frameworks/PostgresKit')
-rw-r--r--Frameworks/PostgresKit/Resources/Tests-Info.plist2
-rw-r--r--Frameworks/PostgresKit/Source/PGPostgresConnection.m6
-rw-r--r--Frameworks/PostgresKit/Source/PGPostgresConnectionQueryExecution.m4
-rw-r--r--Frameworks/PostgresKit/Tests/PGDataTypeTests.m38
4 files changed, 21 insertions, 29 deletions
diff --git a/Frameworks/PostgresKit/Resources/Tests-Info.plist b/Frameworks/PostgresKit/Resources/Tests-Info.plist
index a820956d..b88d8638 100644
--- a/Frameworks/PostgresKit/Resources/Tests-Info.plist
+++ b/Frameworks/PostgresKit/Resources/Tests-Info.plist
@@ -5,7 +5,7 @@
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
- <string>PostgresKit</string>
+ <string>Tests</string>
<key>CFBundleIdentifier</key>
<string>com.sequelpro.postgreskit.tests</string>
<key>CFBundleInfoDictionaryVersion</key>
diff --git a/Frameworks/PostgresKit/Source/PGPostgresConnection.m b/Frameworks/PostgresKit/Source/PGPostgresConnection.m
index dda021fe..920fc626 100644
--- a/Frameworks/PostgresKit/Source/PGPostgresConnection.m
+++ b/Frameworks/PostgresKit/Source/PGPostgresConnection.m
@@ -168,11 +168,7 @@ static void _PGPostgresConnectionNoticeProcessor(void *arg, const char *message)
*/
- (BOOL)connect
{
- if ([self isConnected]) {
- [PGPostgresException raise:PGPostgresConnectionErrorDomain reason:@"Attempt to initiate a connection that is already active"];
-
- return NO;
- }
+ if ([self isConnected]) return YES;
[self _createConnectionParameters];
diff --git a/Frameworks/PostgresKit/Source/PGPostgresConnectionQueryExecution.m b/Frameworks/PostgresKit/Source/PGPostgresConnectionQueryExecution.m
index ee8853c7..3de02350 100644
--- a/Frameworks/PostgresKit/Source/PGPostgresConnectionQueryExecution.m
+++ b/Frameworks/PostgresKit/Source/PGPostgresConnectionQueryExecution.m
@@ -118,8 +118,8 @@ PGQueryParamData;
_lastQueryWasCancelled = NO;
if (!query ||
- ![query isKindOfClass:[NSString class]] ||
- ![query isKindOfClass:[PGPostgresStatement class]] ||
+ (![query isKindOfClass:[NSString class]] &&
+ ![query isKindOfClass:[PGPostgresStatement class]]) ||
![self isConnected])
{
return nil;
diff --git a/Frameworks/PostgresKit/Tests/PGDataTypeTests.m b/Frameworks/PostgresKit/Tests/PGDataTypeTests.m
index 8bea485e..b334c9f6 100644
--- a/Frameworks/PostgresKit/Tests/PGDataTypeTests.m
+++ b/Frameworks/PostgresKit/Tests/PGDataTypeTests.m
@@ -67,7 +67,7 @@ static NSUInteger PGTestDatabasePort = 5432;
[self _addTestForField:@"int" withExpectedResult:[NSNumber numberWithInt:12345] connection:connection toTestSuite:testSuite];
[self _addTestForField:@"smallint" withExpectedResult:[NSNumber numberWithInt:2] connection:connection toTestSuite:testSuite];
[self _addTestForField:@"bigint" withExpectedResult:[NSNumber numberWithInt:123456789] connection:connection toTestSuite:testSuite];
- [self _addTestForField:@"bool" withExpectedResult:[NSNumber numberWithBool:YES] connection:connection toTestSuite:testSuite];
+ [self _addTestForField:@"bool" withExpectedResult:[NSNumber numberWithInteger:1] connection:connection toTestSuite:testSuite];
[self _addTestForField:@"float" withExpectedResult:[NSNumber numberWithFloat:12345.678] connection:connection toTestSuite:testSuite];
[self _addTestForField:@"numeric" withExpectedResult:[NSNumber numberWithDouble:12345.678] connection:connection toTestSuite:testSuite];
[self _addTestForField:@"char" withExpectedResult:@"CHAR" connection:connection toTestSuite:testSuite];
@@ -103,17 +103,10 @@ static NSUInteger PGTestDatabasePort = 5432;
#pragma mark Setup & Teardown
- (void)setUp
-{
- PGPostgresResult *queryResult = [_connection executeWithFormat:@"SELECT \"%@\" FROM \"data_types\"", _field];
+{
+ PGPostgresResult *queryResult = [_connection executeWithFormat:@"SELECT \"%@_field\" FROM \"data_types\"", _field];
- _result = [[queryResult row] objectForKey:_field];
-}
-
-- (void)tearDown
-{
- if (_connection && [_connection isConnected]) {
- [_connection disconnect];
- }
+ [self setResult:[[queryResult row] objectForKey:[NSString stringWithFormat:@"%@_field", _field]]];
}
#pragma mark -
@@ -125,32 +118,31 @@ static NSUInteger PGTestDatabasePort = 5432;
}
- (void)testResultIsOfCorrectType
-{
+{
STAssertTrue([_result isKindOfClass:[_expectedResult class]], @"");
}
- (void)testResultHasCorrectValue
-{
- STAssertEquals(_result, _expectedResult, @"");
+{
+ STAssertEqualObjects(_result, _expectedResult, @"");
}
-#pragma mark -
+#pragma mark -r
#pragma mark Private API
- (void)_establishConnection
{
+ [_connection setDelegate:self];
+
[_connection setHost:PGTestDatabaseHost];
[_connection setUser:PGTestDatabaseUser];
[_connection setPort:PGTestDatabasePort];
[_connection setDatabase:PGTestDatabaseName];
[_connection setPassword:PGTestDatabasePassword];
- do {
- sleep(0.1);
- }
- while (![_connection isConnected]);
-
- if (![_connection isConnected]) STFail(@"Unable to establish connection to local database. All tests will fail.");
+ if (![_connection connect] || ![_connection isConnected]) {
+ STFail(@"Unable to establish connection to local database. All tests will fail.");
+ }
}
+ (void)_addTestForField:(NSString *)field
@@ -172,6 +164,10 @@ static NSUInteger PGTestDatabasePort = 5432;
- (void)dealloc
{
+ if (_connection && [_connection isConnected]) {
+ [_connection disconnect];
+ }
+
if (_result) [_result release], _result = nil;
if (_field) [_field release], _field = nil;
if (_connection) [_connection release], _connection = nil;