Skip to content

Commit

Permalink
Merge branch 'simplicitybg-sort-posts'
Browse files Browse the repository at this point in the history
  • Loading branch information
GBH committed May 10, 2018
2 parents 7f04203 + 2a623a3 commit 99824c7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/controllers/comfy/blog/posts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def index
end

scope = scope.for_category(params[:category]) if params[:category]
scope = scope.order(:published_at).reverse_order

@blog_posts = comfy_paginate(scope, per_page: ComfyBlog.config.posts_per_page)
render layout: ComfyBlog.config.app_layout
Expand Down
15 changes: 15 additions & 0 deletions test/controllers/comfy/blog/posts_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,21 @@ def test_get_index_with_category_invalid
assert_equal 0, assigns(:blog_posts).count
end

def test_get_index_is_sorted
new_post = @site.blog_posts.create!(
title: "Test Post",
published_at: @post.published_at + 1.day,
layout: comfy_cms_layouts(:default)
)

get comfy_blog_posts_path

assert_response :success
assert assigns(:blog_posts)
assert_equal 2, assigns(:blog_posts).count
assert_equal [new_post, @post], assigns(:blog_posts).to_a
end

def test_get_show
@post.update_column(:content_cache, "blog post content")
get comfy_blog_post_path(@site.path, @post.year, @post.month, @post.slug)
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/comfy/blog/posts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ default:
is_published: true
year: 2012
month: 1
published_at: <%= 2.days.ago %>
published_at: 2012-01-01 01:23:00
layout: default

0 comments on commit 99824c7

Please sign in to comment.