@@ -393,7 +393,7 @@ public void testFindBySQL(){
393
393
}
394
394
395
395
@ Test
396
- public void testFrosen (){
396
+ public void testFrozen (){
397
397
deleteAndPopulateTables ("users" , "addresses" );
398
398
final User u = User .findById (1 );
399
399
final Address a = new Address ();
@@ -483,35 +483,44 @@ 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 shouldGenerateValidUpdateSQL () {
488
+ public void shouldGenerateCorrectUpdateSQL () {
489
+
490
+ // Create the student
489
491
deleteAndPopulateTable ("students" );
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 );
500
-
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
501
507
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 );
506
- }
507
508
508
- @ Test (expected = NoSuchElementException .class )
509
+ // Verify that the first name column changed
510
+ the (s .get ("first_name" )).shouldBeEqual ("Drew" );
511
+ System .out .println (updateSQL );
512
+
513
+ }
514
+
515
+ @ Test (expected =NoSuchElementException .class )
509
516
public void shouldGenerateNoSuchElementFromBlankUpdate () {
510
517
// Verify that a model with no attributes throws an error
511
518
Student s = new Student ();
519
+ s .saveIt ();
512
520
s .toUpdate ();
513
521
}
514
522
523
+
515
524
@ Test
516
525
public void shouldGenerateValidInsertSQL () {
517
526
Student s = new Student ();
@@ -522,6 +531,7 @@ public void shouldGenerateValidInsertSQL() {
522
531
s .setTimestamp ("enrollment_date" , enrollmentDate );
523
532
524
533
String insertSql = s .toInsert ();
534
+ System .out .println (insertSql );
525
535
Object id = Base .execInsert (insertSql , s .getIdName ());
526
536
527
537
s = Student .findById (id );
0 commit comments