/
by_direction_spec.rb
82 lines (65 loc) · 2.17 KB
/
by_direction_spec.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
require 'spec_helper'
describe "before" do
def posts_count(*args)
Post.before(*args).count
end
it "should show the correct number of posts in the past" do
posts_count.should == 9
end
it "is aliased as before_now" do
Post.before_now.count.should == 9
end
it "should find for a given time" do
posts_count(Time.zone.now - 2.days).should eql(1)
end
it "should find for a given date" do
posts_count(Date.today - 2).should eql(1)
end
it "should find for a given string" do
posts_count("next tuesday").should eql(11)
end
it "raises an exception when Chronic can't parse" do
lambda { posts_count(";aosdjbjisdabdgofbi") }.should raise_error(ByStar::ParseError)
end
it "should be able to find all events before Ryan's birthday using a non-standard field" do
Event.before(Time.local(Time.zone.now.year+2), :field => "start_time").count.should eql(8)
end
end
describe "future" do
def posts_count(*args)
Post.after(*args).count
end
it "should show the correct number of posts in the future" do
Post.after.count.should eql(posts_count)
Post.after_now.count.should eql(posts_count)
end
it "should find for a given date" do
posts_count(Date.today - 2).should eql(23)
end
it "should find for a given string" do
posts_count("next tuesday").should eql(13)
end
it "should be able to find all events before Dad's birthday using a non-standard field" do
Event.after(Time.zone.local(Time.zone.now.year, 7, 5), :field => "start_time").count.should eql(3)
end
end
describe "previous and next" do
let(:current_post) { Post.find_by_text("post 1") }
let(:current_event) { Event.find_by_name("Mum's birthday!") }
context "previous" do
it "can find the previous post" do
current_post.previous.text.should == "Last year"
end
it "takes the field option" do
current_event.previous(:field => "start_time").name.should == "Dad's birthday!"
end
end
context "next" do
it "can find the next post" do
current_post.next.text.should == "Today's post"
end
it "takes the field option" do
current_event.next(:field => "start_time").name.should == "Ryan's birthday!"
end
end
end