Commit 0012e836229a8e5dbb390a6926096040fa12993c

Authored by Daniela Feitosa
Committed by Antonio Terceiro
1 parent 55ac1172

Fixed bug of blog posts pagination

(ActionItem1622)
app/helpers/application_helper.rb
... ... @@ -947,7 +947,7 @@ module ApplicationHelper
947 947 end
948 948  
949 949 def article_to_html(article, options = {})
950   - options.merge(:page => params[:npage])
  950 + options.merge!(:page => params[:npage])
951 951 content = article.to_html(options)
952 952 return self.instance_eval(&content) if content.kind_of?(Proc)
953 953 content
... ...
test/functional/content_viewer_controller_test.rb
... ... @@ -614,6 +614,38 @@ class ContentViewerControllerTest < Test::Unit::TestCase
614 614 assert_tag :tag => 'a', :attributes => { :href => "/#{profile.identifier}/#{blog.path}?npage=2", :rel => 'next' }
615 615 end
616 616  
  617 + should 'display first page of blog posts' do
  618 + blog = Blog.create!(:name => 'My blog', :profile => profile, :posts_per_page => 5)
  619 + for n in 1..10
  620 + blog.children << TextileArticle.create!(:name => "Post #{n}", :profile => profile, :parent => blog)
  621 + end
  622 + assert_equal 10, blog.posts.size
  623 +
  624 + get :view_page, :profile => profile.identifier, :page => [blog.path]
  625 + for n in 1..5
  626 + assert_no_tag :tag => 'h1', :attributes => { :class => 'title' }, :descendant => {:tag => 'a', :attributes => {:href => /\/#{profile.identifier}\/my-blog\/post-#{n}/}, :content => "Post #{n}"}
  627 + end
  628 + for n in 6..10
  629 + assert_tag :tag => 'h1', :attributes => { :class => 'title' }, :descendant => {:tag => 'a', :attributes => {:href => /\/#{profile.identifier}\/my-blog\/post-#{n}/}, :content => "Post #{n}"}
  630 + end
  631 + end
  632 +
  633 + should 'display others pages of blog posts' do
  634 + blog = Blog.create!(:name => 'My blog', :profile => profile, :posts_per_page => 5)
  635 + for n in 1..10
  636 + blog.children << TextileArticle.create!(:name => "Post #{n}", :profile => profile, :parent => blog)
  637 + end
  638 + assert_equal 10, blog.posts.size
  639 +
  640 + get :view_page, :profile => profile.identifier, :page => [blog.path], :npage => 2
  641 + for n in 1..5
  642 + assert_tag :tag => 'h1', :attributes => { :class => 'title' }, :descendant => {:tag => 'a', :attributes => {:href => /\/#{profile.identifier}\/my-blog\/post-#{n}/}, :content => "Post #{n}"}
  643 + end
  644 + for n in 6..10
  645 + assert_no_tag :tag => 'h1', :attributes => { :class => 'title' }, :descendant => {:tag => 'a', :attributes => {:href => /\/#{profile.identifier}\/my-blog\/post-#{n}/}, :content => "Post #{n}"}
  646 + end
  647 + end
  648 +
617 649 should 'set year and month filter from URL params' do
618 650 profile.articles << Blog.new(:name => 'A blog test', :profile => profile)
619 651 year, month = profile.blog.created_at.year.to_s, '%02d' % profile.blog.created_at.month
... ...