From e4a2319bf3e9b9bf7c7775263424e76426911897 Mon Sep 17 00:00:00 2001 From: Kris Brown Date: Sat, 16 Jan 2010 14:48:21 +0000 Subject: [PATCH] added tests to show how date and tags can end up having the wrong value when rendered --- .../_posts/2010-01-09-date-override.textile | 2 + .../_posts/2010-01-09-time-override.textile | 2 + .../2010-01-09-timezone-override.textile | 7 ++++ .../_posts/2010-01-16-override-data.textile | 4 ++ test/test_generated_site.rb | 2 +- test/test_post.rb | 40 +++++++++++++++++++ 6 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 test/source/_posts/2010-01-09-timezone-override.textile create mode 100644 test/source/_posts/2010-01-16-override-data.textile diff --git a/test/source/_posts/2010-01-09-date-override.textile b/test/source/_posts/2010-01-09-date-override.textile index efe8af4a..45b3834a 100644 --- a/test/source/_posts/2010-01-09-date-override.textile +++ b/test/source/_posts/2010-01-09-date-override.textile @@ -3,3 +3,5 @@ date: 2010-01-10 --- Post with a front matter date + +{{ page.date | date_to_string }} diff --git a/test/source/_posts/2010-01-09-time-override.textile b/test/source/_posts/2010-01-09-time-override.textile index 7f80065a..e462c418 100644 --- a/test/source/_posts/2010-01-09-time-override.textile +++ b/test/source/_posts/2010-01-09-time-override.textile @@ -3,3 +3,5 @@ date: 2010-01-10 13:07:09 --- Post with a front matter time + +{{ page.date | date_to_string }} diff --git a/test/source/_posts/2010-01-09-timezone-override.textile b/test/source/_posts/2010-01-09-timezone-override.textile new file mode 100644 index 00000000..3dc0e4fa --- /dev/null +++ b/test/source/_posts/2010-01-09-timezone-override.textile @@ -0,0 +1,7 @@ +--- +date: 2010-01-10 13:07:09 +00:00 +--- + +Post with a front matter time with timezone + +{{ page.date | date_to_string }} diff --git a/test/source/_posts/2010-01-16-override-data.textile b/test/source/_posts/2010-01-16-override-data.textile new file mode 100644 index 00000000..5b1a95c4 --- /dev/null +++ b/test/source/_posts/2010-01-16-override-data.textile @@ -0,0 +1,4 @@ +--- +date: 2010-01-10 13:07:09 +tags: A string +--- diff --git a/test/test_generated_site.rb b/test/test_generated_site.rb index a276e572..bfb86daa 100644 --- a/test/test_generated_site.rb +++ b/test/test_generated_site.rb @@ -14,7 +14,7 @@ class TestGeneratedSite < Test::Unit::TestCase end should "ensure post count is as expected" do - assert_equal 24, @site.posts.size + assert_equal 26, @site.posts.size end should "insert site.posts into the index" do diff --git a/test/test_post.rb b/test/test_post.rb index f57f530d..7c602c67 100644 --- a/test/test_post.rb +++ b/test/test_post.rb @@ -227,12 +227,37 @@ class TestPost < Test::Unit::TestCase should "recognize date in yaml" do post = setup_post("2010-01-09-date-override.textile") + do_render(post) + assert_equal Time, post.date.class + assert_equal Time, post.to_liquid["date"].class assert_equal "/2010/01/10/date-override.html", post.url + assert_equal "

Post with a front matter date

\n

10 Jan 2010

", post.output end should "recognize time in yaml" do post = setup_post("2010-01-09-time-override.textile") + do_render(post) + assert_equal Time, post.date.class + assert_equal Time, post.to_liquid["date"].class assert_equal "/2010/01/10/time-override.html", post.url + assert_equal "

Post with a front matter time

\n

10 Jan 2010

", post.output + end + + should "recognize time with timezone in yaml" do + post = setup_post("2010-01-09-timezone-override.textile") + do_render(post) + assert_equal Time, post.date.class + assert_equal Time, post.to_liquid["date"].class + assert_equal "/2010/01/10/timezone-override.html", post.url + assert_equal "

Post with a front matter time with timezone

\n

10 Jan 2010

", post.output + end + + should "to_liquid prioritizes post attributes over data" do + post = setup_post("2010-01-16-override-data.textile") + assert_equal Array, post.tags.class + assert_equal Array, post.to_liquid["tags"].class + assert_equal Time, post.date.class + assert_equal Time, post.to_liquid["date"].class end should "recognize category in yaml" do @@ -333,6 +358,21 @@ class TestPost < Test::Unit::TestCase assert_equal "<<<
\n

Tom Preston-Werner github.com/mojombo

\n\n

This is cool

>>>", post.output end + + should "render date specified in front matter properly" do + post = setup_post("2010-01-09-date-override.textile") + do_render(post) + + assert_equal "

Post with a front matter date

\n

10 Jan 2010

", post.output + end + + should "render time specified in front matter properly" do + post = setup_post("2010-01-09-time-override.textile") + do_render(post) + + assert_equal "

Post with a front matter time

\n

10 Jan 2010

", post.output + end + end end