Commit 446eea30169bd2debc6b5d1f9d1635e765c43175
1 parent
01158469
Exists in
master
and in
29 other branches
ActionItem22: adding comment class
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1111 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
3 changed files
with
71 additions
and
0 deletions
Show diff stats
@@ -0,0 +1,26 @@ | @@ -0,0 +1,26 @@ | ||
1 | +class CreateComments < ActiveRecord::Migration | ||
2 | + def self.up | ||
3 | + create_table :comments do |t| | ||
4 | + | ||
5 | + # acts as filesystem | ||
6 | + t.column :title, :string | ||
7 | + t.column :body, :text | ||
8 | + | ||
9 | + # belongs to an article | ||
10 | + t.column :article_id, :integer | ||
11 | + | ||
12 | + # belongs to a person, maybe unauthenticated | ||
13 | + t.column :author_id, :integer | ||
14 | + t.column :name, :string | ||
15 | + t.column :email, :string | ||
16 | + | ||
17 | + # keep track of changes | ||
18 | + t.column :created_on, :datetime | ||
19 | + end | ||
20 | + | ||
21 | + end | ||
22 | + | ||
23 | + def self.down | ||
24 | + drop_table :comments | ||
25 | + end | ||
26 | +end |
@@ -0,0 +1,40 @@ | @@ -0,0 +1,40 @@ | ||
1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
2 | + | ||
3 | +class CommentTest < Test::Unit::TestCase | ||
4 | + | ||
5 | + should 'have a name and require it' do | ||
6 | + assert_mandatory(Comment.new, :title) | ||
7 | + end | ||
8 | + | ||
9 | + should 'have a body and require it' do | ||
10 | + assert_mandatory(Comment.new, :body) | ||
11 | + end | ||
12 | + | ||
13 | + should 'belong to an article' do | ||
14 | + c = Comment.new | ||
15 | + assert_raise ActiveRecord::AssociationTypeMismatch do | ||
16 | + c.article = 1 | ||
17 | + end | ||
18 | + assert_nothing_raised do | ||
19 | + c.article = Article.new | ||
20 | + end | ||
21 | + end | ||
22 | + | ||
23 | + should 'record authenticated author' do | ||
24 | + c = Comment.new | ||
25 | + assert_raise ActiveRecord::AssociationTypeMismatch do | ||
26 | + c.author = 1 | ||
27 | + end | ||
28 | + assert_raise ActiveRecord::AssociationTypeMismatch do | ||
29 | + c.author = Profile | ||
30 | + end | ||
31 | + assert_nothing_raised do | ||
32 | + c.author = Person.new | ||
33 | + end | ||
34 | + end | ||
35 | + | ||
36 | + should 'record unauthenticated author' do | ||
37 | + flunk 'not yet' | ||
38 | + end | ||
39 | + | ||
40 | +end |