mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-27 04:14:21 +00:00
Test that RowModel.isEdited is false after a RowModel has been initialized with a row that is wider than its storedDatabaseDictionary.
This commit is contained in:
1 parent
be35124b9a
commit
1eb5c2c9c1
4 files changed
+25
-18
No files matched your search
@@ -48,6 +48,20 @@ class RowModelIsEditedTests: RowModelTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
func testRowModelIsNotEditedAfterWiderThanFullFetch() {
|
||||
// Fetch a model from a row that contains all the columns in
|
||||
// storedDatabaseDictionary, plus extra ones: An update statement, which
|
||||
// only saves the columns in storedDatabaseDictionary would perform no
|
||||
// change. So the model is not edited.
|
||||
assertNoError {
|
||||
try dbQueue.inDatabase { db in
|
||||
try Person(name: "Arthur", age: 41).insert(db)
|
||||
let person = db.fetchOne(Person.self, "SELECT *, 1 AS foo FROM persons")!
|
||||
XCTAssertFalse(person.isEdited)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testRowModelIsEditedAfterPartialFetch() {
|
||||
// Fetch a model from a row that does not contain all the columns in
|
||||
// storedDatabaseDictionary: An update statement saves the columns in
|
||||
|
||||
@@ -248,21 +248,6 @@ public struct Row: CollectionType {
|
||||
}
|
||||
}
|
||||
|
||||
func containsSameColumnsAndValuesAsRow(other: Row) -> Bool {
|
||||
guard count == other.count else {
|
||||
return true
|
||||
}
|
||||
for (key, dbv) in self {
|
||||
guard let otherDbv = other[key] else {
|
||||
return true
|
||||
}
|
||||
if dbv != otherDbv {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
// MARK: - DictionaryRowImpl
|
||||
|
||||
|
||||
+11
-2
@@ -189,8 +189,17 @@ public class RowModel {
|
||||
return true
|
||||
}
|
||||
|
||||
let currentRow = Row(dictionary: storedDatabaseDictionary)
|
||||
return referenceRow.containsSameColumnsAndValuesAsRow(currentRow)
|
||||
// All stored database values must match reference database values
|
||||
for (column, storedValue) in storedDatabaseDictionary {
|
||||
guard let referenceDatabaseValue = referenceRow[column] else {
|
||||
return true
|
||||
}
|
||||
let storedDatabaseValue = storedValue?.databaseValue ?? .Null
|
||||
if storedDatabaseValue != referenceDatabaseValue {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
- [ ] Fetch with a collection of primary keys: db.fetch(RowModel.type, primaryKeys:[...]). Problem: users will often want to sort, so the plain SELECT * FROM persons WHERE id IN (?,?,?) won't be appreciated. Needs more thought.
|
||||
- [ ] Let Bindings eat arrays, or make it easy to generate series of ?,?,?,?
|
||||
- [ ] Remove RowModelError.Dummy when rdar://problem/21707972 is fixed.
|
||||
- [ ] Test that RowModel.isEdited returns false when rowmodel is fetched with more columns that it stores.
|
||||
Reference in new issue
Block a user