зеркало из https://github.com/mozilla/kitsune.git
When deleting the solution to a question, set the question solution to None (bug 585313)
This commit is contained in:
Родитель
c814e090b3
Коммит
ed55bcb294
|
@ -287,13 +287,16 @@ class Answer(ModelBase):
|
|||
def delete(self, *args, **kwargs):
|
||||
"""Override delete method to update parent question info."""
|
||||
question = Question.uncached.get(pk=self.question.id)
|
||||
if question.last_answer and question.last_answer == self:
|
||||
if question.last_answer == self:
|
||||
answers = question.answers.all().order_by('-created')
|
||||
try:
|
||||
question.last_answer = answers[1]
|
||||
except IndexError:
|
||||
# The question has only one answer
|
||||
question.last_answer = None
|
||||
if question.solution == self:
|
||||
question.solution = None
|
||||
|
||||
question.num_answers = question.answers.count() - 1
|
||||
question.save()
|
||||
|
||||
|
|
|
@ -57,6 +57,20 @@ class TestAnswer(TestCaseBase):
|
|||
eq_(question.last_answer.id, last_answer.id)
|
||||
eq_(Answer.objects.filter(pk=answer.id).count(), 0)
|
||||
|
||||
def test_delete_solution_of_question(self):
|
||||
"""Deleting the solution of a Question should update the question.
|
||||
"""
|
||||
# set a solution to the question
|
||||
question = Question.objects.all()[0]
|
||||
solution = question.last_answer
|
||||
question.solution = solution
|
||||
question.save()
|
||||
|
||||
# delete the solution and question.solution should go back to None
|
||||
solution.delete()
|
||||
question = Question.objects.get(pk=question.id)
|
||||
eq_(question.solution, None)
|
||||
|
||||
def test_creator_num_posts(self):
|
||||
"""Test retrieval of post count for creator of a particular answer"""
|
||||
question = Question.objects.all()[0]
|
||||
|
|
Загрузка…
Ссылка в новой задаче