Skip to content
This repository has been archived by the owner on Jun 29, 2020. It is now read-only.

Commit

Permalink
add_comment Activityの描画ができるようになった
Browse files Browse the repository at this point in the history
  • Loading branch information
giginet committed Oct 23, 2014
1 parent 091fab6 commit 834cdbe
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/kawaz/core/comments/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ def alter(self, instance, activity, **kwargs):
activity.content_type = ct
activity.object_id = pk
activity.status = 'add_comment'
activity.remarks = str(pk)
return activity
30 changes: 29 additions & 1 deletion src/kawaz/core/comments/tests/test_activity.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
from unittest.mock import MagicMock
from django.template import Context
from django.test import TestCase
from activities.mediator import ActivityMediator
from activities.models import Activity
from activities.registry import registry
from .factories import CommentTestArticleFactory
from .factories import CommentFactory
from kawaz.core.comments.tests.models import CommentTestArticle

__author__ = 'giginet'


class CommentActivityMediatorTestCase(TestCase):
def setUp(self):
registry.register(CommentTestArticle, ActivityMediator())

def test_add_comment(self):
"""
Expand All @@ -17,11 +24,32 @@ def test_add_comment(self):
nactivities = Activity.objects.get_for_object(object).count()

# コメントをする
CommentFactory(content_object=object)
comment = CommentFactory(content_object=object)

activities = Activity.objects.get_for_object(object)
self.assertEqual(nactivities + 1, activities.count())

activity = activities[0]
self.assertEqual(activity.status, 'add_comment')
self.assertEqual(activity.snapshot, object)
# remarksにコメントのpkが入る
self.assertEqual(activity.remarks, str(comment.pk))

def test_render_add_comment(self):
"""
render_activityでadd_commentが正しく表示できる
"""
object = CommentTestArticleFactory()

nactivities = Activity.objects.get_for_object(object).count()

# コメントをする
CommentFactory(content_object=object)

activities = Activity.objects.get_for_object(object)
self.assertEqual(nactivities + 1, activities.count())

activity = activities[0]
mediator = registry.get(activity)

self.assertTrue(mediator.render(activity, Context()))
8 changes: 8 additions & 0 deletions src/templates/activities/add_comment.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% extends "activities/base.html" %}
{% block icon %}
<img src="{{ comment.user.get_large_avatar }}" class="avatar avatar-large">
{% endblock %}
{% block history-item %}
{# 現在、非ログインユーザーのコメントは考慮していない #}
{% include "components/small_avatar.html" with user=comment.user render_username=False %}コメントが付きました
{% endblock %}

0 comments on commit 834cdbe

Please sign in to comment.