Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Re-implement today and yesterday methods

Using the by_day_Time_or_Date method
  • Loading branch information...
commit 8405f0ae5aa61c0a5966f5a51dcc6993b484d776 1 parent f543fbd
@radar authored
Showing with 31 additions and 2 deletions.
  1. +9 −2 lib/by_star/by_day.rb
  2. +22 −0 spec/by_star/by_day_spec.rb
View
11 lib/by_star/by_day.rb
@@ -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
View
22 spec/by_star/by_day_spec.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.