Commit 0770524c6f7d433dbf30a3a6f08f86ea8e324382
1 parent
5bd427bd
Exists in
master
and in
29 other branches
adding tests for comment_helper
Showing
1 changed file
with
85 additions
and
0 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,85 @@ |
| 1 | +require File.dirname(__FILE__) + '/../test_helper' | |
| 2 | + | |
| 3 | +class CommentHelperTest < ActiveSupport::TestCase | |
| 4 | + | |
| 5 | + include CommentHelper | |
| 6 | + include ActionView::Helpers::TagHelper | |
| 7 | + include NoosferoTestHelper | |
| 8 | + | |
| 9 | + def setup | |
| 10 | + @user = create_user('usertest').person | |
| 11 | + @profile = @user | |
| 12 | + self.stubs(:logged_in?).returns(true) | |
| 13 | + self.stubs(:report_abuse).returns('<a href="#">link</a>') | |
| 14 | + self.stubs(:expirable_comment_link).returns('<a href="#">link</a>') | |
| 15 | + @plugins.stubs(:dispatch).returns([]) | |
| 16 | + end | |
| 17 | + | |
| 18 | + attr_reader :user, :profile | |
| 19 | + | |
| 20 | + should 'show menu if it has links for actions' do | |
| 21 | + comment = Comment.new | |
| 22 | + menu = comment_actions(comment) | |
| 23 | + assert menu | |
| 24 | + end | |
| 25 | + | |
| 26 | + should 'do not show menu if it has no actions' do | |
| 27 | + comment = Comment.new | |
| 28 | + self.stubs(:links_for_comment_actions).returns([]) | |
| 29 | + menu = comment_actions(comment) | |
| 30 | + assert !menu | |
| 31 | + end | |
| 32 | + | |
| 33 | + should 'include actions of plugins in menu' do | |
| 34 | + comment = Comment.new | |
| 35 | + plugin_action = {:link => 'plugin_action'} | |
| 36 | + @plugins.stubs(:dispatch).returns([plugin_action]) | |
| 37 | + links = links_for_comment_actions(comment) | |
| 38 | + assert_includes links, plugin_action | |
| 39 | + end | |
| 40 | + | |
| 41 | + should 'return link for report abuse action when comment has a author' do | |
| 42 | + comment = Comment.new | |
| 43 | + comment.author = user | |
| 44 | + link = link_for_report_abuse(comment) | |
| 45 | + assert link | |
| 46 | + end | |
| 47 | + | |
| 48 | + should 'do not return link for report abuse action when comment has no author' do | |
| 49 | + comment = Comment.new | |
| 50 | + link = link_for_report_abuse(comment) | |
| 51 | + assert !link | |
| 52 | + end | |
| 53 | + | |
| 54 | + should 'return link for mark comment as spam' do | |
| 55 | + comment = Comment.new | |
| 56 | + link = link_for_spam(comment) | |
| 57 | + assert_match /Mark as SPAM/, link[:link] | |
| 58 | + end | |
| 59 | + | |
| 60 | + should 'return link for mark comment as not spam' do | |
| 61 | + comment = Comment.new | |
| 62 | + comment.spam = true | |
| 63 | + link = link_for_spam(comment) | |
| 64 | + assert_match /Mark as NOT SPAM/, link[:link] | |
| 65 | + end | |
| 66 | + | |
| 67 | + should 'do not return link for edit comment' do | |
| 68 | + comment = Comment.new | |
| 69 | + link = link_for_edit(comment) | |
| 70 | + assert !link | |
| 71 | + end | |
| 72 | + | |
| 73 | + should 'return link for edit comment' do | |
| 74 | + comment = Comment.new | |
| 75 | + comment.author = user | |
| 76 | + link = link_for_edit(comment) | |
| 77 | + assert link | |
| 78 | + end | |
| 79 | + | |
| 80 | + def link_to_function(content, url, options = {}) | |
| 81 | + link_to(content, url, options) | |
| 82 | + end | |
| 83 | + | |
| 84 | +end | |
| 85 | + | ... | ... |