Skip to content

Commit

Permalink
fix hashing
Browse files Browse the repository at this point in the history
  • Loading branch information
dbstratta committed Oct 1, 2024
1 parent c34c36c commit b4bbace
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
5 changes: 0 additions & 5 deletions src/sync/question_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ impl QuestionData {
self.deduplicate();
self.check()?;

// We refresh the options' hashes because when we sort them, we change their references.
for question_option in &mut self.question_options {
question_option.refresh_hash();
}

self.refresh_hash();

Ok(())
Expand Down
11 changes: 5 additions & 6 deletions src/sync/question_option_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub struct QuestionOptionData {
pub question_id: Uuid,
pub text: String,
pub correct: bool,
#[medici(skip_hash)]
pub reference: u16,

pub hash: String,
Expand Down Expand Up @@ -44,6 +45,8 @@ impl QuestionOptionData {
self.format();
self.check()?;

self.refresh_hash();

Ok(())
}

Expand Down Expand Up @@ -111,13 +114,9 @@ mod tests {
let id = Uuid::new_v4();
let question_id = Uuid::new_v4();

let mut data_1 =
QuestionOptionData::new(id, question_id, "opt 1".into(), false, 0).unwrap();
data_1.refresh_hash();
let data_1 = QuestionOptionData::new(id, question_id, "opt 1".into(), false, 0).unwrap();

let mut data_2 =
QuestionOptionData::new(id, question_id, "opt 2".into(), false, 0).unwrap();
data_2.refresh_hash();
let data_2 = QuestionOptionData::new(id, question_id, "opt 2".into(), false, 0).unwrap();

assert_ne!(data_1.hash, data_2.hash);
}
Expand Down

0 comments on commit b4bbace

Please sign in to comment.