Skip to content

Commit

Permalink
Merge pull request refinery#236 from GeekOnCoffee/refactor_post_by_ar…
Browse files Browse the repository at this point in the history
…chive

Rename ::by_archive to ::to_month for clarity's sake.
  • Loading branch information
robyurkowski committed May 20, 2012
2 parents 6fa5bbd + ccf9c0e commit f4b647c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/controllers/refinery/blog/posts_controller.rb
Expand Up @@ -60,7 +60,7 @@ def archive
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)
Expand Down
9 changes: 7 additions & 2 deletions app/models/refinery/blog/post.rb
Expand Up @@ -53,10 +53,15 @@ def friendly_id_source
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)
Refinery.deprecate("Refinery::Blog::Post.by_archive(date)", {:replacement => "Refinery::Blog::Post.by_month(date)", :when => 2.2 })
by_month(date)
end

def by_year(date)
where(:published_at => date.beginning_of_year..date.end_of_year)
end
Expand Down
6 changes: 3 additions & 3 deletions spec/models/refinery/blog/post_spec.rb
Expand Up @@ -53,7 +53,7 @@ module Blog
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))
Expand All @@ -65,8 +65,8 @@ module Blog
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

Expand Down

0 comments on commit f4b647c

Please sign in to comment.