Commit b621535285b8d00974c9bd172687c196d133a41f

Authored by Caio Almeida
Committed by Daniela Feitosa
1 parent ce1d83e9

Show "post a comment" top button only if there is more than one comment

(ActionItem1771)
app/controllers/public/content_viewer_controller.rb
... ... @@ -100,6 +100,7 @@ class ContentViewerController < ApplicationController
100 100 end
101 101  
102 102 @comments = @page.comments(true).as_thread
  103 + @comments_count = @page.comments.count
103 104 if params[:slideshow]
104 105 render :action => 'slideshow', :layout => 'slideshow'
105 106 end
... ...
app/views/content_viewer/view_page.rhtml
... ... @@ -125,7 +125,7 @@
125 125 <h3 <%= 'class="no-comments-yet"' if @comments.size == 0 %>>
126 126 <%= number_of_comments(@page) %>
127 127 </h3>
128   - <% if @comments.size > 0 %>
  128 + <% if @comments_count > 1 %>
129 129 <p class="post-comment-button"><a href="#comment_form" onclick="jQuery('#page-comment-form h4').first().trigger('click')"><%= _('Post a comment') %></a></p>
130 130 <% end %>
131 131 <ul class="article-comments-list">
... ...
features/comment.feature
... ... @@ -7,8 +7,13 @@ Feature: comment
7 7 | login |
8 8 | booking |
9 9 And the following articles
10   - | owner | name |
11   - | booking | article to comment |
  10 + | owner | name |
  11 + | booking | article to comment |
  12 + | booking | article with comment |
  13 + And the following comments
  14 + | article | author | title | body |
  15 + | article with comment | booking | hi | how are you? |
  16 + | article with comment | booking | hello | i am fine |
12 17  
13 18 Scenario: not post a comment without javascript
14 19 Given I am on /booking/article-to-comment
... ... @@ -71,11 +76,8 @@ Feature: comment
71 76  
72 77 @selenium
73 78 Scenario: render comment form and go to bottom
74   - Given the following comment
75   - | article | author | title | body |
76   - | article to comment | booking | hi | how are you? |
77   - Given I am on /booking/article-to-comment
  79 + Given I am on /booking/article-with-comment
78 80 When I follow "Post a comment" within ".post-comment-button"
79 81 Then I should see "Enter your comment" within "div#page-comment-form div.post_comment_box.opened"
80   - And I should be exactly on /booking/article-to-comment
  82 + And I should be exactly on /booking/article-with-comment
81 83 And I should be moved to anchor "comment_form"
... ...
test/functional/content_viewer_controller_test.rb
... ... @@ -1324,14 +1324,14 @@ class ContentViewerControllerTest &lt; Test::Unit::TestCase
1324 1324 assert_tag :a, :attributes => { :href => "http://" + url}, :content => url.scan(/.{4}/).join('&#x200B;')
1325 1325 end
1326 1326  
1327   - should 'show a post comment button on top if there are comments' do
  1327 + should 'not show a post comment button on top if there is only one comment' do
1328 1328 profile = create_user('testuser').person
1329 1329 article = profile.articles.build(:name => 'test')
1330 1330 article.save!
1331 1331 comment = article.comments.build(:author => profile, :title => 'hi', :body => 'hello')
1332 1332 comment.save!
1333 1333 get :view_page, :profile => 'testuser', :page => [ 'test' ]
1334   - assert_tag :tag => 'p', :attributes => { :class => 'post-comment-button' }
  1334 + assert_no_tag :tag => 'p', :attributes => { :class => 'post-comment-button' }
1335 1335 end
1336 1336  
1337 1337 should 'not show a post comment button on top if there are no comments' do
... ... @@ -1342,4 +1342,28 @@ class ContentViewerControllerTest &lt; Test::Unit::TestCase
1342 1342 assert_no_tag :tag => 'p', :attributes => { :class => 'post-comment-button' }
1343 1343 end
1344 1344  
  1345 + should 'show a post comment button on top if there are at least two comments' do
  1346 + profile = create_user('testuser').person
  1347 + article = profile.articles.build(:name => 'test')
  1348 + article.save!
  1349 + comment1 = article.comments.build(:author => profile, :title => 'hi', :body => 'hello')
  1350 + comment1.save!
  1351 + comment2 = article.comments.build(:author => profile, :title => 'hi', :body => 'hello', :reply_of_id => comment1.id)
  1352 + comment2.save!
  1353 + get :view_page, :profile => 'testuser', :page => [ 'test' ]
  1354 + assert_tag :tag => 'p', :attributes => { :class => 'post-comment-button' }
  1355 + end
  1356 +
  1357 + should 'store number of comments' do
  1358 + profile = create_user('testuser').person
  1359 + article = profile.articles.build(:name => 'test')
  1360 + article.save!
  1361 + comment1 = article.comments.build(:author => profile, :title => 'hi', :body => 'hello')
  1362 + comment1.save!
  1363 + comment2 = article.comments.build(:author => profile, :title => 'hi', :body => 'hello', :reply_of_id => comment1.id)
  1364 + comment2.save!
  1365 + get :view_page, :profile => 'testuser', :page => [ 'test' ]
  1366 + assert_equal 2, assigns(:comments_count)
  1367 + end
  1368 +
1345 1369 end
... ...