From e5c62eb726850526ef20ec6fad62b7c098143ef8 Mon Sep 17 00:00:00 2001 From: Georgi Kirichkov Date: Thu, 10 May 2018 09:33:07 +0300 Subject: [PATCH] Adds a test for sorting posts by their published_at date --- .../comfy/blog/posts_controller_test.rb | 22 +++++++++++++++++++ test/fixtures/comfy/blog/posts.yml | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/test/controllers/comfy/blog/posts_controller_test.rb b/test/controllers/comfy/blog/posts_controller_test.rb index ad41a1a..9311673 100644 --- a/test/controllers/comfy/blog/posts_controller_test.rb +++ b/test/controllers/comfy/blog/posts_controller_test.rb @@ -74,6 +74,28 @@ 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!( + site: comfy_cms_sites(:default), + title: "Default title 2", + slug: "default-title-2", + is_published: true, + year: 2012, + month: 1, + published_at: DateTime.new(2012, 1, 1, 1, 24, 0), + 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, assigns(:blog_posts)[0] + assert_equal comfy_blog_posts(:default), assigns(:blog_posts)[1] + 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) diff --git a/test/fixtures/comfy/blog/posts.yml b/test/fixtures/comfy/blog/posts.yml index 02eb214..cbe327c 100644 --- a/test/fixtures/comfy/blog/posts.yml +++ b/test/fixtures/comfy/blog/posts.yml @@ -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