Skip to content

Commit

Permalink
#383 Corrections in toUpdate() unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ericbn committed Mar 25, 2015
1 parent f76c76b commit 4a3a221
Showing 1 changed file with 19 additions and 29 deletions.
48 changes: 19 additions & 29 deletions activejdbc/src/test/java/org/javalite/activejdbc/ModelTest.java
Expand Up @@ -483,44 +483,35 @@ public void shouldGenerateCorrectInsertSQL() {
insertSQL = s.toInsert(new SimpleFormatter(java.sql.Date.class, "to_date('", "')"));
the(insertSQL).shouldBeEqual("INSERT INTO students (dob, first_name, id, last_name) VALUES (to_date('1965-12-01'), 'Jim', 1, 'Cary')");
}

@Test
public void shouldGenerateCorrectUpdateSQL() {

// Create the student
public void shouldGenerateValidUpdateSQL() {
deleteAndPopulateTable("students");
Student s = new Student();
s.set("first_name", "Jim");
s.set("last_name", "Cary");
s.set("dob", new java.sql.Date(getDate(1965, 12, 1).getTime()));
s.set("id", 1);
s.saveIt();

// find them, and change a column
s = Student.findById(1);
s.set("first_name", "Drew");
s.saveIt();
String updateSQL = s.toUpdate();
Base.exec(updateSQL);

// Find them again
s = Student.findById(1);
Student s = Student.findById(1);
s.set("first_name", "James", "last_name", "Meredith");
java.sql.Date dob = getDate(1933, 6, 25);
java.sql.Timestamp enrollmentDate = getTimestamp(1962, 10, 1, 12, 0, 0, 0);
s.setDate("dob", dob);
s.setTimestamp("enrollment_date", enrollmentDate);
// don't save it!

String updateSql = s.toUpdate();
the(Base.exec(updateSql)).shouldBeEqual(1);

// Verify that the first name column changed
the(s.get("first_name")).shouldBeEqual("Drew");
System.out.println(updateSQL);

s = Student.findById(1);
the(s.get("first_name")).shouldBeEqual("James");
the(s.get("last_name")).shouldBeEqual("Meredith");
the(s.get("dob")).shouldBeEqual(dob);
the(s.get("enrollment_date")).shouldBeEqual(enrollmentDate);
}
@Test(expected=NoSuchElementException.class)

@Test(expected = NoSuchElementException.class)
public void shouldGenerateNoSuchElementFromBlankUpdate() {
// Verify that a model with no attributes throws an error
Student s = new Student();
s.saveIt();
s.toUpdate();
}


@Test
public void shouldGenerateValidInsertSQL() {
Student s = new Student();
Expand All @@ -531,7 +522,6 @@ public void shouldGenerateValidInsertSQL() {
s.setTimestamp("enrollment_date", enrollmentDate);

String insertSql = s.toInsert();
System.out.println(insertSql);
Object id = Base.execInsert(insertSql, s.getIdName());

s = Student.findById(id);
Expand Down

0 comments on commit 4a3a221

Please sign in to comment.