1 require File.dirname(__FILE__) + '/../helpers'
4 class PostTest < Test::Unit::TestCase
6 should "raise an error if trying to load a `Post` from a non-existant file" do
7 assert_raise(RuntimeError) { Bloggit::Post.from_file 'crapfile.post' }
10 should "parse `Post` from file" do
11 assert_nothing_raised(RuntimeError) do
12 post = Bloggit::Post.from_file File.join(File.dirname(__FILE__), '../fixtures/test.blog/posts/2004.03.07_to-boldly-go.post')
14 assert_equal 'to-boldly-go', post.slug
15 assert_equal 2004, post.post_year
19 should "parse publish date and slug" do
20 assert_nothing_raised(RuntimeError) do
22 post = Bloggit::Post.from_file File.join(File.dirname(__FILE__), '../fixtures/test.blog/posts/2004.03.07_to-boldly-go.post')
24 assert_equal 'to-boldly-go', post.slug
25 assert_equal 2004, post.post_year
26 assert_equal Time, post.publish_date.class
28 post = Bloggit::Post.from_file File.join(File.dirname(__FILE__), '../fixtures/test.blog/posts/2007.03.25_sure-whatever.post')
30 assert_equal 'sure-whatever', post.slug
31 assert_equal 2007, post.post_year
32 assert_equal Time, post.publish_date.class
36 should "allowing finding by tag" do
37 site = Bloggit::Site.from_file(File.join(File.dirname(__FILE__), '../fixtures/test.blog') )
38 posts = Post.find_by_tag 'two'
39 assert_equal 2, posts.length
41 posts = Post.find_by_tags ['two', 'one']
42 assert_equal 2, posts.length
44 posts = Post.find_by_tag ['one']
45 assert_equal 3, posts.length
47 posts = Post.find_by_tag ['rdoc']
48 assert_equal 1, posts.length
49 puts posts[0].publish_date