Commit 6ec69965ca3d6d7e79ef6e76661962ce525dec47
1 parent
3a4726cb
Exists in
master
and in
28 other branches
Fix pagination for parent contents at context content block
Showing
2 changed files
with
19 additions
and
1 deletions
Show diff stats
plugins/context_content/lib/context_content_block.rb
@@ -41,7 +41,7 @@ class ContextContentBlock < Block | @@ -41,7 +41,7 @@ class ContextContentBlock < Block | ||
41 | return @children unless @children.blank? | 41 | return @children unless @children.blank? |
42 | if page | 42 | if page |
43 | @children = page.children.with_types(types).paginate(:per_page => limit, :page => p) | 43 | @children = page.children.with_types(types).paginate(:per_page => limit, :page => p) |
44 | - (@children.blank? && show_parent_content) ? contents(page.parent) : @children | 44 | + (@children.blank? && show_parent_content) ? contents(page.parent, p) : @children |
45 | else | 45 | else |
46 | nil | 46 | nil |
47 | end | 47 | end |
plugins/context_content/test/unit/context_content_block_test.rb
@@ -48,6 +48,24 @@ class ContextContentBlockTest < ActiveSupport::TestCase | @@ -48,6 +48,24 @@ class ContextContentBlockTest < ActiveSupport::TestCase | ||
48 | assert_equal 2, @block.contents(folder).length | 48 | assert_equal 2, @block.contents(folder).length |
49 | end | 49 | end |
50 | 50 | ||
51 | + should 'show contents for next page' do | ||
52 | + @block.limit = 2 | ||
53 | + folder = fast_create(Folder) | ||
54 | + article1 = fast_create(TinyMceArticle, :parent_id => folder.id) | ||
55 | + article2 = fast_create(TinyMceArticle, :parent_id => folder.id) | ||
56 | + article3 = fast_create(TinyMceArticle, :parent_id => folder.id) | ||
57 | + assert_equal [article3], @block.contents(folder, 2) | ||
58 | + end | ||
59 | + | ||
60 | + should 'show parent contents for next page' do | ||
61 | + @block.limit = 2 | ||
62 | + folder = fast_create(Folder) | ||
63 | + article1 = fast_create(TinyMceArticle, :parent_id => folder.id) | ||
64 | + article2 = fast_create(TinyMceArticle, :parent_id => folder.id) | ||
65 | + article3 = fast_create(TinyMceArticle, :parent_id => folder.id) | ||
66 | + assert_equal [article3], @block.contents(article1, 2) | ||
67 | + end | ||
68 | + | ||
51 | should 'return parent children if page has no children' do | 69 | should 'return parent children if page has no children' do |
52 | folder = fast_create(Folder) | 70 | folder = fast_create(Folder) |
53 | article = fast_create(TinyMceArticle, :parent_id => folder.id) | 71 | article = fast_create(TinyMceArticle, :parent_id => folder.id) |