]> source.dussan.org Git - redmine.git/commitdiff
Add NewsController and TimelogController tests.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 17 Mar 2008 20:48:22 +0000 (20:48 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 17 Mar 2008 20:48:22 +0000 (20:48 +0000)
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1270 e93f8b46-1217-0410-a6f0-8f06a7374b81

test/fixtures/comments.yml
test/functional/news_controller_test.rb
test/functional/timelog_controller_test.rb

index b60a68b849ec5b3556729b7c791d01c226f7f5ce..538f67ed33255c29b218048037b2b468f6dacc11 100644 (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
   
\ No newline at end of file
index 397e928f1e85ffcf6b660cb165100bab8716f586..01f8015b9177766f8231a58a7e2ad25b3984cdd9 100644 (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 => '',
index 66247e5694f1dc105bed67b7f454913b9a57c8aa..fa44322952da5ab8488b57bed881d055504db883 100644 (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