From 55ed70529aefdb3029f5ab72169b2f7909b2f2a3 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sun, 10 Dec 2006 18:35:48 +0000 Subject: added model Comment. comments can now be added on news. git-svn-id: http://redmine.rubyforge.org/svn/trunk@81 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- test/fixtures/comments.yml | 10 ++++++++++ test/fixtures/news.yml | 2 ++ test/unit/comment_test.rb | 30 ++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 test/fixtures/comments.yml create mode 100644 test/unit/comment_test.rb (limited to 'test') diff --git a/test/fixtures/comments.yml b/test/fixtures/comments.yml new file mode 100644 index 000000000..24a4546aa --- /dev/null +++ b/test/fixtures/comments.yml @@ -0,0 +1,10 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html +comments_001: + commented_type: News + commented_id: 1 + id: 1 + author_id: 1 + comment: my first comment + created_on: 2006-12-10 18:10:10 +01:00 + updated_on: 2006-12-10 18:10:10 +01:00 + \ No newline at end of file diff --git a/test/fixtures/news.yml b/test/fixtures/news.yml index 1bef9184e..2c2e2c134 100644 --- a/test/fixtures/news.yml +++ b/test/fixtures/news.yml @@ -10,6 +10,7 @@ news_001: Visit http://ecookbook.somenet.foo/ summary: First version was released... author_id: 2 + comments_count: 1 news_002: created_on: 2006-07-19 22:42:58 +02:00 project_id: 1 @@ -18,3 +19,4 @@ news_002: description: eCookbook 1.0 have downloaded 100,000 times summary: eCookbook 1.0 have downloaded 100,000 times author_id: 2 + comments_count: 0 diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb new file mode 100644 index 000000000..4435f0a7f --- /dev/null +++ b/test/unit/comment_test.rb @@ -0,0 +1,30 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class CommentTest < Test::Unit::TestCase + fixtures :users, :news, :comments + + def setup + @jsmith = User.find(2) + @news = News.find(1) + end + + def test_create + comment = Comment.new(:commented => @news, :author => @jsmith, :comment => "my comment") + assert comment.save + @news.reload + assert_equal 2, @news.comments_count + end + + def test_validate + comment = Comment.new(:commented => @news) + assert !comment.save + assert_equal 2, comment.errors.length + end + + def test_destroy + comment = Comment.find(1) + assert comment.destroy + @news.reload + assert_equal 0, @news.comments_count + end +end -- cgit v1.2.3