/
models.rb
70 lines (51 loc) · 2.22 KB
/
models.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
class Post < ActiveRecord::Base
default_scope :order => "created_at ASC"
has_and_belongs_to_many :tags
def self.factory(text, created_at = nil)
create!(:text => text, :created_at => created_at)
end
end
class Tag < ActiveRecord::Base
has_and_belongs_to_many :posts
end
class Event < ActiveRecord::Base
named_scope :private, :conditions => { :public => false }
end
## seed data:
year = Time.zone.now.year
1.upto(12) do |month|
month.times do |n|
Post.factory "post #{n}", Time.local(year, month, 1)
end
end
Post.factory "Today's post"
Post.factory "Yesterday's post", 1.day.ago.utc
Post.factory "Tomorrow's post", 1.day.from_now.utc
Post.factory "That's it!", Time.zone.now.end_of_year
# For by_weekend scoped test
post = Post.factory "Weekend of May", "16-05-2009".to_time
post.tags.create(:name => "weekend")
# For by_day scoped test
post = Post.factory "Today", Time.zone.now
post.tags.create(:name => "today")
# For yesterday scoped test
post = Post.factory "Yesterday", Time.zone.now.yesterday
post.tags.create(:name => "yesterday")
# For tomorrow scoped test
post = Post.factory "Tomorrow's Another Day", Time.zone.now.tomorrow
post.tags.create(:name => "tomorrow")
post = Post.factory "Last year", Time.local(year - 1, 1, 1)
post.tags.create(:name => "ruby")
post = Post.factory "The 'Current' Fortnight", Time.local(year, 5, 15)
post.tags.create(:name => "may")
post = Post.factory "The 'Current' Week", Time.local(year, 5, 15)
post.tags.create(:name => "may2")
Event.create(:name => "Ryan's birthday!", :start_time => "04-12-#{Time.zone.now.year}".to_time)
Event.create(:name => "Dad's birthday!", :start_time => "05-07-#{Time.zone.now.year}".to_time)
Event.create(:name => "Mum's birthday!", :start_time => "17-11-#{Time.zone.now.year}".to_time)
Event.create(:name => "Today", :start_time => Time.zone.now)
Event.create(:name => "Yesterday", :start_time => Time.zone.now - 1.day)
Event.create(:name => "Tomorrow", :start_time => Time.zone.now + 1.day)
# For by_weekend test
Event.create(:name => "1st of August", :start_time => "01-08-#{Time.zone.now.year}".to_time)
Event.create(:name => "FBI meeting", :start_time => "02-03-#{Time.zone.now.year}".to_time, :public => false)