Commit 148ad37633916bc98f805f72e0af3b3e9724485d
Committed by
Antonio Terceiro
1 parent
2cd8dbb3
Exists in
staging
and in
42 other branches
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
Showing
4 changed files
with
30 additions
and
5 deletions
Show diff stats
app/models/comment.rb
| @@ -21,9 +21,9 @@ class Comment < ActiveRecord::Base | @@ -21,9 +21,9 @@ class Comment < ActiveRecord::Base | ||
| 21 | 21 | ||
| 22 | def author_name | 22 | def author_name |
| 23 | if author | 23 | if author |
| 24 | - author.name | 24 | + author.short_name |
| 25 | else | 25 | else |
| 26 | - name | 26 | + author_id ? '' : name |
| 27 | end | 27 | end |
| 28 | end | 28 | end |
| 29 | 29 | ||
| @@ -39,6 +39,14 @@ class Comment < ActiveRecord::Base | @@ -39,6 +39,14 @@ class Comment < ActiveRecord::Base | ||
| 39 | article.view_url.merge(:anchor => anchor) | 39 | article.view_url.merge(:anchor => anchor) |
| 40 | end | 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 | def anchor | 50 | def anchor |
| 43 | "comment-#{id}" | 51 | "comment-#{id}" |
| 44 | end | 52 | end |
app/views/content_viewer/_comment.rhtml
| @@ -8,15 +8,16 @@ | @@ -8,15 +8,16 @@ | ||
| 8 | <% end %> | 8 | <% end %> |
| 9 | 9 | ||
| 10 | <% if comment.author %> | 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 | :class => 'comment-picture', | 12 | :class => 'comment-picture', |
| 13 | :style => 'background-image:url(%s)' % profile_icon(comment.author, :minor) | 13 | :style => 'background-image:url(%s)' % profile_icon(comment.author, :minor) |
| 14 | %> | 14 | %> |
| 15 | <% else %> | 15 | <% else %> |
| 16 | <%# unauthenticated user: display gravatar icon %> | 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 | :class => 'comment-picture', | 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 | <% end %> | 22 | <% end %> |
| 22 | 23 |
test/functional/content_viewer_controller_test.rb
| @@ -883,4 +883,16 @@ class ContentViewerControllerTest < Test::Unit::TestCase | @@ -883,4 +883,16 @@ class ContentViewerControllerTest < Test::Unit::TestCase | ||
| 883 | post :view_page, :profile => profile.identifier, :page => [ 'myarticle' ], :comment => { :title => 'crap!', :body => 'I think that this article is crap' } | 883 | post :view_page, :profile => profile.identifier, :page => [ 'myarticle' ], :comment => { :title => 'crap!', :body => 'I think that this article is crap' } |
| 884 | assert_not_equal yesterday, assigns(:page).updated_at | 884 | assert_not_equal yesterday, assigns(:page).updated_at |
| 885 | end | 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 | end | 898 | end |
test/unit/comment_test.rb
| @@ -78,6 +78,10 @@ class CommentTest < Test::Unit::TestCase | @@ -78,6 +78,10 @@ class CommentTest < Test::Unit::TestCase | ||
| 78 | assert_equal 'anonymous coward', Comment.new(:name => 'anonymous coward').author_name | 78 | assert_equal 'anonymous coward', Comment.new(:name => 'anonymous coward').author_name |
| 79 | end | 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 | should "provide author e-mail for athenticated authors" do | 85 | should "provide author e-mail for athenticated authors" do |
| 82 | owner = create_user('testuser').person | 86 | owner = create_user('testuser').person |
| 83 | assert_equal owner.email, Comment.new(:author => owner).author_email | 87 | assert_equal owner.email, Comment.new(:author => owner).author_email |