Skip to content

Commit e048bd2

Browse files
authored
Merge f45311c into 5a9ec53
2 parents 5a9ec53 + f45311c commit e048bd2

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

Firestore/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# v8.6.0
22
- [changed] Internal refactor to improve serialization performance.
3+
- [changed] `DocumentSnapshot` objects consider the document's key and data for
4+
equality comparison, but ignore the internal state and internal version.
35

46
# v8.4.0
57
- [fixed] Fixed handling of Unicode characters in log and assertion messages

Firestore/Example/Tests/Integration/API/FIRDatabaseTests.mm

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,36 @@ - (void)testCanUpdateAnExistingDocument {
6060
XCTAssertEqualObjects(result.data, finalData);
6161
}
6262

63+
- (void)testEqualityComparison {
64+
FIRDocumentReference *doc = [self.db documentWithPath:@"rooms/eros"];
65+
NSDictionary<NSString *, id> *initialData =
66+
@{@"desc" : @"Description", @"owner" : @{@"name" : @"Jonny", @"email" : @"[email protected]"}};
67+
68+
[self writeDocumentRef:doc data:initialData];
69+
70+
FIRDocumentSnapshot *snap1 = [self readDocumentForRef:doc];
71+
FIRDocumentSnapshot *snap2 = [self readDocumentForRef:doc];
72+
FIRDocumentSnapshot *snap3 = [self readDocumentForRef:doc];
73+
74+
XCTAssertTrue([snap1.metadata isEqual:snap2.metadata]);
75+
XCTAssertTrue([snap2.metadata isEqual:snap3.metadata]);
76+
77+
XCTAssertTrue([snap1.documentID isEqual:snap2.documentID]);
78+
XCTAssertTrue([snap2.documentID isEqual:snap3.documentID]);
79+
80+
XCTAssertTrue(snap1.exists == snap2.exists);
81+
XCTAssertTrue(snap2.exists == snap3.exists);
82+
83+
XCTAssertTrue([snap1.reference isEqual:snap2.reference]);
84+
XCTAssertTrue([snap2.reference isEqual:snap3.reference]);
85+
86+
XCTAssertTrue([[snap1 data] isEqual:[snap2 data]]);
87+
XCTAssertTrue([[snap2 data] isEqual:[snap3 data]]);
88+
89+
XCTAssertTrue([snap1 isEqual:snap2]);
90+
XCTAssertTrue([snap2 isEqual:snap3]);
91+
}
92+
6393
- (void)testCanUpdateAnUnknownDocument {
6494
[self readerAndWriterOnDocumentRef:^(FIRDocumentReference *readerRef,
6595
FIRDocumentReference *writerRef) {

Firestore/core/src/api/document_snapshot.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ absl::optional<google_firestore_v1_Value> DocumentSnapshot::GetValue(
8888
bool operator==(const DocumentSnapshot& lhs, const DocumentSnapshot& rhs) {
8989
return lhs.firestore_ == rhs.firestore_ &&
9090
lhs.internal_key_ == rhs.internal_key_ &&
91-
lhs.internal_document_ == rhs.internal_document_ &&
91+
lhs.exists() == rhs.exists() &&
92+
(lhs.exists() ? lhs.internal_document_->get().data() ==
93+
rhs.internal_document_->get().data()
94+
: true) &&
9295
lhs.metadata_ == rhs.metadata_;
9396
}
9497

Firestore/core/src/model/mutable_document.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class MutableDocument {
167167
return value_->Get();
168168
}
169169

170-
ObjectValue& data() {
170+
ObjectValue& data() const {
171171
return *value_;
172172
}
173173

0 commit comments

Comments
 (0)