Skip to content

Commit

Permalink
Add missing validation for observing unmanaged LinkingObjects
Browse files Browse the repository at this point in the history
This isn't supported, but we crashed rather than throwing a useful exception.
  • Loading branch information
tgoyne committed Jun 28, 2019
1 parent 93fca58 commit 2ca7372
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ x.y.z Release notes (yyyy-MM-dd)
* Add support for including Realm via Swift Package Manager.

### Fixed
* <How to hit and notice issue? what was the impact?> ([#????](https://github.com/realm/realm-js/issues/????), since v?.?.?)
* None.
* Attempting to observe an unmanaged LinkingObjects object crashed rather than
throwing an approriate exception (since v0.100.0).

<!-- ### Breaking Changes - ONLY INCLUDE FOR NEW MAJOR version -->

Expand Down
3 changes: 3 additions & 0 deletions Realm/RLMResults.mm
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,9 @@ - (RLMFastEnumerator *)fastEnumerator {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmismatched-parameter-types"
- (RLMNotificationToken *)addNotificationBlock:(void (^)(RLMResults *, RLMCollectionChange *, NSError *))block {
if (!_realm) {
@throw RLMException(@"Linking objects notifications are only supported on managed objects.");
}
[_realm verifyNotificationsAreSupported:true];
return RLMAddNotificationBlock(self, _results, block, true);
}
Expand Down
3 changes: 3 additions & 0 deletions Realm/Tests/LinkingObjectsTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ - (void)testLinkingObjectsOnUnmanagedObject {
PersonObject *mark = [[PersonObject alloc] initWithValue:@[ @"Mark", @30, @[] ]];
XCTAssertEqual(NSNotFound, [don.parents indexOfObject:mark]);
XCTAssertEqual(NSNotFound, [don.parents indexOfObjectWhere:@"TRUEPREDICATE"]);

RLMAssertThrowsWithReason(([don.parents addNotificationBlock:^(RLMResults *, RLMCollectionChange *, NSError *) { }]),
@"Linking objects notifications are only supported on managed objects.");
}

- (void)testFilteredLinkingObjects {
Expand Down

0 comments on commit 2ca7372

Please sign in to comment.