requireFile.dirname(__FILE__) + '/../test_helper'defdefault_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 falseend
specify "Must have a parent id"do
@comment = Comment.create(default_comment({:parent_id => nil}))
@comment.save.should.be falseend
specify "Must have a body"do
@comment = Comment.create(default_comment({:body => nil}))
@comment.save.should.be falseend
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 falseendend
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 @erikendend