aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/helpers/refinery/blog/posts_helper.rb4
-rw-r--r--app/models/refinery/blog/post.rb4
-rw-r--r--spec/models/refinery/blog/post_spec.rb11
3 files changed, 10 insertions, 9 deletions
diff --git a/app/helpers/refinery/blog/posts_helper.rb b/app/helpers/refinery/blog/posts_helper.rb
index 4653617..dfb742a 100644
--- a/app/helpers/refinery/blog/posts_helper.rb
+++ b/app/helpers/refinery/blog/posts_helper.rb
@@ -24,8 +24,8 @@ module Refinery
ArchiveWidget.new(dates, self).display
end
- def blog_archive_dates
- Refinery::Blog::Post.select('published_at').all_previous.map(&:published_at)
+ def blog_archive_dates(cutoff=Time.now.beginning_of_month)
+ Refinery::Blog::Post.published_dates_older_than(cutoff)
end
class ArchiveWidget
diff --git a/app/models/refinery/blog/post.rb b/app/models/refinery/blog/post.rb
index 822ddf7..b6d161c 100644
--- a/app/models/refinery/blog/post.rb
+++ b/app/models/refinery/blog/post.rb
@@ -71,8 +71,8 @@ module Refinery
where(['published_at between ? and ?', archive_year.beginning_of_year, archive_year.end_of_year])
end
- def all_previous
- where(['published_at <= ?', Time.now.beginning_of_month])
+ def published_dates_older_than(date)
+ where("published_at <= ?", date).map(&:published_at)
end
def live
diff --git a/spec/models/refinery/blog/post_spec.rb b/spec/models/refinery/blog/post_spec.rb
index 1d0a3e7..1e7ec5a 100644
--- a/spec/models/refinery/blog/post_spec.rb
+++ b/spec/models/refinery/blog/post_spec.rb
@@ -70,16 +70,17 @@ module Refinery
end
end
- describe "all_previous scope" do
+ describe ".published_dates_older_than" do
before do
@post1 = FactoryGirl.create(:blog_post, :published_at => Time.now - 2.months)
@post2 = FactoryGirl.create(:blog_post, :published_at => Time.now - 1.month)
FactoryGirl.create(:blog_post, :published_at => Time.now)
end
- it "returns all posts from previous months" do
- subject.class.all_previous.count.should be == 2
- subject.class.all_previous.should == [@post2, @post1]
+ it "returns all published dates older than the argument" do
+ expected = [@post2.published_at, @post1.published_at]
+
+ described_class.published_dates_older_than(1.day.ago).should eq(expected)
end
end
@@ -246,4 +247,4 @@ module Refinery
end
end
-end \ No newline at end of file
+end