Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests for new migration from RLMObject to RLMEmbeddedObject #7094

Merged
merged 5 commits into from
Mar 2, 2021

Conversation

DominicFrei
Copy link
Contributor

@DominicFrei DominicFrei commented Feb 4, 2021

Tests on our side for the changed embedded table functionality introduced by realm/realm-core#4414.

@DominicFrei DominicFrei self-assigned this Feb 4, 2021
@DominicFrei DominicFrei marked this pull request as ready for review March 1, 2021 17:44
@DominicFrei DominicFrei requested review from jsflax and tgoyne March 1, 2021 17:44
@DominicFrei DominicFrei changed the title Fix migration when converting RLMObject to RLMEmbeddedObject Tests for new migration from RLMObject to RLMEmbeddedObject Mar 1, 2021
@DominicFrei DominicFrei merged commit 54cb8ac into master Mar 2, 2021
@DominicFrei DominicFrei deleted the df/changing-embeddedness-of-types branch March 2, 2021 13:54
@@ -1398,6 +1398,390 @@ - (void)testModifyPrimaryKeyInMigration {
}
}

- (void)testChangeEmptyTableFromTopLevelToEmbedded {
RLMProperty *intProperty = [[RLMProperty alloc] initWithName:@"intProperty"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than manually defining the base schema, this should just define a normal subclass and use that for the initial schema (or reuse an existing type if possible). The general pattern these tests should take is obtain schema from classes with schemaForObjectClass:, mutate a second copy of the schema to match the thing being tested, then call assertMigrationRequiredForChangeFrom:to: which initializes the Realm with the initial schema, verifies that the schema version has to be bumped to migrate to the new schema, and then verifies that the tables are in the correct state after migrating to the new schema.

The tests which actually have a migration block should use createTestRealmWithSchema : + migrateTestRealmWithBlock:

XCTAssertNotNil(oldObject);
XCTAssertNotNil(newObject);
XCTAssertEqual(oldObject[@"childProperty"][@"intProperty"], newObject[@"childProperty"][@"intProperty"]);
XCTAssert([newObject[@"childProperty"][@"intProperty"] intValue] == 42 || [newObject[@"childProperty"][@"intProperty"] intValue] == 43);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should read the value to a local variable rather than duplicating all that stuff.

XCTAssertNotNil(oldObject);
XCTAssertNotNil(newObject);
XCTAssertEqual([oldObject[@"intProperty"] intValue], [newObject[@"intProperty"] intValue]);
XCTAssert([newObject[@"intProperty"] intValue] == 42);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

XCTAssertEqual

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants