Commit e846bef3 authored by Fjen Undso's avatar Fjen Undso
Browse files

fix vote request reset

parent 3e32cd0e
......@@ -45,8 +45,9 @@ public class VoteController extends Controller {
if (vote.type == Vote.Type.REQUEST && vote.value == -1) {
// remove all requests from this owner.
// session owner has the power to reset all
for (Vote v : session.votes) {
if (v.type == Vote.Type.REQUEST && v.owner == vote.owner || vote.owner == session.owner) {
List<Vote> sessionvotes = new ArrayList<Vote>(session.votes);
for (Vote v : sessionvotes) {
if (v.type == Vote.Type.REQUEST && (v.owner == vote.owner || vote.owner == session.owner)) {
session.deleteVote(v);
}
}
......
......@@ -89,8 +89,8 @@ public class Session extends Model {
}
public void deleteVote(Vote v) {
v.delete();
this.votes.remove(v);
v.delete();
}
public void addVote(Vote v) {
......
......@@ -47,6 +47,26 @@ public class ModelTest {
assertEquals(0, Session.find.all().size());
assertEquals(0, Vote.find.all().size());
}
@Test
public void testDeleteVotes() {
// Deletion of Votes
Session s1 = new Session("owner1", "Session1");
Vote v1 = new Vote(s1, "owner2", Vote.Type.SPEED, 1);
Vote v2 = new Vote(s1, "owner2", Vote.Type.UNDERSTANDABILITY, -1);
s1.addVote(v1);
s1.addVote(v2);
s1.save();
assertEquals(1, Session.find.all().size());
assertEquals(2, Vote.find.all().size());
assertEquals(2, s1.votes.size());
s1.deleteVote(v1);
s1.save();
assertEquals(1, Session.find.all().size());
assertEquals(1, Vote.find.all().size());
assertEquals(1, s1.votes.size());
}
@Test
public void testSessionAnswers() {
......@@ -84,8 +104,10 @@ public class ModelTest {
assertEquals(2, QuestionAnswer.find.all().size());
assertEquals(2, s1.questionAnswers.size());
s1.resetAnswers();
s1.save();
assertEquals(1, Session.find.all().size());
assertEquals(0, QuestionAnswer.find.all().size());
assertEquals(0, s1.questionAnswers.size());
}
@Test
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment