-
-
Save pat/139854 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Examples: | |
# Post.by_day | |
# Post.by_day(Time.yesterday) | |
# Post.by_day("next tuesday") | |
def by_day(time = Time.zone.now, options = {}, &block) | |
time = parse(time) | |
by_star(time.utc.beginning_of_day, time.utc.end_of_day, options, &block) | |
end | |
alias_method :today, :by_day | |
# Examples: | |
# Post.yesterday | |
# # 2 days ago: | |
# Post.yesterday(Time.yesterday) | |
# # day before next tuesday | |
# Post.yesterday("next tuesday") | |
def yesterday(time = Time.zone.now, options = {}, &block) | |
time = parse(time) | |
by_day(time.advance(:days => -1), options, &block) | |
end | |
# Examples: | |
# Post.tomorrow | |
# # 2 days from now: | |
# Post.tomorrow(Time.tomorrow) | |
# # day after next tuesday | |
# Post.tomorrow("next tuesday") | |
def tomorrow(time = Time.zone.now, options = {}, &block) | |
time = parse(time) | |
by_day(time.advance(:days => 1), options, &block) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def find(*args) | |
method = description_args.first.sub(' ', '_') | |
Post.send(method, *args) | |
end | |
describe "today" do | |
it "should show the post for tomorrow" do | |
find("tomorrow").map(&:text).should include("Tomorrow's post") | |
end | |
end | |
describe "yesterday" do | |
it "should be able find yesterday, given a Date" do | |
find(Date.today).map(&:text).should include("Yesterday's post") | |
end | |
end | |
describe "tomorrow" do | |
it "should be able find tomorrow, given a Date" do | |
find(Date.today).map(&:text).should include("Tomorrow's post") | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Failures for by_star only occur (seemingly) in a positive timezone where the local time is in a day in the future from UTC. | |
So in +1000 (Brisbane) these three specs only fail BEFORE 10am. After 10am it's a sea of wonderful green. | |
..................................F..F..F................................... | |
1) | |
'Post today should show the post for tomorrow' FAILED | |
expected ["Today's post", "Today"] to include "Tomorrow's post" | |
./spec/by_star_spec.rb:197: | |
2) | |
'Post yesterday should be able find yesterday, given a Date' FAILED | |
expected ["Today's post", "Today"] to include "Yesterday's post" | |
./spec/by_star_spec.rb:213: | |
3) | |
'Post tomorrow should be able find tomorrow, given a Date' FAILED | |
expected [] to include "Tomorrow's post" | |
./spec/by_star_spec.rb:230: | |
Finished in 0.263454 seconds | |
76 examples, 3 failures |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment