Improve isolation of Record tests

This commit is contained in:
Gwendal Roué committed 2015-09-15 07:19:05 +02:00
1 parent 4cacbffb4b
commit 2d936037f5
18 files changed
+164 -51

No files matched your search

@@ -25,7 +25,17 @@ class MinimalRowID: Record {
}
}
class MinimalPrimaryKeyRowIDTests: RecordTestCase {
class MinimalPrimaryKeyRowIDTests: GRDBTestCase {
override func setUp() {
super.setUp()
var migrator = DatabaseMigrator()
migrator.registerMigration("createMinimalRowID", MinimalRowID.setupInDatabase)
assertNoError {
try migrator.migrate(dbQueue)
}
}
// MARK: - Insert
@@ -25,7 +25,17 @@ class MinimalSingle: Record {
}
}
class MinimalPrimaryKeySingleTests: RecordTestCase {
class MinimalPrimaryKeySingleTests: GRDBTestCase {
override func setUp() {
super.setUp()
var migrator = DatabaseMigrator()
migrator.registerMigration("createMinimalSingle", MinimalSingle.setupInDatabase)
assertNoError {
try migrator.migrate(dbQueue)
}
}
// MARK: - Insert
@@ -48,7 +48,17 @@ class Citizenship: Record {
}
class PrimaryKeyMultipleTests: RecordTestCase {
class PrimaryKeyMultipleTests: GRDBTestCase {
override func setUp() {
super.setUp()
var migrator = DatabaseMigrator()
migrator.registerMigration("createCitizenship", Citizenship.setupInDatabase)
assertNoError {
try migrator.migrate(dbQueue)
}
}
// MARK: - Insert
@@ -35,7 +35,17 @@ class Item: Record {
}
}
class PrimaryKeyNoneTests: RecordTestCase {
class PrimaryKeyNoneTests: GRDBTestCase {
override func setUp() {
super.setUp()
var migrator = DatabaseMigrator()
migrator.registerMigration("createItem", Item.setupInDatabase)
assertNoError {
try migrator.migrate(dbQueue)
}
}
// MARK: - Insert
@@ -61,7 +61,17 @@ class Person: Record {
}
}
class PrimaryKeyRowIDTests: RecordTestCase {
class PrimaryKeyRowIDTests: GRDBTestCase {
override func setUp() {
super.setUp()
var migrator = DatabaseMigrator()
migrator.registerMigration("createPerson", Person.setupInDatabase)
assertNoError {
try migrator.migrate(dbQueue)
}
}
// MARK: - Insert
@@ -41,7 +41,17 @@ class Pet: Record {
}
}
class PrimaryKeySingleTests: RecordTestCase {
class PrimaryKeySingleTests: GRDBTestCase {
override func setUp() {
super.setUp()
var migrator = DatabaseMigrator()
migrator.registerMigration("createPet", Pet.setupInDatabase)
assertNoError {
try migrator.migrate(dbQueue)
}
}
// MARK: - Insert
@@ -18,19 +18,23 @@ class Email : Record {
if let dbv = row["label"] { label = dbv.value() }
super.updateFromRow(row) // Subclasses are required to call super.
}
static func setupInDatabase(db: Database) throws {
try db.execute(
"CREATE TABLE emails (" +
"email TEXT NOT NULL PRIMARY KEY ON CONFLICT REPLACE, " +
"label TEXT " +
")")
}
}
class PrimaryKeySingleWithReplaceConflictResolutionTests: RecordTestCase {
class PrimaryKeySingleWithReplaceConflictResolutionTests: GRDBTestCase {
override func setUp() {
super.setUp()
var migrator = DatabaseMigrator()
migrator.registerMigration("createAddresses") { db in
try db.execute("CREATE TABLE emails (email TEXT NOT NULL PRIMARY KEY ON CONFLICT REPLACE, label TEXT)")
}
migrator.registerMigration("createEmail", Email.setupInDatabase)
assertNoError {
try migrator.migrate(dbQueue)
}
@@ -22,10 +22,24 @@ class EventRecorder : Record {
super.awakeFromFetch(row)
awakeFromFetchCount += 1
}
static func setupInDatabase(db: Database) throws {
try db.execute("CREATE TABLE eventRecorders (id INTEGER PRIMARY KEY)")
}
}
class RecordEventsTests: GRDBTestCase {
override func setUp() {
super.setUp()
var migrator = DatabaseMigrator()
migrator.registerMigration("createEventRecorder", EventRecorder.setupInDatabase)
assertNoError {
try migrator.migrate(dbQueue)
}
}
func testAwakeFromFetchIsNotTriggeredByInit() {
let record = EventRecorder()
XCTAssertEqual(record.awakeFromFetchCount, 0)
@@ -39,7 +53,6 @@ class RecordEventsTests: GRDBTestCase {
func testAwakeFromFetchIsTriggeredByFetch() {
assertNoError {
try dbQueue.inDatabase { db in
try db.execute("CREATE TABLE eventRecorders (id INTEGER PRIMARY KEY)")
do {
let record = EventRecorder()
try record.insert(db)
@@ -53,7 +66,6 @@ class RecordEventsTests: GRDBTestCase {
func testAwakeFromFetchIsTriggeredByReload() {
assertNoError {
try dbQueue.inDatabase { db in
try db.execute("CREATE TABLE eventRecorders (id INTEGER PRIMARY KEY)")
try EventRecorder().insert(db)
do {
let record = EventRecorder.fetchOne(db, "SELECT * FROM eventRecorders")!
@@ -1,7 +1,7 @@
import XCTest
import GRDB
class RecordCopyTests: RecordTestCase {
class RecordCopyTests: GRDBTestCase {
func testRecordCopy() {
let person1 = Person(id: 123, name: "Arthur", age: 41, creationDate: NSDate())
@@ -21,7 +21,7 @@ class DoubleColumnRecord : Record {
}
}
class RecordDescriptionTests: RecordTestCase {
class RecordDescriptionTests: GRDBTestCase {
func testRecordWithoutStoredDatabaseDictionaryDescription() {
let record = RecordWithoutStoredDatabaseDictionary()
@@ -14,7 +14,18 @@ class IntegerPropertyOnRealAffinityColumn : Record {
}
}
class RecordEditedTests: RecordTestCase {
class RecordEditedTests: GRDBTestCase {
override func setUp() {
super.setUp()
var migrator = DatabaseMigrator()
migrator.registerMigration("createPerson", Person.setupInDatabase)
assertNoError {
try migrator.migrate(dbQueue)
}
}
func testRecordIsEditedAfterInit() {
// Create a Record. No fetch has happen, so we don't know if it is
@@ -1,6 +1,18 @@
import XCTest
import GRDB
class RecordFetchTests: RecordTestCase {
class RecordFetchTests: GRDBTestCase {
override func setUp() {
super.setUp()
var migrator = DatabaseMigrator()
migrator.registerMigration("createPerson", Person.setupInDatabase)
assertNoError {
try migrator.migrate(dbQueue)
}
}
func testSelectStatement() {
assertNoError {
@@ -93,7 +93,7 @@ class RecordWithImmutablePropertyAndCustomInitializer : Record {
}
}
class RecordInitializersTests : RecordTestCase {
class RecordInitializersTests : GRDBTestCase {
func testFetchedRecordAreInitializedFromRow() {
@@ -26,7 +26,17 @@ class PersonWithOverrides: Person {
}
}
class RecordSubClassTests: RecordTestCase {
class RecordSubClassTests: GRDBTestCase {
override func setUp() {
super.setUp()
var migrator = DatabaseMigrator()
migrator.registerMigration("createPerson", Person.setupInDatabase)
assertNoError {
try migrator.migrate(dbQueue)
}
}
// MARK: - Save
@@ -1,21 +0,0 @@
import XCTest
import GRDB
class RecordTestCase : GRDBTestCase {
override func setUp() {
super.setUp()
var migrator = DatabaseMigrator()
migrator.registerMigration("createPersons", Person.setupInDatabase)
migrator.registerMigration("createPets", Pet.setupInDatabase)
migrator.registerMigration("createItems", Item.setupInDatabase)
migrator.registerMigration("createCitizenships", Citizenship.setupInDatabase)
migrator.registerMigration("createMinimalRowIDs", MinimalRowID.setupInDatabase)
migrator.registerMigration("createMinimalSingles", MinimalSingle.setupInDatabase)
assertNoError {
try migrator.migrate(dbQueue)
}
}
}
@@ -61,9 +61,29 @@ class Placemark : Record {
// Subclasses are required to call super.
super.updateFromRow(row)
}
static func setupInDatabase(db: Database) throws {
try db.execute(
"CREATE TABLE placemarks (" +
"id INTEGER PRIMARY KEY, " +
"name TEXT, " +
"latitude REAL, " +
"longitude REAL" +
")")
}
}
class RecordUpdateFromRowTests: RecordTestCase {
class RecordUpdateFromRowTests: GRDBTestCase {
override func setUp() {
super.setUp()
var migrator = DatabaseMigrator()
migrator.registerMigration("createPlacemark", Placemark.setupInDatabase)
assertNoError {
try migrator.migrate(dbQueue)
}
}
func testInitFromRow() {
let parisLatitude = 48.8534100
@@ -106,7 +126,6 @@ class RecordUpdateFromRowTests: RecordTestCase {
let parisLongitude = 2.3488000
assertNoError {
try dbQueue.inDatabase { db in
try db.execute("CREATE TABLE placemarks (id INTEGER PRIMARY KEY, name TEXT, latitude REAL, longitude REAL)")
try db.execute("INSERT INTO placemarks (name, latitude, longitude) VALUES (?,?,?)", arguments: ["Paris", parisLatitude, parisLongitude])
let paris = Placemark.fetchOne(db, "SELECT * FROM placemarks")!
XCTAssertEqual(paris.name!, "Paris")
@@ -121,7 +140,6 @@ class RecordUpdateFromRowTests: RecordTestCase {
let parisLongitude = 2.3488000
assertNoError {
try dbQueue.inDatabase { db in
try db.execute("CREATE TABLE placemarks (id INTEGER PRIMARY KEY, name TEXT, latitude REAL, longitude REAL)")
try db.execute("INSERT INTO placemarks (name, latitude, longitude) VALUES (?,?,?)", arguments: ["Paris", parisLatitude, parisLongitude])
let paris = Placemark.fetchOne(db, "SELECT * FROM placemarks")!
paris.coordinate = nil
@@ -24,14 +24,27 @@ class BadlyMangledStuff : Record {
if let dbv = row["mangled_name"] { name = dbv.value() }
super.updateFromRow(row)
}
static func setupInDatabase(db: Database) throws {
try db.execute("CREATE TABLE stuffs (id INTEGER PRIMARY KEY, name TEXT)")
}
}
class RecordWithColumnNameManglingTests: GRDBTestCase {
override func setUp() {
super.setUp()
var migrator = DatabaseMigrator()
migrator.registerMigration("createBadlyMangledStuff", BadlyMangledStuff.setupInDatabase)
assertNoError {
try migrator.migrate(dbQueue)
}
}
func testBadlyMangledStuff() {
assertNoError {
try dbQueue.inDatabase { db in
try db.execute("CREATE TABLE stuffs (id INTEGER PRIMARY KEY, name TEXT)")
do {
let record = BadlyMangledStuff()
record.name = "foo"
-6
View File
@@ -72,8 +72,6 @@
56A238681B9C74A90082EB20 /* RecordInitializersTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238321B9C74A90082EB20 /* RecordInitializersTests.swift */; settings = {ASSET_TAGS = (); }; };
56A238691B9C74A90082EB20 /* RecordSubClassTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238331B9C74A90082EB20 /* RecordSubClassTests.swift */; settings = {ASSET_TAGS = (); }; };
56A2386A1B9C74A90082EB20 /* RecordSubClassTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238331B9C74A90082EB20 /* RecordSubClassTests.swift */; settings = {ASSET_TAGS = (); }; };
56A2386B1B9C74A90082EB20 /* RecordTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238341B9C74A90082EB20 /* RecordTestCase.swift */; settings = {ASSET_TAGS = (); }; };
56A2386C1B9C74A90082EB20 /* RecordTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238341B9C74A90082EB20 /* RecordTestCase.swift */; settings = {ASSET_TAGS = (); }; };
56A2386D1B9C74A90082EB20 /* RecordUpdateFromRowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238351B9C74A90082EB20 /* RecordUpdateFromRowTests.swift */; settings = {ASSET_TAGS = (); }; };
56A2386E1B9C74A90082EB20 /* RecordUpdateFromRowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238351B9C74A90082EB20 /* RecordUpdateFromRowTests.swift */; settings = {ASSET_TAGS = (); }; };
56A2387B1B9C75030082EB20 /* Configuration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56A238701B9C75030082EB20 /* Configuration.swift */; settings = {ASSET_TAGS = (); }; };
@@ -193,7 +191,6 @@
56A238311B9C74A90082EB20 /* RecordFetchTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordFetchTests.swift; sourceTree = "<group>"; };
56A238321B9C74A90082EB20 /* RecordInitializersTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordInitializersTests.swift; sourceTree = "<group>"; };
56A238331B9C74A90082EB20 /* RecordSubClassTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordSubClassTests.swift; sourceTree = "<group>"; };
56A238341B9C74A90082EB20 /* RecordTestCase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordTestCase.swift; sourceTree = "<group>"; };
56A238351B9C74A90082EB20 /* RecordUpdateFromRowTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordUpdateFromRowTests.swift; sourceTree = "<group>"; };
56A238701B9C75030082EB20 /* Configuration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Configuration.swift; sourceTree = "<group>"; };
56A238711B9C75030082EB20 /* Database.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Database.swift; sourceTree = "<group>"; };
@@ -419,7 +416,6 @@
56A238311B9C74A90082EB20 /* RecordFetchTests.swift */,
56A238321B9C74A90082EB20 /* RecordInitializersTests.swift */,
56A238331B9C74A90082EB20 /* RecordSubClassTests.swift */,
56A238341B9C74A90082EB20 /* RecordTestCase.swift */,
56A238351B9C74A90082EB20 /* RecordUpdateFromRowTests.swift */,
56A5E4081BA2BCF900707640 /* RecordWithColumnNameManglingTests.swift */,
);
@@ -801,7 +797,6 @@
56A238501B9C74A90082EB20 /* MinimalPrimaryKeyRowIDTests.swift in Sources */,
56AC8CCF1BA3F2AD009E4319 /* ConcurrencyTests.swift in Sources */,
56A238461B9C74A90082EB20 /* DictionaryRowTests.swift in Sources */,
56A2386C1B9C74A90082EB20 /* RecordTestCase.swift in Sources */,
56A2384A1B9C74A90082EB20 /* SelectStatementTests.swift in Sources */,
56A2384C1B9C74A90082EB20 /* UpdateStatementTests.swift in Sources */,
56A2384E1B9C74A90082EB20 /* DatabaseMigratorTests.swift in Sources */,
@@ -843,7 +838,6 @@
56A2384F1B9C74A90082EB20 /* MinimalPrimaryKeyRowIDTests.swift in Sources */,
56AC8CCE1BA3F2AD009E4319 /* ConcurrencyTests.swift in Sources */,
56A238451B9C74A90082EB20 /* DictionaryRowTests.swift in Sources */,
56A2386B1B9C74A90082EB20 /* RecordTestCase.swift in Sources */,
56A238491B9C74A90082EB20 /* SelectStatementTests.swift in Sources */,
56A2384B1B9C74A90082EB20 /* UpdateStatementTests.swift in Sources */,
56A2384D1B9C74A90082EB20 /* DatabaseMigratorTests.swift in Sources */,