Skip to content

Commit

Permalink
Re-implement today and yesterday methods
Browse files Browse the repository at this point in the history
Using the by_day_Time_or_Date method
  • Loading branch information
radar committed Feb 19, 2012
1 parent f543fbd commit 8405f0a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/by_star/by_day.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@ def by_day(*args)
end

def today(options={})
time = Time.zone.now
by_day_Time_or_Date(time, options)
by_day_Time_or_Date(Time.zone.now, options)
end

def yesterday(options={})
by_day_Time_or_Date(Time.zone.now.yesterday, options)
end

def tomorrow(options={})
by_day_Time_or_Date(Time.zone.now.tomorrow, options)
end

private
Expand Down
22 changes: 22 additions & 0 deletions spec/by_star/by_day_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,25 @@ def posts_count(*args)
Event.today(:field => "start_time").size.should eql(1)
end
end

describe "yesterday" do

it "should show the post for yesterday" do
Post.yesterday.map(&:text).should include("Yesterday")
end

it "should be able to use an alternative field" do
Event.yesterday(:field => "start_time").size.should eql(1)
end

end

describe "tomorrow" do
it "should show the post for tomorrow" do
Post.tomorrow.map(&:text).should include("Tomorrow's post")
end

it "should be able to use an alternative field" do
Event.tomorrow(:field => "start_time").size.should eql(1)
end
end

0 comments on commit 8405f0a

Please sign in to comment.