diff --git a/app/models/comment.rb b/app/models/comment.rb
index f1b90ef..7fdf56c 100644
--- a/app/models/comment.rb
+++ b/app/models/comment.rb
@@ -21,9 +21,9 @@ class Comment < ActiveRecord::Base
def author_name
if author
- author.name
+ author.short_name
else
- name
+ author_id ? '' : name
end
end
@@ -39,6 +39,14 @@ class Comment < ActiveRecord::Base
article.view_url.merge(:anchor => anchor)
end
+ def message
+ author_id ? _('(removed user)') : ('
' + _('(unauthenticated user)'))
+ end
+
+ def removed_user_image
+ '/images/icons-app/user_icon_size-minor.png'
+ end
+
def anchor
"comment-#{id}"
end
diff --git a/app/views/content_viewer/_comment.rhtml b/app/views/content_viewer/_comment.rhtml
index 13b2e17..f20bf0a 100644
--- a/app/views/content_viewer/_comment.rhtml
+++ b/app/views/content_viewer/_comment.rhtml
@@ -8,15 +8,16 @@
<% end %>
<% if comment.author %>
- <%= link_to content_tag( 'span', comment.author.short_name, :class => 'comment-info' ), comment.author.url,
+ <%= link_to content_tag( 'span', comment.author_name, :class => 'comment-info' ), comment.author.url,
:class => 'comment-picture',
:style => 'background-image:url(%s)' % profile_icon(comment.author, :minor)
%>
<% else %>
<%# unauthenticated user: display gravatar icon %>
- <%= content_tag 'span', content_tag('span', comment.name + '
'+ _('(unauthenticated user)'), :class => 'comment-info'),
+ <% url_image = comment.author_id ? comment.removed_user_image : str_gravatar_url_for( comment.email, :size => 50 ) %>
+ <%= content_tag 'span', content_tag('span', comment.author_name + comment.message, :class => 'comment-info'),
:class => 'comment-picture',
- :style => 'background-image:url(%s)' % str_gravatar_url_for( comment.email, :size => 50 )
+ :style => 'background-image:url(%s)' % url_image
%>
<% end %>
diff --git a/test/functional/content_viewer_controller_test.rb b/test/functional/content_viewer_controller_test.rb
index 993b7a5..5ff3896 100644
--- a/test/functional/content_viewer_controller_test.rb
+++ b/test/functional/content_viewer_controller_test.rb
@@ -883,4 +883,16 @@ class ContentViewerControllerTest < Test::Unit::TestCase
post :view_page, :profile => profile.identifier, :page => [ 'myarticle' ], :comment => { :title => 'crap!', :body => 'I think that this article is crap' }
assert_not_equal yesterday, assigns(:page).updated_at
end
+
+ should 'display message if user was removed' do
+ article = profile.articles.create(:name => 'comment test')
+ to_be_removed = create_user('removed_user').person
+ comment = article.comments.create(:author => to_be_removed, :title => 'Test Comment', :body => 'My author does not exist =(')
+ to_be_removed.destroy
+
+ get :view_page, :profile => profile.identifier, :page => article.explode_path
+
+ assert_tag :tag => 'span', :content => '(removed user)', :attributes => {:class => 'comment-info'}
+ end
+
end
diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb
index 7f0ffae..2e9ef58 100644
--- a/test/unit/comment_test.rb
+++ b/test/unit/comment_test.rb
@@ -78,6 +78,10 @@ class CommentTest < Test::Unit::TestCase
assert_equal 'anonymous coward', Comment.new(:name => 'anonymous coward').author_name
end
+ should 'provide empty text for author name if user was removed ' do
+ assert_equal '', Comment.new(:author_id => 9999).author_name
+ end
+
should "provide author e-mail for athenticated authors" do
owner = create_user('testuser').person
assert_equal owner.email, Comment.new(:author => owner).author_email
--
libgit2 0.21.2