Renaming Method to better describe use, Including Deprecation Warning on Old Method
This commit is contained in:
parent
6fa5bbdf33
commit
86fa2d2f5d
3 changed files with 11 additions and 6 deletions
|
@ -60,7 +60,7 @@ module Refinery
|
|||
date = "#{params[:month]}/#{params[:year]}"
|
||||
@archive_date = Time.parse(date)
|
||||
@date_title = @archive_date.strftime('%B %Y')
|
||||
@posts = Post.live.by_archive(@archive_date).page(params[:page])
|
||||
@posts = Post.live.by_month(@archive_date).page(params[:page])
|
||||
else
|
||||
date = "01/#{params[:year]}"
|
||||
@archive_date = Time.parse(date)
|
||||
|
|
|
@ -53,10 +53,15 @@ module Refinery
|
|||
end
|
||||
|
||||
class << self
|
||||
def by_archive(date)
|
||||
def by_month(date)
|
||||
where(:published_at => date.beginning_of_month..date.end_of_month)
|
||||
end
|
||||
|
||||
def by_archive(date)
|
||||
warn "[Deprecation Warning] Refinery::Blog::Post.by_archive(date) has been replaced with by_month"
|
||||
by_month(date)
|
||||
end
|
||||
|
||||
def by_year(date)
|
||||
where(:published_at => date.beginning_of_year..date.end_of_year)
|
||||
end
|
||||
|
|
|
@ -53,7 +53,7 @@ module Refinery
|
|||
end
|
||||
end
|
||||
|
||||
describe "by_archive" do
|
||||
describe "by_month" do
|
||||
before do
|
||||
@post1 = FactoryGirl.create(:blog_post, :published_at => Date.new(2011, 3, 11))
|
||||
@post2 = FactoryGirl.create(:blog_post, :published_at => Date.new(2011, 3, 12))
|
||||
|
@ -65,8 +65,8 @@ module Refinery
|
|||
it "returns all posts from specified month" do
|
||||
#check for this month
|
||||
date = "03/2011"
|
||||
described_class.by_archive(Time.parse(date)).count.should be == 2
|
||||
described_class.by_archive(Time.parse(date)).should == [@post2, @post1]
|
||||
described_class.by_month(Time.parse(date)).count.should be == 2
|
||||
described_class.by_month(Time.parse(date)).should == [@post2, @post1]
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue