Skip to content

Commit

Permalink
Add test case for non-copy primary key that rely on serialize_as
Browse files Browse the repository at this point in the history
  • Loading branch information
Aethelflaed committed Aug 30, 2024
1 parent f17db14 commit 119efdc
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions diesel_derives/tests/identifiable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,26 @@ fn derive_identifiable_with_pk_serialize_as() {
assert_eq!(MyI32(1), foo1.id());
assert_eq!(MyI32(2), foo2.id());
}

#[test]
fn derive_identifiable_with_non_copy_pk_serialize() {
#[derive(Debug, PartialEq, Eq, Hash)]
struct MyString(String);

impl From<String> for MyString {
fn from(value: String) -> Self {
MyString(value)
}
}

#[derive(Identifiable)]
struct Foo {
#[diesel(serialize_as = MyString)]
id: String,
}

let foo1 = Foo { id: "1".to_owned() };
let foo2 = Foo { id: "2".to_owned() };
assert_eq!(MyString("1".to_owned()), foo1.id());
assert_eq!(MyString("2".to_owned()), foo2.id());
}

0 comments on commit 119efdc

Please sign in to comment.