test/blog_spec.rb in shinmun-0.5.2 vs test/blog_spec.rb in shinmun-0.9
- old
+ new
@@ -1,5 +1,7 @@
+$:.unshift "#{File.dirname __FILE__}/../lib"
+
require 'shinmun'
require 'rack/mock'
require 'rexml/document'
require 'rexml/xpath'
require 'pp'
@@ -25,18 +27,23 @@
:language => 'en',
:author => 'The Author',
:categories => ['Ruby', 'Javascript']
}
- @posts = [blog.create_post(:title => 'New post', :date => '2008-10-10', :category => 'Ruby', :body => 'Body1'),
- blog.create_post(:title => 'And this', :date => '2008-10-11', :category => 'Ruby', :body => 'Body2'),
- blog.create_post(:title => 'Again', :date => '2008-11-10', :category => 'Javascript', :body => 'Body3')]
+ @posts = [Shinmun::Post.new(:title => 'New post', :date => Date.new(2008,10,10), :category => 'Ruby', :body => 'Body1'),
+ Shinmun::Post.new(:title => 'And this', :date => Date.new(2008,10,11), :category => 'Ruby', :body => 'Body2'),
+ Shinmun::Post.new(:title => 'Again', :date => Date.new(2008,11,10), :category => 'Javascript', :body => 'Body3')]
- @pages = [blog.create_page(:title => 'Page 1', :body => 'Body1'),
- blog.create_page(:title => 'Page 2', :body => 'Body2')]
+ @pages = {
+ 'page-1' => Shinmun::Post.new(:title => 'Page 1', :body => 'Body1'),
+ 'page-2' => Shinmun::Post.new(:title => 'Page 2', :body => 'Body2')
+ }
- blog.store.load
+ blog.instance_variable_set('@posts', @posts)
+ blog.instance_variable_set('@pages', @pages)
+
+ blog.sort_posts
end
def request(method, uri, options={})
@request = Rack::MockRequest.new(blog)
@response = @request.request(method, uri, options)
@@ -71,58 +78,33 @@
it "should load templates" do
blog.load_template("index.rhtml").should be_kind_of(ERB)
end
it "should find posts for a category" do
- category = blog.find_category('ruby')
- category[:name].should == 'Ruby'
+ blog.find_category('ruby').should == 'Ruby'
- category[:posts].should include(@posts[0])
- category[:posts].should include(@posts[1])
+ blog.posts_by_category['Ruby'].should include(@posts[0])
+ blog.posts_by_category['Ruby'].should include(@posts[1])
- category = blog.find_category('javascript')
- category[:name].should == 'Javascript'
- category[:posts].should include(@posts[2])
+ blog.find_category('javascript').should == 'Javascript'
+ blog.posts_by_category['Javascript'].should include(@posts[2])
end
- it "should create a post" do
- post = blog.create_post(:title => 'New post', :date => '2008-10-10')
- blog.store.load
-
- post = blog.find_post(2008, 10, 'new-post')
- post.should_not be_nil
- post.title.should == 'New post'
- post.date.should == Date.new(2008, 10, 10)
- post.name.should == 'new-post'
- end
-
it "should render posts" do
xml = get('/2008/10/new-post').body
-
+
xpath(xml, "//h1")[0].text.should == 'New post'
xpath(xml, "//p")[0].text.should == 'Body1'
end
- it "should render categories" do
- get('/categories/ruby.rss')['Content-Type'].should == 'application/rss+xml'
-
- xml = get('/categories/ruby.rss').body
-
- xpath(xml, '/rss/channel/title')[0].text.should == 'Ruby'
- xpath(xml, '/rss/channel/item/title')[0].text.should == 'And this'
- xpath(xml, '/rss/channel/item/pubDate')[0].text.should == "Sat, 11 Oct 2008 00:00:00 +0000"
- xpath(xml, '/rss/channel/item/link')[0].text.should == "http://example.org/2008/10/and-this"
- xpath(xml, '/rss/channel/item/title')[1].text.should == 'New post'
- xpath(xml, '/rss/channel/item/pubDate')[1].text.should == "Fri, 10 Oct 2008 00:00:00 +0000"
- xpath(xml, '/rss/channel/item/link')[1].text.should == "http://example.org/2008/10/new-post"
-
+ it "should render categories" do
assert_listing(get('/categories/ruby').body, [['And this', 'Body2'], ['New post', 'Body1']])
end
it "should render index and archives" do
- blog.posts_for_month(2008, 10).should_not be_empty
- blog.posts_for_month(2008, 11).should_not be_empty
+ blog.posts_by_date[2008][10].should_not be_empty
+ blog.posts_by_date[2008][11].should_not be_empty
assert_listing(get('/2008/10').body, [['And this', 'Body2'], ['New post', 'Body1']])
assert_listing(get('/').body, [['Again', 'Body3'], ['And this', 'Body2'], ['New post', 'Body1']])
end
@@ -134,23 +116,13 @@
xml = get('/page-2').body
xpath(xml, "//h1")[0].text.should == 'Page 2'
xpath(xml, "//p")[0].text.should == 'Body2'
end
- it "should post a comment" do
- post "/2008/10/new-post/comments?name=Hans&text=Hallo"
- post "/2008/10/new-post/comments?name=Peter&text=Servus"
+ it "should render a post" do
+ xml = get('/2008/10/new-post').body
- blog.store.load
-
- comments = blog.comments_for(@posts[0])
-
- comments[0].should_not be_nil
- comments[0].name.should == 'Hans'
- comments[0].text.should == 'Hallo'
-
- comments[1].should_not be_nil
- comments[1].name.should == 'Peter'
- comments[1].text.should == 'Servus'
+ xpath(xml, "//h1")[0].text.should == 'New post'
+ xpath(xml, "//div[@class='date']")[0].text.strip.should == 'October 10, 2008'
end
end