remove polls from poll cache on deletion
add test for poll castvote and delete
This commit is contained in:
parent
167a0edba3
commit
d723895f5d
@ -50,6 +50,7 @@ func (p *Poll) Delete() error {
|
||||
return err
|
||||
}
|
||||
_, err = pollStmts.deletePoll.Exec(p.ID)
|
||||
_ = Polls.GetCache().Remove(p.ID)
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -207,11 +207,11 @@ func (s *DefaultPollStore) unpackOptionsMap(rawOptions map[int]string) []PollOpt
|
||||
|
||||
// TODO: Use a transaction for this
|
||||
func (s *DefaultPollStore) Create(parent Pollable, pollType int, pollOptions map[int]string) (id int, err error) {
|
||||
// TODO: Move the option names into the polls_options table and get rid of this json sludge?
|
||||
pollOptionsTxt, err := json.Marshal(pollOptions)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
res, err := s.createPoll.Exec(parent.GetID(), parent.GetTable(), pollType, pollOptionsTxt)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
18
misc_test.go
18
misc_test.go
@ -1269,6 +1269,7 @@ func TestPolls(t *testing.T) {
|
||||
pid, err := c.Polls.Create(topic, pollType, map[int]string{0: "item 1", 1: "item 2", 2: "item 3"})
|
||||
expectNilErr(t, err)
|
||||
expect(t, pid == 1, fmt.Sprintf("poll id should be 1 not %d", pid))
|
||||
expect(t, c.Polls.Exists(1), "poll 1 should exist")
|
||||
p, err := c.Polls.Get(1)
|
||||
expectNilErr(t, err)
|
||||
expect(t, p.ID == 1, fmt.Sprintf("p.ID should be 1 not %d", p.ID))
|
||||
@ -1279,7 +1280,22 @@ func TestPolls(t *testing.T) {
|
||||
// TODO: More fields
|
||||
expect(t, p.VoteCount == 0, fmt.Sprintf("p.VoteCount should be 0 not %d", p.VoteCount))
|
||||
|
||||
// TODO: More tests
|
||||
expectNilErr(t, p.CastVote(0, 1, ""))
|
||||
expectNilErr(t, c.Polls.Reload(p.ID))
|
||||
p, err = c.Polls.Get(1)
|
||||
expectNilErr(t, err)
|
||||
expect(t, p.ID == 1, fmt.Sprintf("p.ID should be 1 not %d", p.ID))
|
||||
expect(t, p.ParentID == tid, fmt.Sprintf("p.ParentID should be %d not %d", tid, p.ParentID))
|
||||
expect(t, p.ParentTable == "topics", fmt.Sprintf("p.ParentID should be %s not %s", "topics", p.ParentTable))
|
||||
expect(t, p.Type == 0, fmt.Sprintf("p.ParentID should be 0 not %d", p.Type))
|
||||
expect(t, !p.AntiCheat, "p.AntiCheat should be false")
|
||||
// TODO: More fields
|
||||
expect(t, p.VoteCount == 1, fmt.Sprintf("p.VoteCount should be 1 not %d", p.VoteCount))
|
||||
|
||||
expectNilErr(t, p.Delete())
|
||||
expect(t, !c.Polls.Exists(1), "poll 1 should no longer exist")
|
||||
_, err = c.Polls.Get(1)
|
||||
recordMustNotExist(t, err, "poll 1 should no longer exist")
|
||||
}
|
||||
|
||||
func TestProfileReplyStore(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user