diff --git a/CHANGELOG b/CHANGELOG index 9c2a8ae..fc98dbd 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ Current version (0.2) : + - Bug corrigé : Génération de 2 timelines si on crée un jeu avec l'état "created" - Renommage des consoles en « plateformes » - Activation des requêtes CORS pour permettre à une autre application d'accéder à l'API - MàJ vers Django 1.11.5 diff --git a/collection/games/signals.py b/collection/games/signals.py index 8cd7c9f..5d285d9 100644 --- a/collection/games/signals.py +++ b/collection/games/signals.py @@ -18,5 +18,6 @@ def game_saved(sender, instance, created, raw, using, update_fields, new_entry = dict(entry) new_entry.update({'status': instance.CREATED}) Timeline.objects.create(**new_entry) - # Add new timeline entry - Timeline.objects.create(**entry) + # Add new timeline entry ONLY if status is difference from CREATED one + if instance.status != instance.CREATED: + Timeline.objects.create(**entry) diff --git a/collection/games/tests/test_timeline.py b/collection/games/tests/test_timeline.py new file mode 100644 index 0000000..07a98f9 --- /dev/null +++ b/collection/games/tests/test_timeline.py @@ -0,0 +1,34 @@ +from django.test import TestCase +from games.models import Game, Platform, Timeline + + +class TimelineTest(TestCase): + """ + Timeline Model + """ + + @classmethod + def setUpTestData(cls): + cls.console = Platform.objects.create(name='GP2X') + + + def test_game_with_status_created_gives_one_timeline(self): + """ + Game with status "created" should only generate ONE status. Not more. + """ + # Games creation should generate timelines. + game1 = Game.objects.create( + name='Vektronizor', + collection=self.console, + status='beaten') + game2 = Game.objects.create( + name='Pomperman', + collection=self.console, + status='created') + + game1_timeline = Timeline.objects.filter( + item=game1) + game2_timeline = Timeline.objects.filter( + item=game2) + self.assertEqual(game1_timeline.count(), 2) + self.assertEqual(game2_timeline.count(), 1)