Commit 4d40b67889b8210a93aee6233ac7b7b603fe89e6
1 parent
f81c2116
Exists in
master
and in
23 other branches
[comments-refactor-review] Checking permissions to show edit link
Showing
2 changed files
with
4 additions
and
3 deletions
Show diff stats
app/helpers/comment_helper.rb
| ... | ... | @@ -56,7 +56,7 @@ module CommentHelper |
| 56 | 56 | end |
| 57 | 57 | |
| 58 | 58 | def link_for_edit(comment) |
| 59 | - if comment.author && comment.author == user | |
| 59 | + if comment.can_be_updated_by?(user) | |
| 60 | 60 | {:link => expirable_comment_link(comment, :edit, _('Edit'), url_for(:profile => profile.identifier, :controller => :comment, :action => :edit, :id => comment.id),:class => 'colorbox')} |
| 61 | 61 | end |
| 62 | 62 | end | ... | ... |
test/unit/comment_helper_test.rb
| ... | ... | @@ -105,13 +105,14 @@ class CommentHelperTest < ActiveSupport::TestCase |
| 105 | 105 | |
| 106 | 106 | should 'do not return link for edit comment' do |
| 107 | 107 | comment = Comment.new |
| 108 | + comment.stubs(:can_be_updated_by?).with(user).returns(false) | |
| 108 | 109 | link = link_for_edit(comment) |
| 109 | - assert !link | |
| 110 | + assert_nil link | |
| 110 | 111 | end |
| 111 | 112 | |
| 112 | 113 | should 'return link for edit comment' do |
| 113 | 114 | comment = Comment.new |
| 114 | - comment.author = user | |
| 115 | + comment.stubs(:can_be_updated_by?).with(user).returns(true) | |
| 115 | 116 | link = link_for_edit(comment) |
| 116 | 117 | assert link |
| 117 | 118 | end | ... | ... |