Skip to content

Commit

Permalink
Issue mozilla#108: Ensure team deletion does not also delete badges
Browse files Browse the repository at this point in the history
  • Loading branch information
lmorchard committed Mar 1, 2015
1 parent 0200ae6 commit ce833be
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion badger/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,8 @@ class Badge(models.Model):
tags = TaggableManager(blank=True)

if teamwork:
team = models.ForeignKey(BadgeTeam, blank=True, null=True)
team = models.ForeignKey(BadgeTeam, blank=True, null=True,
on_delete=models.SET_NULL)

creator = models.ForeignKey(User, blank=True, null=True)
created = models.DateTimeField(auto_now_add=True, blank=False)
Expand Down
13 changes: 13 additions & 0 deletions badgus/teams/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ def test_slug(self):
team.save()
eq_(slug2, team.slug)

def test_team_deletion_does_not_delete_badges(self):
"""Deletion of a team should not delete badges"""
team = BadgeTeam(name='To delete')
team.save()

badge = Badge(title='No disassemble', creator=self.users['user'],
team=team)
badge.save()

eq_(1, Badge.objects.filter(title=badge.title).count())
team.delete()
eq_(1, Badge.objects.filter(title=badge.title).count())


class BadgeTeamApplicationTest(BadgeTeamTestCase):

Expand Down

0 comments on commit ce833be

Please sign in to comment.