From 1c4bcc5b558e6dd89456edf80811c9e701168845 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Mon, 17 Mar 2008 20:48:22 +0000 Subject: [PATCH] Add NewsController and TimelogController tests. git-svn-id: http://redmine.rubyforge.org/svn/trunk@1270 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- test/fixtures/comments.yml | 8 ++ test/functional/news_controller_test.rb | 90 +++++++++++++++++++++- test/functional/timelog_controller_test.rb | 8 ++ 3 files changed, 105 insertions(+), 1 deletion(-) diff --git a/test/fixtures/comments.yml b/test/fixtures/comments.yml index b60a68b84..538f67ed3 100644 --- a/test/fixtures/comments.yml +++ b/test/fixtures/comments.yml @@ -7,4 +7,12 @@ comments_001: comments: my first comment created_on: 2006-12-10 18:10:10 +01:00 updated_on: 2006-12-10 18:10:10 +01:00 +comments_002: + commented_type: News + commented_id: 1 + id: 2 + author_id: 2 + comments: This is an other comment + created_on: 2006-12-10 18:12:10 +01:00 + updated_on: 2006-12-10 18:12:10 +01:00 \ No newline at end of file diff --git a/test/functional/news_controller_test.rb b/test/functional/news_controller_test.rb index 397e928f1..01f8015b9 100644 --- a/test/functional/news_controller_test.rb +++ b/test/functional/news_controller_test.rb @@ -22,7 +22,7 @@ require 'news_controller' class NewsController; def rescue_action(e) raise e end; end class NewsControllerTest < Test::Unit::TestCase - fixtures :projects, :users, :roles, :members, :enabled_modules + fixtures :projects, :users, :roles, :members, :enabled_modules, :news, :comments def setup @controller = NewsController.new @@ -46,6 +46,94 @@ class NewsControllerTest < Test::Unit::TestCase assert_not_nil assigns(:newss) end + def test_show + get :show, :id => 1 + assert_response :success + assert_template 'show' + assert_tag :tag => 'h2', :content => /eCookbook first release/ + end + + def test_show_not_found + get :show, :id => 999 + assert_response 404 + end + + def test_get_new + @request.session[:user_id] = 2 + get :new, :project_id => 1 + assert_response :success + assert_template 'new' + end + + def test_post_new + @request.session[:user_id] = 2 + post :new, :project_id => 1, :news => { :title => 'NewsControllerTest', + :description => 'This is the description', + :summary => '' } + assert_redirected_to 'projects/ecookbook/news' + + news = News.find_by_title('NewsControllerTest') + assert_not_nil news + assert_equal 'This is the description', news.description + assert_equal User.find(2), news.author + assert_equal Project.find(1), news.project + end + + def test_get_edit + @request.session[:user_id] = 2 + get :edit, :id => 1 + assert_response :success + assert_template 'edit' + end + + def test_post_edit + @request.session[:user_id] = 2 + post :edit, :id => 1, :news => { :description => 'Description changed by test_post_edit' } + assert_redirected_to 'news/show/1' + news = News.find(1) + assert_equal 'Description changed by test_post_edit', news.description + end + + def test_post_new_with_validation_failure + @request.session[:user_id] = 2 + post :new, :project_id => 1, :news => { :title => '', + :description => 'This is the description', + :summary => '' } + assert_response :success + assert_template 'new' + assert_not_nil assigns(:news) + assert assigns(:news).new_record? + assert_tag :tag => 'div', :attributes => { :id => 'errorExplanation' }, + :content => /1 error/ + end + + def test_add_comment + @request.session[:user_id] = 2 + post :add_comment, :id => 1, :comment => { :comments => 'This is a NewsControllerTest comment' } + assert_redirected_to 'news/show/1' + + comment = News.find(1).comments.find(:first, :order => 'created_on DESC') + assert_not_nil comment + assert_equal 'This is a NewsControllerTest comment', comment.comments + assert_equal User.find(2), comment.author + end + + def test_destroy_comment + comments_count = News.find(1).comments.size + @request.session[:user_id] = 2 + post :destroy_comment, :id => 1, :comment_id => 2 + assert_redirected_to 'news/show/1' + assert_nil Comment.find_by_id(2) + assert_equal comments_count - 1, News.find(1).comments.size + end + + def test_destroy + @request.session[:user_id] = 2 + post :destroy, :id => 1 + assert_redirected_to 'projects/ecookbook/news' + assert_nil News.find_by_id(1) + end + def test_preview get :preview, :project_id => 1, :news => {:title => '', diff --git a/test/functional/timelog_controller_test.rb b/test/functional/timelog_controller_test.rb index 66247e569..fa4432295 100644 --- a/test/functional/timelog_controller_test.rb +++ b/test/functional/timelog_controller_test.rb @@ -152,4 +152,12 @@ class TimelogControllerTest < Test::Unit::TestCase assert_nil assigns(:from) assert_nil assigns(:to) end + + def test_details_csv_export + get :details, :project_id => 1, :format => 'csv' + assert_response :success + assert_equal 'text/csv', @response.content_type + assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment\n") + assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,2,Feature request,Add ingredients categories,1.0,\"\"\n") + end end -- 2.39.5