Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit d7c0758

Browse files
author
keegan
committed
Filled out and updated unit tests. Also updated TODO.
git-svn-id: http://svn.pdxruby.org/repos/www/trunk@202 f0fbaf97-c700-0410-a5eb-8ea856f8537e
1 parent 4e4b50d commit d7c0758

File tree

7 files changed

+363
-233
lines changed

7 files changed

+363
-233
lines changed

doc/TODO

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ _Other_
2727

2828
- User should be able to delete their own account...
2929

30+
- Validation for Article, plus tests to match.
31+
32+
- Some pseudo-relationships implemented using map can be done with
33+
has_many :through instead.
34+
3035
_Cosmetic_
3136

3237
- on Edit/New Event, when existing location is selected, alternative location
@@ -45,10 +50,6 @@ _Testing_
4550
- write functional tests for index_controller.rb
4651
- write functional tests for locations_controller.rb
4752
- write functional tests for participants_controller.rb
48-
- write unit tests for article.rb
49-
- write unit tests for event.rb
50-
- write unit tests for feedback.rb
51-
- write unit tests for participant.rb
5253

5354
_Feeds_
5455

test/unit/article_test.rb

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,29 @@ class ArticleTest < Test::Unit::TestCase
44
fixtures :articles
55

66
def setup
7-
@article = Article.find(1)
7+
@article = Article.new
88
end
99

10-
# Replace this with your real tests.
11-
def test_truth
12-
assert_kind_of Article, @article
10+
def test_create_read_update_delete
11+
assert(@article.save)
12+
13+
read_article = Article.find @article.id
14+
15+
assert_equal(@article.id, read_article.id)
16+
17+
@article.title = 'Just a test'
18+
19+
assert(@article.save)
20+
21+
assert(@article.destroy)
22+
end
23+
24+
def test_associations
25+
assert_kind_of(Member, articles(:hamster).member)
26+
end
27+
28+
def test_filtered_content
29+
@article.content = '<script>something bad</script> other'
30+
assert_equal('[script] other', @article.filtered_content)
1331
end
1432
end

test/unit/event_test.rb

Lines changed: 144 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,153 @@
11
require File.dirname(__FILE__) + '/../test_helper'
22

33
class EventTest < Test::Unit::TestCase
4-
fixtures :events
4+
fixtures :events, :feedbacks, :locations, :members, :participants
55

66
def setup
7-
@event = Event.find(1)
7+
@event = Event.new
8+
9+
@event.name = 'Unit test'
10+
@event.agenda = 'Testing stuff'
11+
@event.starts_at = Time.now
12+
@event.ends_at = Time.now
13+
@event.location = locations(:first)
14+
@event.status = 'active'
15+
end
16+
17+
def test_create_read_update_delete
18+
assert(@event.save)
19+
20+
read_event = locations(:first).events.find_by_name('Unit test')
21+
22+
assert_equal(@event.agenda, read_event.agenda)
23+
24+
@event.agenda = 'Testing a lot of stuff'
25+
26+
assert(@event.save)
27+
28+
assert(@event.destroy)
29+
end
30+
31+
def test_associations
32+
assert_kind_of(Member, events(:peats_baby_shower).member)
33+
assert_kind_of(Location, events(:peats_baby_shower).location)
34+
assert_kind_of(Array, events(:peats_baby_shower).participants)
35+
end
36+
37+
def test_validates_presence_of_name
38+
@event.name = nil
39+
40+
assert_equal(false, @event.save)
41+
end
42+
43+
def test_validates_presence_of_agenda
44+
@event.agenda = nil
45+
46+
assert_equal(false, @event.save)
47+
end
48+
49+
def test_validates_presence_of_starts_at
50+
@event.starts_at = nil
51+
52+
assert_equal(false, @event.save)
53+
end
54+
55+
def test_validates_presence_of_ends_at
56+
@event.ends_at = nil
57+
58+
assert_equal(false, @event.save)
59+
end
60+
61+
def test_validates_presence_of_location_id
62+
@event.location = nil
63+
64+
assert_equal(false, @event.save)
65+
end
66+
67+
def test_validates_length_of_name
68+
@event.name = 'This is a very long name for an event - perhaps even ' +
69+
'a little bit *too* long. Oh no!'
70+
71+
assert_equal(false, @event.save)
72+
end
73+
74+
def test_validates_status
75+
@event.status = nil
76+
77+
assert_equal(false, @event.save)
78+
end
79+
80+
def test_validates_starts_at
81+
@event.starts_at = Time.now + 1000
82+
83+
assert_equal(false, @event.save)
84+
end
85+
86+
def test_validates_ends_at
87+
@event.ends_at = Time.now - 1000
88+
89+
assert_equal(false, @event.save)
90+
end
91+
92+
def test_cancelled?
93+
assert_equal(false, @event.cancelled?)
94+
end
95+
96+
def test_cancel!
97+
@event.cancel!
98+
99+
assert(@event.cancelled?)
100+
end
101+
102+
def test_active?
103+
assert_equal(true, @event.active?)
104+
end
105+
106+
def test_active!
107+
@event.cancel!
108+
109+
assert_equal(false, @event.active?)
110+
111+
@event.active!
112+
113+
assert(@event.active?)
114+
end
115+
116+
def test_has_participant
117+
assert_equal(false,
118+
events(:peats_baby_shower).has_participant(members(:sue)))
119+
120+
assert_equal(true,
121+
events(:peats_baby_shower).has_participant(members(:bob)))
122+
end
123+
124+
def test_started?
125+
@event.starts_at = Time.now - 1000
126+
@event.ends_at = Time.now + 1000
127+
128+
assert_equal(true, @event.started?)
129+
end
130+
131+
def test_ended?
132+
@event.starts_at = Time.now - 2000
133+
@event.ends_at = Time.now - 1000
134+
135+
assert_equal(true, @event.ended?)
136+
end
137+
138+
def test_feedbacks
139+
assert_equal([ feedbacks(:first) ], events(:peats_baby_shower).feedbacks)
140+
end
141+
142+
def test_unclaimed?
143+
assert_equal(true, @event.unclaimed?)
144+
end
145+
146+
def test_find_upcoming
147+
assert_equal([ events(:bens_high_school_prom) ], Event.find_upcoming)
8148
end
9149

10-
# Replace this with your real tests.
11-
def test_truth
12-
assert_kind_of Event, @event
150+
def test_find_recent
151+
assert_equal([ events(:peats_baby_shower) ], Event.find_recent)
13152
end
14153
end

test/unit/feedback_test.rb

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,24 @@ class FeedbackTest < Test::Unit::TestCase
44
fixtures :feedbacks
55

66
def setup
7-
@feedback = Feedback.find(1)
7+
@feedback = Feedback.new
88
end
99

10-
# Replace this with your real tests.
11-
def test_truth
12-
assert_kind_of Feedback, @feedback
10+
def test_create_read_update_delete
11+
assert(@feedback.save)
12+
13+
read_feedback = Feedback.find @feedback.id
14+
15+
assert_equal(@feedback.id, read_feedback.id)
16+
17+
@feedback.feedback = 'Testing'
18+
19+
assert(@feedback.save)
20+
21+
assert(@feedback.destroy)
22+
end
23+
24+
def test_associations
25+
assert_kind_of(Participant, feedbacks(:first).participant)
1326
end
1427
end

0 commit comments

Comments
 (0)