Commit 4d40b67889b8210a93aee6233ac7b7b603fe89e6

Authored by Rodrigo Souto
1 parent f81c2116

[comments-refactor-review] Checking permissions to show edit link

app/helpers/comment_helper.rb
@@ -56,7 +56,7 @@ module CommentHelper @@ -56,7 +56,7 @@ module CommentHelper
56 end 56 end
57 57
58 def link_for_edit(comment) 58 def link_for_edit(comment)
59 - if comment.author && comment.author == user 59 + if comment.can_be_updated_by?(user)
60 {:link => expirable_comment_link(comment, :edit, _('Edit'), url_for(:profile => profile.identifier, :controller => :comment, :action => :edit, :id => comment.id),:class => 'colorbox')} 60 {:link => expirable_comment_link(comment, :edit, _('Edit'), url_for(:profile => profile.identifier, :controller => :comment, :action => :edit, :id => comment.id),:class => 'colorbox')}
61 end 61 end
62 end 62 end
test/unit/comment_helper_test.rb
@@ -105,13 +105,14 @@ class CommentHelperTest < ActiveSupport::TestCase @@ -105,13 +105,14 @@ class CommentHelperTest < ActiveSupport::TestCase
105 105
106 should 'do not return link for edit comment' do 106 should 'do not return link for edit comment' do
107 comment = Comment.new 107 comment = Comment.new
  108 + comment.stubs(:can_be_updated_by?).with(user).returns(false)
108 link = link_for_edit(comment) 109 link = link_for_edit(comment)
109 - assert !link 110 + assert_nil link
110 end 111 end
111 112
112 should 'return link for edit comment' do 113 should 'return link for edit comment' do
113 comment = Comment.new 114 comment = Comment.new
114 - comment.author = user 115 + comment.stubs(:can_be_updated_by?).with(user).returns(true)
115 link = link_for_edit(comment) 116 link = link_for_edit(comment)
116 assert link 117 assert link
117 end 118 end