From 0012e836229a8e5dbb390a6926096040fa12993c Mon Sep 17 00:00:00 2001 From: Daniela Soares Feitosa Date: Thu, 12 Aug 2010 12:37:46 -0300 Subject: [PATCH] Fixed bug of blog posts pagination --- app/helpers/application_helper.rb | 2 +- test/functional/content_viewer_controller_test.rb | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index e64f026..91e42b5 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -947,7 +947,7 @@ module ApplicationHelper end def article_to_html(article, options = {}) - options.merge(:page => params[:npage]) + options.merge!(:page => params[:npage]) content = article.to_html(options) return self.instance_eval(&content) if content.kind_of?(Proc) content diff --git a/test/functional/content_viewer_controller_test.rb b/test/functional/content_viewer_controller_test.rb index 607f6a6..a4f8d49 100644 --- a/test/functional/content_viewer_controller_test.rb +++ b/test/functional/content_viewer_controller_test.rb @@ -614,6 +614,38 @@ class ContentViewerControllerTest < Test::Unit::TestCase assert_tag :tag => 'a', :attributes => { :href => "/#{profile.identifier}/#{blog.path}?npage=2", :rel => 'next' } end + should 'display first page of blog posts' do + blog = Blog.create!(:name => 'My blog', :profile => profile, :posts_per_page => 5) + for n in 1..10 + blog.children << TextileArticle.create!(:name => "Post #{n}", :profile => profile, :parent => blog) + end + assert_equal 10, blog.posts.size + + get :view_page, :profile => profile.identifier, :page => [blog.path] + for n in 1..5 + assert_no_tag :tag => 'h1', :attributes => { :class => 'title' }, :descendant => {:tag => 'a', :attributes => {:href => /\/#{profile.identifier}\/my-blog\/post-#{n}/}, :content => "Post #{n}"} + end + for n in 6..10 + assert_tag :tag => 'h1', :attributes => { :class => 'title' }, :descendant => {:tag => 'a', :attributes => {:href => /\/#{profile.identifier}\/my-blog\/post-#{n}/}, :content => "Post #{n}"} + end + end + + should 'display others pages of blog posts' do + blog = Blog.create!(:name => 'My blog', :profile => profile, :posts_per_page => 5) + for n in 1..10 + blog.children << TextileArticle.create!(:name => "Post #{n}", :profile => profile, :parent => blog) + end + assert_equal 10, blog.posts.size + + get :view_page, :profile => profile.identifier, :page => [blog.path], :npage => 2 + for n in 1..5 + assert_tag :tag => 'h1', :attributes => { :class => 'title' }, :descendant => {:tag => 'a', :attributes => {:href => /\/#{profile.identifier}\/my-blog\/post-#{n}/}, :content => "Post #{n}"} + end + for n in 6..10 + assert_no_tag :tag => 'h1', :attributes => { :class => 'title' }, :descendant => {:tag => 'a', :attributes => {:href => /\/#{profile.identifier}\/my-blog\/post-#{n}/}, :content => "Post #{n}"} + end + end + should 'set year and month filter from URL params' do profile.articles << Blog.new(:name => 'A blog test', :profile => profile) year, month = profile.blog.created_at.year.to_s, '%02d' % profile.blog.created_at.month -- libgit2 0.21.2