|
15 | 15 | */
|
16 | 16 | package org.javalite.activejdbc;
|
17 | 17 |
|
| 18 | +import java.util.HashMap; |
| 19 | +import java.util.Map; |
18 | 20 | import org.javalite.activejdbc.test.ActiveJDBCTest;
|
19 | 21 | import org.javalite.activejdbc.test_models.Programmer;
|
20 | 22 | import org.junit.Test;
|
@@ -47,4 +49,39 @@ public void isModifiedAfterCreated() {
|
47 | 49 | the(prg).shouldNotBe("modified");
|
48 | 50 | }
|
49 | 51 |
|
| 52 | + @Test |
| 53 | + public void isModifiedAfterFroMap() { |
| 54 | + Programmer prg = Programmer.createIt("first_name", "John"); |
| 55 | + the(prg).shouldNotBe("new"); |
| 56 | + the(prg).shouldNotBe("modified"); |
| 57 | + |
| 58 | + Map<String, Object> map = new HashMap<String, Object>(); |
| 59 | + map.put("last_name", "Doe"); |
| 60 | + prg.fromMap(map); |
| 61 | + the(prg).shouldBe("modified"); |
| 62 | + prg.saveIt(); |
| 63 | + the(prg).shouldNotBe("modified"); |
| 64 | + } |
| 65 | + |
| 66 | + @Test |
| 67 | + public void isModifiedAfterFind() { |
| 68 | + Programmer prg = Programmer.createIt("first_name", "John", "last_name", "Doe"); |
| 69 | + the(prg).shouldNotBe("new"); |
| 70 | + the(prg).shouldNotBe("modified"); |
| 71 | + prg.set("last_name", "Roe"); |
| 72 | + |
| 73 | + Programmer prgFromDB = Programmer.findById(prg.getId()); |
| 74 | + the(prgFromDB).shouldNotBe("new"); |
| 75 | + the(prgFromDB).shouldNotBe("modified"); |
| 76 | + the(prgFromDB.get("last_name")).shouldBeEqual("Doe"); |
| 77 | + |
| 78 | + prgFromDB.set("first_name", "Jane"); |
| 79 | + the(prgFromDB).shouldBe("modified"); |
| 80 | + prgFromDB.saveIt(); |
| 81 | + the(prgFromDB).shouldNotBe("modified"); |
| 82 | + |
| 83 | + prgFromDB = (Programmer) Programmer.where("id = ?", prg.getId()).get(0); |
| 84 | + the(prgFromDB).shouldNotBe("new"); |
| 85 | + the(prgFromDB).shouldNotBe("modified"); |
| 86 | + } |
50 | 87 | }
|
0 commit comments