Skip to content

Commit

Permalink
add test and fix behaviour (#551)
Browse files Browse the repository at this point in the history
  • Loading branch information
do4gr committed Mar 4, 2020
1 parent 56d82f1 commit 0a835f6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Expand Up @@ -164,3 +164,35 @@ async fn introspecting_a_table_with_enum_default_values_should_work(api: &TestAp
let result = dbg!(api.introspect().await);
custom_assert(&result, dm);
}

#[test_each_connector(tags("postgres"))]
async fn introspecting_a_table_with_enum_default_values_that_look_like_booleans_should_work(api: &TestApi) {
let sql = format!("CREATE Type Truth as ENUM ( 'true', 'false', 'rumor')");

api.database().execute_raw(&sql, &[]).await.unwrap();

api.barrel()
.execute(|migration| {
migration.create_table("News", |t| {
t.add_column("id", types::primary());
t.inject_custom("confirmed truth Not Null default 'true'");
});
})
.await;

let dm = r#"
model News {
confirmed truth @default(true)
id Int @default(autoincrement()) @id
}
enum truth{
false
rumor
true
}
"#;

let result = dbg!(api.introspect().await);
custom_assert(&result, dm);
}
1 change: 1 addition & 0 deletions libs/datamodel/core/src/common/value_validator.rs
Expand Up @@ -182,6 +182,7 @@ impl ValueValidator {
pub fn as_constant_literal(&self) -> Result<String, DatamodelError> {
match &self.value {
ast::Expression::ConstantValue(value, _) => Ok(value.to_string()),
ast::Expression::BooleanValue(value, _) => Ok(value.to_string()),
ast::Expression::Any(value, _) => Ok(value.to_string()),
_ => Err(self.construct_type_mismatch_error("constant literal")),
}
Expand Down

0 comments on commit 0a835f6

Please sign in to comment.