/
by_day.rb
62 lines (48 loc) · 1.57 KB
/
by_day.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
require 'spec_helper'
shared_examples_for "by day" do
describe "by day" do
def posts_count(*args)
Post.by_day(*args).count
end
it "should be able to find a post for today" do
posts_count.should eql(4)
end
it "should be able to find a post by a given date in last year" do
posts_count(:year => Time.zone.now.year - 1).should eql(1)
end
it "should be able to use an alternative field" do
Event.by_day(Time.now.yesterday, :field => "start_time").size.should eql(1)
end
it "should be able to use a date" do
posts_count(Date.today).should eql(4)
end
it "should be able to use a String" do
posts_count(Date.today.to_s).should eql(4)
end
end
describe "today" do
it "should show the post for today" do
Post.today.map(&:text).should include("Today's post")
end
it "should be able to use an alternative field" do
# Test may occur on an event day.
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's post")
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
end