fix that AcceptNewFields does not take into account the primary-key; fix #518

This commit is contained in:
qdequele 2020-03-11 12:00:40 +01:00
parent 14c1aba6c7
commit c25641ff2d
No known key found for this signature in database
GPG Key ID: B3F0A000EBF11745
2 changed files with 63 additions and 2 deletions

View File

@ -288,3 +288,62 @@ fn index_new_fields_false_then_true() {
assert_eq!(status_code, 200);
assert_json_eq!(response, expected);
}
// Fix issue https://github.com/meilisearch/MeiliSearch/issues/518
#[test]
fn accept_new_fields_does_not_take_into_account_the_primary_key () {
let mut server = common::Server::with_uid("movies");
// 1 - Create an index with no primary-key
let body = json!({
"uid": "movies",
});
let (response, status_code) = server.create_index(body);
assert_eq!(status_code, 201);
assert_eq!(response["primaryKey"], json!(null));
// 2 - Add searchable and displayed attributes as: ["title"] & Set acceptNewFields to false
let body = json!({
"searchableAttributes": ["title"],
"displayedAttributes": ["title"],
"acceptNewFields": false,
});
server.update_all_settings(body);
// 4 - Add a document
let body = json!([{
"id": 1,
"title": "Test",
"comment": "comment test"
}]);
server.add_or_replace_multiple_documents(body);
// 5 - Get settings, they should not changed
let (response, _status_code) = server.get_all_settings();
let expected = json!({
"rankingRules": [
"typo",
"words",
"proximity",
"attribute",
"wordsPosition",
"exactness",
],
"distinctAttribute": null,
"searchableAttributes": ["title"],
"displayedAttributes": ["title"],
"stopWords": [],
"synonyms": {},
"acceptNewFields": false,
});
assert_json_eq!(response, expected, ordered: false);
}

View File

@ -63,8 +63,10 @@ impl Schema {
let id = self.insert(name)?;
self.primary_key = Some(id);
self.set_indexed(name)?;
self.set_displayed(name)?;
if self.accept_new_fields {
self.set_indexed(name)?;
self.set_displayed(name)?;
}
Ok(id)
}