| 1 |
require File.dirname(__FILE__) + '/../spec_helper' |
| 2 |
|
| 3 |
describe Comment do |
| 4 |
before(:each) do |
| 5 |
@comment = new_comment |
| 6 |
end |
| 7 |
|
| 8 |
def new_comment(opts={}) |
| 9 |
c = Comment.new({ |
| 10 |
:repository => repositories(:johans), |
| 11 |
:sha1 => Digest::SHA1.hexdigest("baz"), |
| 12 |
:body => "blabla", |
| 13 |
:project => projects(:johans) |
| 14 |
}.merge(opts)) |
| 15 |
c.user = opts[:user] || users(:johan) |
| 16 |
c |
| 17 |
end |
| 18 |
|
| 19 |
it "should have valid associations" do |
| 20 |
@comment.should have_valid_associations |
| 21 |
end |
| 22 |
|
| 23 |
it "should have a repository to be valid" do |
| 24 |
@comment.repository = nil |
| 25 |
@comment.should_not be_valid |
| 26 |
@comment.should have(1).error_on(:repository_id) |
| 27 |
end |
| 28 |
|
| 29 |
it "should have a user to be valid" do |
| 30 |
@comment.user_id = nil |
| 31 |
@comment.should_not be_valid |
| 32 |
@comment.should have(1).error_on(:user_id) |
| 33 |
end |
| 34 |
|
| 35 |
it "should have a body to be valid" do |
| 36 |
@comment.body = nil |
| 37 |
@comment.should_not be_valid |
| 38 |
@comment.should have(1).error_on(:body) |
| 39 |
end |
| 40 |
|
| 41 |
it "should belong to a project to be valid" do |
| 42 |
@comment.project_id = nil |
| 43 |
@comment.should_not be_valid |
| 44 |
@comment.should have(1).error_on(:project_id) |
| 45 |
end |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
end |