Skip to content

Commit ace002b

Browse files
committed
#381: Added more tests for isModified
1 parent 0f0b70f commit ace002b

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

activejdbc/src/test/java/org/javalite/activejdbc/Defect381_UpdateModifiedOnlyTest.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package org.javalite.activejdbc;
1717

18+
import java.util.HashMap;
19+
import java.util.Map;
1820
import org.javalite.activejdbc.test.ActiveJDBCTest;
1921
import org.javalite.activejdbc.test_models.Programmer;
2022
import org.junit.Test;
@@ -47,4 +49,39 @@ public void isModifiedAfterCreated() {
4749
the(prg).shouldNotBe("modified");
4850
}
4951

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+
}
5087
}

0 commit comments

Comments
 (0)