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
require File.dirname(__FILE__) + '/../test_helper'

def default_comment(options = {})
  {
    :user_id    => 3829,
    :parent_id  => 2,
    :body       => "Hi"
  }.merge(options)
end

context "A new comment" do
  
  specify "Must have a user id" do
    @comment = Comment.create(default_comment({:user_id => nil}))
    @comment.save.should.be false
  end
  
  specify "Must have a parent id" do
    @comment = Comment.create(default_comment({:parent_id => nil}))
    @comment.save.should.be false
  end
  
  specify "Must have a body" do
    @comment = Comment.create(default_comment({:body => nil}))
    @comment.save.should.be false    
  end
  
  specify "should be able to be created" do
    # this validates the relationship
    Comment.should.differ(:count).by(1) {
      Comment.create(default_comment)
    }
  end
  
  specify "should not allow when user a does not list user b as a friend" do
    @comment = Comment.create(default_comment({:parent_id => 3829, :user_id => 2}))
    @comment.save.should.be false
  end
  
end

context "An existing comment" do
  setup do
    @comment = Comment.find(:first, :include => [:user, :parent])
    @erik = User.find_by_screen_name("kastner")
  end
  
  specify "should have a user" do
    @comment.user.should.equal @erik
  end
end