event_test.rb
2.03 KB
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
require File.dirname(__FILE__) + '/../test_helper'
class EventTest < ActiveSupport::TestCase
should 'be an article' do
assert_kind_of Article, Event.new
end
should 'provide description' do
assert_kind_of String, Event.description
end
should 'provide short description' do
assert_kind_of String, Event.short_description
end
should 'have a description' do
e = Event.new(:description => 'some useful description')
assert_equal 'some useful description', e.description
end
should 'have a link' do
e = Event.new(:link => 'http://some.nice.site/')
assert_equal 'http://some.nice.site/', e.link
end
should 'have a start date' do
e = Event.new
e.start_date = Date.today
assert_kind_of Date, e.start_date
end
should 'require start date' do
e = Event.new
e.valid?
assert e.errors.invalid?(:start_date)
e.start_date = Date.today
e.valid?
assert !e.errors.invalid?(:start_date)
end
should 'have a end date' do
e = Event.new
e.end_date = Date.today
assert_kind_of Date, e.end_date
end
should 'be indexed by title' do
profile = create_user('testuser').person
e = Event.create!(:name => 'my surprisingly nice event', :start_date => Date.new(2008, 06, 06), :profile => profile)
assert_includes Event.find_by_contents('surprisingly'), e
end
should 'be indexed by description' do
profile = create_user('testuser').person
e = Event.create!(:name => 'bli', :start_date => Date.new(2008, 06, 06), :profile => profile, :description => 'my surprisingly long description about my freaking nice event')
assert_includes Event.find_by_contents('surprisingly'), e
end
should 'use its own icon' do
assert_equal 'event', Event.new.icon_name
end
should 'not allow end date before start date' do
e = Event.new(:start_date => Date.new(2008, 01, 01), :end_date => Date.new(2007,01,01))
e.valid?
assert e.errors.invalid?(:start_date)
e.end_date = Date.new(2008,01,05)
e.valid?
assert !e.errors.invalid?(:start_date)
end
end