@@ -483,44 +483,35 @@ public void shouldGenerateCorrectInsertSQL() {
483
483
insertSQL = s .toInsert (new SimpleFormatter (java .sql .Date .class , "to_date('" , "')" ));
484
484
the (insertSQL ).shouldBeEqual ("INSERT INTO students (dob, first_name, id, last_name) VALUES (to_date('1965-12-01'), 'Jim', 1, 'Cary')" );
485
485
}
486
-
486
+
487
487
@ Test
488
- public void shouldGenerateCorrectUpdateSQL () {
489
-
490
- // Create the student
488
+ public void shouldGenerateValidUpdateSQL () {
491
489
deleteAndPopulateTable ("students" );
492
- Student s = new Student ();
493
- s .set ("first_name" , "Jim" );
494
- s .set ("last_name" , "Cary" );
495
- s .set ("dob" , new java .sql .Date (getDate (1965 , 12 , 1 ).getTime ()));
496
- s .set ("id" , 1 );
497
- s .saveIt ();
498
-
499
- // find them, and change a column
500
- s = Student .findById (1 );
501
- s .set ("first_name" , "Drew" );
502
- s .saveIt ();
503
- String updateSQL = s .toUpdate ();
504
- Base .exec (updateSQL );
505
-
506
- // Find them again
507
- s = Student .findById (1 );
490
+ Student s = Student .findById (1 );
491
+ s .set ("first_name" , "James" , "last_name" , "Meredith" );
492
+ java .sql .Date dob = getDate (1933 , 6 , 25 );
493
+ java .sql .Timestamp enrollmentDate = getTimestamp (1962 , 10 , 1 , 12 , 0 , 0 , 0 );
494
+ s .setDate ("dob" , dob );
495
+ s .setTimestamp ("enrollment_date" , enrollmentDate );
496
+ // don't save it!
497
+
498
+ String updateSql = s .toUpdate ();
499
+ the (Base .exec (updateSql )).shouldBeEqual (1 );
508
500
509
- // Verify that the first name column changed
510
- the (s .get ("first_name" )).shouldBeEqual ("Drew" );
511
- System .out .println (updateSQL );
512
-
501
+ s = Student .findById (1 );
502
+ the (s .get ("first_name" )).shouldBeEqual ("James" );
503
+ the (s .get ("last_name" )).shouldBeEqual ("Meredith" );
504
+ the (s .get ("dob" )).shouldBeEqual (dob );
505
+ the (s .get ("enrollment_date" )).shouldBeEqual (enrollmentDate );
513
506
}
514
-
515
- @ Test (expected = NoSuchElementException .class )
507
+
508
+ @ Test (expected = NoSuchElementException .class )
516
509
public void shouldGenerateNoSuchElementFromBlankUpdate () {
517
510
// Verify that a model with no attributes throws an error
518
511
Student s = new Student ();
519
- s .saveIt ();
520
512
s .toUpdate ();
521
513
}
522
514
523
-
524
515
@ Test
525
516
public void shouldGenerateValidInsertSQL () {
526
517
Student s = new Student ();
@@ -531,7 +522,6 @@ public void shouldGenerateValidInsertSQL() {
531
522
s .setTimestamp ("enrollment_date" , enrollmentDate );
532
523
533
524
String insertSql = s .toInsert ();
534
- System .out .println (insertSql );
535
525
Object id = Base .execInsert (insertSql , s .getIdName ());
536
526
537
527
s = Student .findById (id );
0 commit comments