Add NewsController and TimelogController tests.

git-svn-id: http://redmine.rubyforge.org/svn/trunk@1270 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2008-03-17 20:48:22 +00:00
parent 8cb5acf453
commit 1c4bcc5b55
3 changed files with 105 additions and 1 deletions

View File

@ -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

View File

@ -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 => '',

View File

@ -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