spec/finder_spec.rb in spandex-0.0.5 vs spec/finder_spec.rb in spandex-0.0.6

- old
+ new

@@ -25,11 +25,20 @@ create_file("stuff.md", :title => "The") create_file("more_stuff.textile", :title => "Sounds") make_finder.all_pages.map{|p| p.title}.should =~ ["The", "Sounds"] end - + + it "includes drafts" do + create_file("stuff.md", :draft => "true") + make_finder.all_pages.size.should == 1 + end + + it "ignores stray files" do + create_file("stuff.md~", :date => "1986/5/25") + make_finder.all_articles.should be_empty + end end context "when getting all articles" do it "works fine when there are no articles" do @@ -43,10 +52,21 @@ results = make_finder.all_articles results.size.should == 1 results[0].date.should == Date.civil(2011, 5, 25) end + it "excludes drafts by default" do + create_file("stuff.md", :date => "2011/5/25", :draft => "true") + make_finder.all_articles.size.should == 0 + end + + it "can include drafts" do + create_file("stuff.md", :date => "2011/5/25", :draft => "true") + create_file("more_stuff.md", :date => "2011/5/25", :draft => "false") + make_finder.all_articles(true).size.should == 2 + end + it "sorts by date descending" do create_file("stuff.md", :date => "1986/5/25") create_file("more_stuff.md", :date => "1982/5/25") create_file("even_more_stuff.md", :date => "2011/5/25") @@ -54,17 +74,11 @@ results.size.should == 3 [Date.civil(2011,5,25), Date.civil(1986,5,25), Date.civil(1982,5,25)].each_with_index do |date, i| results[i].date.should == date end - end - - it "ignores stray files" do - create_file("stuff.md~", :date => "1986/5/25") - make_finder.all_articles.should be_empty - end - + end end context "when generating an atom feed" do it "generates real atom content" do @@ -152,20 +166,10 @@ it "doesn't have to exist" do page = make_finder.get("this/is/not/a/real/file") page.should be_nil end - it "caches individual files" do - finder = make_finder - - create_file("stuff.md", :tags => "yeah") - finder.get("stuff").tags.should == ["yeah"] - - create_file("stuff.md", :tags => "nah") - finder.get("stuff").tags.should == ["yeah"] - end - it "doesn't muck up the cache" do create_file("stuff.md") finder = make_finder finder.all_pages finder.get("stuff") @@ -190,12 +194,10 @@ finder = make_finder finder.get("stuff") finder.get("/stuff") finder.all_pages.size.should == 1 end - - end context "when loading by filename" do it "does in fact load something" do create_file("stuff.md") @@ -208,11 +210,11 @@ page.should be_nil end end - context "when find pages" do + context "when finding pages" do it "can find them by tag" do create_file("no.md", :tags => "nono") create_file("yeah.md", :tags => "yeahyeah") @@ -222,12 +224,24 @@ end it "can find them by titles" do create_file("no.md", :title => "This has the wrong title") create_file("yeah.md", :title => "This has the correct title") + + results = make_finder.find_pages :title => "correct" + results.size.should == 1 + results.first.title.should == "This has the correct title" end + it "can find them by draft status" do + create_file "no.md" + create_file "yeah.md", :draft => "true" + results = make_finder.find_pages :draft => true + results.size.should == 1 + results.first.draft?.should == true + end + it "can find them by multiple metrics" do create_file("no.md", :tags => "yeah", :title => "This has the wrong title") create_file("yeah.md", :tags => "no", :title => "This has the correct title") create_file("definitely.md", :tags => "yeah", :title => "This has the correct title") @@ -235,15 +249,29 @@ end end context "when finding articles" do it "only finds articles" do - create_file("no.md", :tags => "yeahyeah") - create_file("yeah.md", :tags => "yeahyeah", :date => "2011/5/26", :title => "Yeah Yeah Yeah") + create_file "no.md", :tags => "yeahyeah" + create_file "yeah.md", :tags => "yeahyeah", :date => "2011/5/26", :title => "Yeah Yeah Yeah" - results = make_finder.find_articles(:tag => "yeahyeah") + results = make_finder.find_articles :tag => "yeahyeah" results.size.should == 1 results.first.title == "Yeah Yeah Yeah" + end + + it "excludes drafts by default" do + create_file "no.md", :tags => "yeahyeah", :date => "2010/5/25", :draft => "true" + create_file "yeah.md", :tags => "yeahyeah", :date => "2011/5/26", :title => "Yeah Yeah Yeah" + results = make_finder.find_articles :tag => "yeahyeah" + results.size.should == 1 + end + + it "can include drats" do + create_file "no.md", :tags => "yeahyeah", :date => "2010/5/25", :draft => "true" + create_file "yeah.md", :tags => "yeahyeah", :date => "2011/5/26", :title => "Yeah Yeah Yeah" + results = make_finder.find_articles :include_drafts => true, :tag => "yeahyeah" + results.size.should == 2 end end before(:each) do