Skip to content

Commit 2778920

Browse files
committed
add: add a test for now in MySQL
1 parent ef9aec4 commit 2778920

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

diesel_tests/tests/expressions/date_and_time.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,32 @@ fn today_executes_sql_function_current_date() {
229229
assert_eq!(Ok(vec![2]), after_today);
230230
}
231231

232+
#[test]
233+
#[cfg(feature = "mysql")]
234+
fn now_executes_sql_function_now() {
235+
use self::has_timestamps::dsl::*;
236+
237+
let connection = connection();
238+
setup_test_table(&connection);
239+
connection
240+
.execute(
241+
"INSERT INTO has_timestamps (created_at) VALUES
242+
(NOW() - interval 1 day), (NOW() + interval 1 day)",
243+
)
244+
.unwrap();
245+
246+
let before_today = has_timestamps
247+
.select(id)
248+
.filter(created_at.lt(now))
249+
.load::<i32>(&connection);
250+
let after_today = has_timestamps
251+
.select(id)
252+
.filter(created_at.gt(now))
253+
.load::<i32>(&connection);
254+
assert_eq!(Ok(vec![1]), before_today);
255+
assert_eq!(Ok(vec![2]), after_today);
256+
}
257+
232258
#[test]
233259
#[cfg(feature = "sqlite")]
234260
fn now_executes_sql_function_now() {
@@ -254,7 +280,6 @@ fn now_executes_sql_function_now() {
254280
assert_eq!(Ok(vec![1]), before_today);
255281
assert_eq!(Ok(vec![2]), after_today);
256282
}
257-
258283
#[test]
259284
#[cfg(not(feature = "mysql"))] // FIXME: Figure out how to handle tests that modify schema
260285
fn date_uses_sql_function_date() {

0 commit comments

Comments
 (0)