Commit 3ce1e98052030923eee708358b07f30e35d8a369
Committed by
Tallys Martins
1 parent
20bfd7e0
Exists in
stable-spb-1.4
Fix article comments ordering bug
Signed-off-by: Eduardo Vital <vitaldu@gmail.com> Signed-off-by: Pedro de Lyra <pedrodelyra@gmail.com> (cherry picked from commit 951fcb57484a69911997572a2bc6d52b27ccbc6b)
Showing
5 changed files
with
35 additions
and
11 deletions
Show diff stats
app/controllers/public/content_viewer_controller.rb
| @@ -64,11 +64,7 @@ class ContentViewerController < ApplicationController | @@ -64,11 +64,7 @@ class ContentViewerController < ApplicationController | ||
| 64 | process_comments(params) | 64 | process_comments(params) |
| 65 | 65 | ||
| 66 | if request.xhr? and params[:comment_order] | 66 | if request.xhr? and params[:comment_order] |
| 67 | - if @comment_order == 'newest' | ||
| 68 | - @comments = @comments.reverse | ||
| 69 | - end | ||
| 70 | - | ||
| 71 | - return render :partial => 'comment/comment', :collection => @comments | 67 | + return render :partial => 'comment/comments_with_pagination' |
| 72 | end | 68 | end |
| 73 | 69 | ||
| 74 | if params[:slideshow] | 70 | if params[:slideshow] |
| @@ -272,8 +268,12 @@ class ContentViewerController < ApplicationController | @@ -272,8 +268,12 @@ class ContentViewerController < ApplicationController | ||
| 272 | @comments = @page.comments.without_spam | 268 | @comments = @page.comments.without_spam |
| 273 | @comments = @plugins.filter(:unavailable_comments, @comments) | 269 | @comments = @plugins.filter(:unavailable_comments, @comments) |
| 274 | @comments_count = @comments.count | 270 | @comments_count = @comments.count |
| 275 | - @comments = @comments.without_reply.paginate(:per_page => per_page, :page => params[:comment_page] ) | ||
| 276 | @comment_order = params[:comment_order].nil? ? 'oldest' : params[:comment_order] | 271 | @comment_order = params[:comment_order].nil? ? 'oldest' : params[:comment_order] |
| 272 | + @comments = @comments.without_reply | ||
| 273 | + if @comment_order == 'newest' | ||
| 274 | + @comments = @comments.reverse | ||
| 275 | + end | ||
| 276 | + @comments = @comments.paginate(:per_page => per_page, :page => params[:comment_page] ) | ||
| 277 | end | 277 | end |
| 278 | 278 | ||
| 279 | private | 279 | private |
app/views/content_viewer/view_page.html.erb
| @@ -81,7 +81,7 @@ | @@ -81,7 +81,7 @@ | ||
| 81 | <ul class="article-comments-list"> | 81 | <ul class="article-comments-list"> |
| 82 | <% if @comments.present? %> | 82 | <% if @comments.present? %> |
| 83 | <%= render :partial => 'comment/comment', :collection => @comments %> | 83 | <%= render :partial => 'comment/comment', :collection => @comments %> |
| 84 | - <%= pagination_links @comments, :param_name => 'comment_page' %> | 84 | + <%= pagination_links @comments, :param_name => 'comment_page', :params => { :comment_order => @comment_order } %> |
| 85 | <% end %> | 85 | <% end %> |
| 86 | </ul> | 86 | </ul> |
| 87 | 87 |
public/javascripts/comment_order.js
| @@ -10,10 +10,9 @@ function send_order(order, url) { | @@ -10,10 +10,9 @@ function send_order(order, url) { | ||
| 10 | }); | 10 | }); |
| 11 | } | 11 | } |
| 12 | 12 | ||
| 13 | - | ||
| 14 | jQuery(document).ready(function(){ | 13 | jQuery(document).ready(function(){ |
| 15 | jQuery("#comment_order").change(function(){ | 14 | jQuery("#comment_order").change(function(){ |
| 16 | - var url = jQuery("#page_url").val(); | 15 | + var url = window.location.href; |
| 17 | send_order(this.value, url); | 16 | send_order(this.value, url); |
| 18 | }); | 17 | }); |
| 19 | -}); | ||
| 20 | \ No newline at end of file | 18 | \ No newline at end of file |
| 19 | +}); |
test/functional/content_viewer_controller_test.rb
| @@ -329,6 +329,27 @@ class ContentViewerControllerTest < ActionController::TestCase | @@ -329,6 +329,27 @@ class ContentViewerControllerTest < ActionController::TestCase | ||
| 329 | assert_tag :content => /list my comment/ | 329 | assert_tag :content => /list my comment/ |
| 330 | end | 330 | end |
| 331 | 331 | ||
| 332 | + should 'order comments according to comments ordering option' do | ||
| 333 | + article = fast_create(Article, :profile_id => profile.id) | ||
| 334 | + for n in 1..24 | ||
| 335 | + article.comments.create!(:author => profile, :title => "some title #{n}", :body => "some body #{n}") | ||
| 336 | + end | ||
| 337 | + | ||
| 338 | + get 'view_page', :profile => profile.identifier, :page => article.path.split('/') | ||
| 339 | + | ||
| 340 | + for i in 1..12 | ||
| 341 | + assert_tag :tag => 'div', :attributes => { :class => 'comment-details' }, :descendant => { :tag => 'h4', :content => "some title #{i}" } | ||
| 342 | + assert_no_tag :tag => 'div', :attributes => { :class => 'comment-details' }, :descendant => { :tag => 'h4', :content => "some title #{i + 12}" } | ||
| 343 | + end | ||
| 344 | + | ||
| 345 | + xhr :get, :view_page, :profile => profile.identifier, :page => article.path.split('/'), :comment_page => 1, :comment_order => 'newest' | ||
| 346 | + | ||
| 347 | + for i in 1..12 | ||
| 348 | + assert_no_tag :tag => 'div', :attributes => { :class => 'comment-details' }, :descendant => { :tag => 'h4', :content => "some title #{i}" } | ||
| 349 | + assert_tag :tag => 'div', :attributes => { :class => 'comment-details' }, :descendant => { :tag => 'h4', :content => "some title #{i + 12}" } | ||
| 350 | + end | ||
| 351 | + end | ||
| 352 | + | ||
| 332 | should 'redirect to new article path under an old path' do | 353 | should 'redirect to new article path under an old path' do |
| 333 | p = create_user('test_user').person | 354 | p = create_user('test_user').person |
| 334 | a = p.articles.create(:name => 'old-name') | 355 | a = p.articles.create(:name => 'old-name') |
| @@ -1364,7 +1385,7 @@ class ContentViewerControllerTest < ActionController::TestCase | @@ -1364,7 +1385,7 @@ class ContentViewerControllerTest < ActionController::TestCase | ||
| 1364 | assert_equal 15, article.comments.count | 1385 | assert_equal 15, article.comments.count |
| 1365 | 1386 | ||
| 1366 | get 'view_page', :profile => profile.identifier, :page => article.path.split('/') | 1387 | get 'view_page', :profile => profile.identifier, :page => article.path.split('/') |
| 1367 | - assert_tag :tag => 'a', :attributes => { :href => "/#{profile.identifier}/#{article.path}?comment_page=2", :rel => 'next' } | 1388 | + assert_tag :tag => 'a', :attributes => { :href => "/#{profile.identifier}/#{article.path}?comment_order=oldest&comment_page=2", :rel => 'next' } |
| 1368 | end | 1389 | end |
| 1369 | 1390 | ||
| 1370 | should 'not escape acceptable HTML in list of blog posts' do | 1391 | should 'not escape acceptable HTML in list of blog posts' do |