Commit 148ad37633916bc98f805f72e0af3b3e9724485d

Authored by Daniela Feitosa
Committed by Antonio Terceiro
1 parent 2cd8dbb3

Comments created by removed users are displayed

    * If the comment was created by a user that now doesn't exist:
        *In the place of name is displayed "(removed user)"
        *In the avatar is displayed "unknown user" avatar

ActionItem1296
app/models/comment.rb
... ... @@ -21,9 +21,9 @@ class Comment < ActiveRecord::Base
21 21  
22 22 def author_name
23 23 if author
24   - author.name
  24 + author.short_name
25 25 else
26   - name
  26 + author_id ? '' : name
27 27 end
28 28 end
29 29  
... ... @@ -39,6 +39,14 @@ class Comment < ActiveRecord::Base
39 39 article.view_url.merge(:anchor => anchor)
40 40 end
41 41  
  42 + def message
  43 + author_id ? _('(removed user)') : ('<br />' + _('(unauthenticated user)'))
  44 + end
  45 +
  46 + def removed_user_image
  47 + '/images/icons-app/user_icon_size-minor.png'
  48 + end
  49 +
42 50 def anchor
43 51 "comment-#{id}"
44 52 end
... ...
app/views/content_viewer/_comment.rhtml
... ... @@ -8,15 +8,16 @@
8 8 <% end %>
9 9  
10 10 <% if comment.author %>
11   - <%= link_to content_tag( 'span', comment.author.short_name, :class => 'comment-info' ), comment.author.url,
  11 + <%= link_to content_tag( 'span', comment.author_name, :class => 'comment-info' ), comment.author.url,
12 12 :class => 'comment-picture',
13 13 :style => 'background-image:url(%s)' % profile_icon(comment.author, :minor)
14 14 %>
15 15 <% else %>
16 16 <%# unauthenticated user: display gravatar icon %>
17   - <%= content_tag 'span', content_tag('span', comment.name + '<br/>'+ _('(unauthenticated user)'), :class => 'comment-info'),
  17 + <% url_image = comment.author_id ? comment.removed_user_image : str_gravatar_url_for( comment.email, :size => 50 ) %>
  18 + <%= content_tag 'span', content_tag('span', comment.author_name + comment.message, :class => 'comment-info'),
18 19 :class => 'comment-picture',
19   - :style => 'background-image:url(%s)' % str_gravatar_url_for( comment.email, :size => 50 )
  20 + :style => 'background-image:url(%s)' % url_image
20 21 %>
21 22 <% end %>
22 23  
... ...
test/functional/content_viewer_controller_test.rb
... ... @@ -883,4 +883,16 @@ class ContentViewerControllerTest &lt; Test::Unit::TestCase
883 883 post :view_page, :profile => profile.identifier, :page => [ 'myarticle' ], :comment => { :title => 'crap!', :body => 'I think that this article is crap' }
884 884 assert_not_equal yesterday, assigns(:page).updated_at
885 885 end
  886 +
  887 + should 'display message if user was removed' do
  888 + article = profile.articles.create(:name => 'comment test')
  889 + to_be_removed = create_user('removed_user').person
  890 + comment = article.comments.create(:author => to_be_removed, :title => 'Test Comment', :body => 'My author does not exist =(')
  891 + to_be_removed.destroy
  892 +
  893 + get :view_page, :profile => profile.identifier, :page => article.explode_path
  894 +
  895 + assert_tag :tag => 'span', :content => '(removed user)', :attributes => {:class => 'comment-info'}
  896 + end
  897 +
886 898 end
... ...
test/unit/comment_test.rb
... ... @@ -78,6 +78,10 @@ class CommentTest &lt; Test::Unit::TestCase
78 78 assert_equal 'anonymous coward', Comment.new(:name => 'anonymous coward').author_name
79 79 end
80 80  
  81 + should 'provide empty text for author name if user was removed ' do
  82 + assert_equal '', Comment.new(:author_id => 9999).author_name
  83 + end
  84 +
81 85 should "provide author e-mail for athenticated authors" do
82 86 owner = create_user('testuser').person
83 87 assert_equal owner.email, Comment.new(:author => owner).author_email
... ...