diff options
author | stuconnolly <stuart02@gmail.com> | 2012-07-09 09:27:48 +0000 |
---|---|---|
committer | stuconnolly <stuart02@gmail.com> | 2012-07-09 09:27:48 +0000 |
commit | c1bab7abd666d809aa01c330a66c53e1b6abe6c4 (patch) | |
tree | 075fcdeb4b371e0fd1a21e74fa14ebf705860e2e /Frameworks/QueryKit/Tests/QKSelectQueryOrderByTests.m | |
parent | a434272a852db341a6ea4421e388ef924b6a99d7 (diff) | |
download | sequelpro-c1bab7abd666d809aa01c330a66c53e1b6abe6c4.tar.gz sequelpro-c1bab7abd666d809aa01c330a66c53e1b6abe6c4.tar.bz2 sequelpro-c1bab7abd666d809aa01c330a66c53e1b6abe6c4.zip |
Improve QueryKit's handling of quotes by making it on by default. Also, add a bunch more tests.
Diffstat (limited to 'Frameworks/QueryKit/Tests/QKSelectQueryOrderByTests.m')
-rw-r--r-- | Frameworks/QueryKit/Tests/QKSelectQueryOrderByTests.m | 58 |
1 files changed, 47 insertions, 11 deletions
diff --git a/Frameworks/QueryKit/Tests/QKSelectQueryOrderByTests.m b/Frameworks/QueryKit/Tests/QKSelectQueryOrderByTests.m index ac70f0fe..cb1a472f 100644 --- a/Frameworks/QueryKit/Tests/QKSelectQueryOrderByTests.m +++ b/Frameworks/QueryKit/Tests/QKSelectQueryOrderByTests.m @@ -29,16 +29,12 @@ // OTHER DEALINGS IN THE SOFTWARE. #import "QKSelectQueryOrderByTests.h" - -static NSString *QKTestTableName = @"test_table"; - -static NSString *QKTestFieldOne = @"test_field1"; -static NSString *QKTestFieldTwo = @"test_field2"; +#import "QKTestConstants.h" @implementation QKSelectQueryOrderByTests #pragma mark - -#pragma mark Setup & tear down +#pragma mark Setup - (void)setUp { @@ -53,43 +49,83 @@ static NSString *QKTestFieldTwo = @"test_field2"; - (void)testSelectQueryTypeIsCorrect { - STAssertTrue([[_query query] hasPrefix:@"SELECT"], @"query type"); + STAssertTrue([[_query query] hasPrefix:@"SELECT"], @"select query type"); } - (void)testSelectQueryOrderByAscendingIsCorrect { [_query orderByField:QKTestFieldOne descending:NO]; + NSString *query = [NSString stringWithFormat:@"ORDER BY `%@` ASC", QKTestFieldOne]; + + STAssertTrue([[_query query] hasSuffix:query], @"select query order by"); +} + +- (void)testSelectQueryOrderByAscendingWithoutQuotesIsCorrect +{ + [_query setUseQuotes:NO]; + [_query orderByField:QKTestFieldOne descending:NO]; + NSString *query = [NSString stringWithFormat:@"ORDER BY %@ ASC", QKTestFieldOne]; - STAssertTrue([[_query query] hasSuffix:query], @"query order by"); + STAssertTrue([[_query query] hasSuffix:query], @"select query order by without quotes"); } - (void)testSelectQueryOrderByMultipleFieldsAscendingIsCorrect { [_query orderByFields:[NSArray arrayWithObjects:QKTestFieldOne, QKTestFieldTwo, nil] descending:NO]; + NSString *query = [NSString stringWithFormat:@"ORDER BY `%@`, `%@` ASC", QKTestFieldOne, QKTestFieldTwo]; + + STAssertTrue([[_query query] hasSuffix:query], @"select query order by multiple fields ascending when quoted"); +} + +- (void)testSelectQueryOrderByMultipleFieldsAscendingWithoutQuotesIsCorrect +{ + [_query setUseQuotes:NO]; + [_query orderByFields:[NSArray arrayWithObjects:QKTestFieldOne, QKTestFieldTwo, nil] descending:NO]; + NSString *query = [NSString stringWithFormat:@"ORDER BY %@, %@ ASC", QKTestFieldOne, QKTestFieldTwo]; - STAssertTrue([[_query query] hasSuffix:query], @"query order by"); + STAssertTrue([[_query query] hasSuffix:query], @"select query order by multiple fields ascending without quotes"); } - (void)testSelectQueryOrderByDescendingIsCorrect { [_query orderByField:QKTestFieldOne descending:YES]; + NSString *query = [NSString stringWithFormat:@"ORDER BY `%@` DESC", QKTestFieldOne]; + + STAssertTrue([[_query query] hasSuffix:query], @"select query order by descending"); +} + +- (void)testSelectQueryOrderByDescendingWithoutQuotesIsCorrect +{ + [_query setUseQuotes:NO]; + [_query orderByField:QKTestFieldOne descending:YES]; + NSString *query = [NSString stringWithFormat:@"ORDER BY %@ DESC", QKTestFieldOne]; - STAssertTrue([[_query query] hasSuffix:query], @"query order by"); + STAssertTrue([[_query query] hasSuffix:query], @"select query order by descending without quotes"); } - (void)testSelectQueryOrderByMultipleFieldsDescendingIsCorrect { [_query orderByFields:[NSArray arrayWithObjects:QKTestFieldOne, QKTestFieldTwo, nil] descending:YES]; + NSString *query = [NSString stringWithFormat:@"ORDER BY `%@`, `%@` DESC", QKTestFieldOne, QKTestFieldTwo]; + + STAssertTrue([[_query query] hasSuffix:query], @"select query order by multiple fields descending"); +} + +- (void)testSelectQueryOrderByMultipleFieldsDescendingWithoutQuotesIsCorrect +{ + [_query setUseQuotes:NO]; + [_query orderByFields:[NSArray arrayWithObjects:QKTestFieldOne, QKTestFieldTwo, nil] descending:YES]; + NSString *query = [NSString stringWithFormat:@"ORDER BY %@, %@ DESC", QKTestFieldOne, QKTestFieldTwo]; - STAssertTrue([[_query query] hasSuffix:query], @"query order by"); + STAssertTrue([[_query query] hasSuffix:query], @"select query order by multiple fields descending without quotes"); } @end |