diff options
author | Philip Arndt <parndt@gmail.com> | 2012-02-22 23:43:01 -0800 |
---|---|---|
committer | Philip Arndt <parndt@gmail.com> | 2012-02-22 23:43:01 -0800 |
commit | f82d2c96e49cdb3c649358b5fd3fbf3f52389660 (patch) | |
tree | 1a58fb580bee0466c9135320f51ec01619e6417b /spec/helpers/refinery/blog/posts_helper_spec.rb | |
parent | aa729edc8495598693d758ad77608293e8be43c9 (diff) | |
parent | 2bcb7c85513c24d579c1134a47a5aeddf5968a9a (diff) | |
download | refinerycms-blog-f82d2c96e49cdb3c649358b5fd3fbf3f52389660.tar.gz refinerycms-blog-f82d2c96e49cdb3c649358b5fd3fbf3f52389660.tar.bz2 refinerycms-blog-f82d2c96e49cdb3c649358b5fd3fbf3f52389660.zip |
Merge pull request #195 from substantial/refactor_archive_widget
Refactor archive widget
Diffstat (limited to 'spec/helpers/refinery/blog/posts_helper_spec.rb')
-rw-r--r-- | spec/helpers/refinery/blog/posts_helper_spec.rb | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/spec/helpers/refinery/blog/posts_helper_spec.rb b/spec/helpers/refinery/blog/posts_helper_spec.rb new file mode 100644 index 0000000..b8c8911 --- /dev/null +++ b/spec/helpers/refinery/blog/posts_helper_spec.rb @@ -0,0 +1,71 @@ +require 'spec_helper' + +module Refinery + module Blog + describe PostsHelper do + describe "#blog_archive_widget" do + let(:html) { helper.blog_archive_widget(dates) } + let(:links) { Capybara.string(html).find("#blog_archive_widget ul") } + + context "with no archive dates" do + let(:dates) { [] } + + it "does not display anything" do + html.should be_blank + end + end + + context "with archive dates" do + let(:recent_post) { 2.months.ago } + let(:old_post) { 4.years.ago } + + let(:dates) do + [old_post, recent_post].map do |date| + [date, date.beginning_of_month, date.end_of_month] + end.flatten + end + + it "has a link for the month of dates not older than one year" do + month = Date::MONTHNAMES[recent_post.month] + year = recent_post.year + + links.should have_link("#{month} #{year} (3)") + end + + it "has a link for the year of dates older than one year" do + year = old_post.year + + links.should have_link("#{year} (3)") + end + + it "sorts recent links before old links" do + links.find("li:first").should have_content(recent_post.year.to_s) + links.find("li:last").should have_content(old_post.year.to_s) + end + end + + context "with multiple recent dates" do + let(:dates) { [3.months.ago, 2.months.ago] } + + it "sorts by the more recent date" do + first, second = dates.map {|p| Date::MONTHNAMES[p.month] } + + links.find("li:first").should have_content(second) + links.find("li:last").should have_content(first) + end + end + + context "with multiple old dates" do + let(:dates) { [5.years.ago, 4.years.ago] } + + it "sorts by the more recent date" do + first, second = dates.map {|p| p.year.to_s } + + links.find("li:first").should have_content(second) + links.find("li:last").should have_content(first) + end + end + end + end + end +end |