diff --git a/app/controllers/public/content_viewer_controller.rb b/app/controllers/public/content_viewer_controller.rb
index 47dec71..89041bd 100644
--- a/app/controllers/public/content_viewer_controller.rb
+++ b/app/controllers/public/content_viewer_controller.rb
@@ -100,6 +100,7 @@ class ContentViewerController < ApplicationController
end
@comments = @page.comments(true).as_thread
+ @comments_count = @page.comments.count
if params[:slideshow]
render :action => 'slideshow', :layout => 'slideshow'
end
diff --git a/app/views/content_viewer/view_page.rhtml b/app/views/content_viewer/view_page.rhtml
index dfea761..7b8df40 100644
--- a/app/views/content_viewer/view_page.rhtml
+++ b/app/views/content_viewer/view_page.rhtml
@@ -125,7 +125,7 @@
>
<%= number_of_comments(@page) %>
- <% if @comments.size > 0 %>
+ <% if @comments_count > 1 %>
<% end %>
diff --git a/features/comment.feature b/features/comment.feature
index 3a416e5..fdb0a84 100644
--- a/features/comment.feature
+++ b/features/comment.feature
@@ -7,8 +7,13 @@ Feature: comment
| login |
| booking |
And the following articles
- | owner | name |
- | booking | article to comment |
+ | owner | name |
+ | booking | article to comment |
+ | booking | article with comment |
+ And the following comments
+ | article | author | title | body |
+ | article with comment | booking | hi | how are you? |
+ | article with comment | booking | hello | i am fine |
Scenario: not post a comment without javascript
Given I am on /booking/article-to-comment
@@ -71,11 +76,8 @@ Feature: comment
@selenium
Scenario: render comment form and go to bottom
- Given the following comment
- | article | author | title | body |
- | article to comment | booking | hi | how are you? |
- Given I am on /booking/article-to-comment
+ Given I am on /booking/article-with-comment
When I follow "Post a comment" within ".post-comment-button"
Then I should see "Enter your comment" within "div#page-comment-form div.post_comment_box.opened"
- And I should be exactly on /booking/article-to-comment
+ And I should be exactly on /booking/article-with-comment
And I should be moved to anchor "comment_form"
diff --git a/test/functional/content_viewer_controller_test.rb b/test/functional/content_viewer_controller_test.rb
index 270e783..bbba9f0 100644
--- a/test/functional/content_viewer_controller_test.rb
+++ b/test/functional/content_viewer_controller_test.rb
@@ -1324,14 +1324,14 @@ class ContentViewerControllerTest < Test::Unit::TestCase
assert_tag :a, :attributes => { :href => "http://" + url}, :content => url.scan(/.{4}/).join('')
end
- should 'show a post comment button on top if there are comments' do
+ should 'not show a post comment button on top if there is only one comment' do
profile = create_user('testuser').person
article = profile.articles.build(:name => 'test')
article.save!
comment = article.comments.build(:author => profile, :title => 'hi', :body => 'hello')
comment.save!
get :view_page, :profile => 'testuser', :page => [ 'test' ]
- assert_tag :tag => 'p', :attributes => { :class => 'post-comment-button' }
+ assert_no_tag :tag => 'p', :attributes => { :class => 'post-comment-button' }
end
should 'not show a post comment button on top if there are no comments' do
@@ -1342,4 +1342,28 @@ class ContentViewerControllerTest < Test::Unit::TestCase
assert_no_tag :tag => 'p', :attributes => { :class => 'post-comment-button' }
end
+ should 'show a post comment button on top if there are at least two comments' do
+ profile = create_user('testuser').person
+ article = profile.articles.build(:name => 'test')
+ article.save!
+ comment1 = article.comments.build(:author => profile, :title => 'hi', :body => 'hello')
+ comment1.save!
+ comment2 = article.comments.build(:author => profile, :title => 'hi', :body => 'hello', :reply_of_id => comment1.id)
+ comment2.save!
+ get :view_page, :profile => 'testuser', :page => [ 'test' ]
+ assert_tag :tag => 'p', :attributes => { :class => 'post-comment-button' }
+ end
+
+ should 'store number of comments' do
+ profile = create_user('testuser').person
+ article = profile.articles.build(:name => 'test')
+ article.save!
+ comment1 = article.comments.build(:author => profile, :title => 'hi', :body => 'hello')
+ comment1.save!
+ comment2 = article.comments.build(:author => profile, :title => 'hi', :body => 'hello', :reply_of_id => comment1.id)
+ comment2.save!
+ get :view_page, :profile => 'testuser', :page => [ 'test' ]
+ assert_equal 2, assigns(:comments_count)
+ end
+
end
--
libgit2 0.21.2