From 4d40b67889b8210a93aee6233ac7b7b603fe89e6 Mon Sep 17 00:00:00 2001 From: Rodrigo Souto Date: Fri, 12 Jul 2013 19:08:05 -0300 Subject: [PATCH] [comments-refactor-review] Checking permissions to show edit link --- app/helpers/comment_helper.rb | 2 +- test/unit/comment_helper_test.rb | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/helpers/comment_helper.rb b/app/helpers/comment_helper.rb index 9359654..c1b7f13 100644 --- a/app/helpers/comment_helper.rb +++ b/app/helpers/comment_helper.rb @@ -56,7 +56,7 @@ module CommentHelper end def link_for_edit(comment) - if comment.author && comment.author == user + if comment.can_be_updated_by?(user) {:link => expirable_comment_link(comment, :edit, _('Edit'), url_for(:profile => profile.identifier, :controller => :comment, :action => :edit, :id => comment.id),:class => 'colorbox')} end end diff --git a/test/unit/comment_helper_test.rb b/test/unit/comment_helper_test.rb index e73fe41..ddc1c54 100644 --- a/test/unit/comment_helper_test.rb +++ b/test/unit/comment_helper_test.rb @@ -105,13 +105,14 @@ class CommentHelperTest < ActiveSupport::TestCase should 'do not return link for edit comment' do comment = Comment.new + comment.stubs(:can_be_updated_by?).with(user).returns(false) link = link_for_edit(comment) - assert !link + assert_nil link end should 'return link for edit comment' do comment = Comment.new - comment.author = user + comment.stubs(:can_be_updated_by?).with(user).returns(true) link = link_for_edit(comment) assert link end -- libgit2 0.21.2