annotate .svn/pristine/c5/c5d488c8c009bfaf1b3e16a81cc375cbb4e01e5b.svn-base @ 1628:9c5f8e24dadc live tip

Quieten this cron script
author Chris Cannam
date Tue, 25 Aug 2020 11:38:49 +0100
parents e248c7af89ec
children
rev   line source
Chris@1494 1 # Redmine - project management software
Chris@1494 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@1494 3 #
Chris@1494 4 # This program is free software; you can redistribute it and/or
Chris@1494 5 # modify it under the terms of the GNU General Public License
Chris@1494 6 # as published by the Free Software Foundation; either version 2
Chris@1494 7 # of the License, or (at your option) any later version.
Chris@1494 8 #
Chris@1494 9 # This program is distributed in the hope that it will be useful,
Chris@1494 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1494 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1494 12 # GNU General Public License for more details.
Chris@1494 13 #
Chris@1494 14 # You should have received a copy of the GNU General Public License
Chris@1494 15 # along with this program; if not, write to the Free Software
Chris@1494 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1494 17
Chris@1494 18 require File.expand_path('../../test_helper', __FILE__)
Chris@1494 19
Chris@1494 20 class NewsControllerTest < ActionController::TestCase
Chris@1494 21 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, :news, :comments
Chris@1494 22
Chris@1494 23 def setup
Chris@1494 24 User.current = nil
Chris@1494 25 end
Chris@1494 26
Chris@1494 27 def test_index
Chris@1494 28 get :index
Chris@1494 29 assert_response :success
Chris@1494 30 assert_template 'index'
Chris@1494 31 assert_not_nil assigns(:newss)
Chris@1494 32 assert_nil assigns(:project)
Chris@1494 33 end
Chris@1494 34
Chris@1494 35 def test_index_with_project
Chris@1494 36 get :index, :project_id => 1
Chris@1494 37 assert_response :success
Chris@1494 38 assert_template 'index'
Chris@1494 39 assert_not_nil assigns(:newss)
Chris@1494 40 end
Chris@1494 41
Chris@1494 42 def test_index_with_invalid_project_should_respond_with_404
Chris@1494 43 get :index, :project_id => 999
Chris@1494 44 assert_response 404
Chris@1494 45 end
Chris@1494 46
Chris@1494 47 def test_show
Chris@1494 48 get :show, :id => 1
Chris@1494 49 assert_response :success
Chris@1494 50 assert_template 'show'
Chris@1494 51 assert_tag :tag => 'h2', :content => /eCookbook first release/
Chris@1494 52 end
Chris@1494 53
Chris@1494 54 def test_show_should_show_attachments
Chris@1494 55 attachment = Attachment.first
Chris@1494 56 attachment.container = News.find(1)
Chris@1494 57 attachment.save!
Chris@1494 58
Chris@1494 59 get :show, :id => 1
Chris@1494 60 assert_response :success
Chris@1494 61 assert_tag 'a', :content => attachment.filename
Chris@1494 62 end
Chris@1494 63
Chris@1494 64 def test_show_not_found
Chris@1494 65 get :show, :id => 999
Chris@1494 66 assert_response 404
Chris@1494 67 end
Chris@1494 68
Chris@1494 69 def test_get_new
Chris@1494 70 @request.session[:user_id] = 2
Chris@1494 71 get :new, :project_id => 1
Chris@1494 72 assert_response :success
Chris@1494 73 assert_template 'new'
Chris@1494 74 end
Chris@1494 75
Chris@1494 76 def test_post_create
Chris@1494 77 ActionMailer::Base.deliveries.clear
Chris@1494 78 @request.session[:user_id] = 2
Chris@1494 79
Chris@1494 80 with_settings :notified_events => %w(news_added) do
Chris@1494 81 post :create, :project_id => 1, :news => { :title => 'NewsControllerTest',
Chris@1494 82 :description => 'This is the description',
Chris@1494 83 :summary => '' }
Chris@1494 84 end
Chris@1494 85 assert_redirected_to '/projects/ecookbook/news'
Chris@1494 86
Chris@1494 87 news = News.find_by_title('NewsControllerTest')
Chris@1494 88 assert_not_nil news
Chris@1494 89 assert_equal 'This is the description', news.description
Chris@1494 90 assert_equal User.find(2), news.author
Chris@1494 91 assert_equal Project.find(1), news.project
Chris@1494 92 assert_equal 1, ActionMailer::Base.deliveries.size
Chris@1494 93 end
Chris@1494 94
Chris@1494 95 def test_post_create_with_attachment
Chris@1494 96 set_tmp_attachments_directory
Chris@1494 97 @request.session[:user_id] = 2
Chris@1494 98 assert_difference 'News.count' do
Chris@1494 99 assert_difference 'Attachment.count' do
Chris@1494 100 post :create, :project_id => 1,
Chris@1494 101 :news => { :title => 'Test', :description => 'This is the description' },
Chris@1494 102 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
Chris@1494 103 end
Chris@1494 104 end
Chris@1494 105 attachment = Attachment.first(:order => 'id DESC')
Chris@1494 106 news = News.first(:order => 'id DESC')
Chris@1494 107 assert_equal news, attachment.container
Chris@1494 108 end
Chris@1494 109
Chris@1494 110 def test_post_create_with_validation_failure
Chris@1494 111 @request.session[:user_id] = 2
Chris@1494 112 post :create, :project_id => 1, :news => { :title => '',
Chris@1494 113 :description => 'This is the description',
Chris@1494 114 :summary => '' }
Chris@1494 115 assert_response :success
Chris@1494 116 assert_template 'new'
Chris@1494 117 assert_not_nil assigns(:news)
Chris@1494 118 assert assigns(:news).new_record?
Chris@1494 119 assert_error_tag :content => /title can&#x27;t be blank/i
Chris@1494 120 end
Chris@1494 121
Chris@1494 122 def test_get_edit
Chris@1494 123 @request.session[:user_id] = 2
Chris@1494 124 get :edit, :id => 1
Chris@1494 125 assert_response :success
Chris@1494 126 assert_template 'edit'
Chris@1494 127 end
Chris@1494 128
Chris@1494 129 def test_put_update
Chris@1494 130 @request.session[:user_id] = 2
Chris@1494 131 put :update, :id => 1, :news => { :description => 'Description changed by test_post_edit' }
Chris@1494 132 assert_redirected_to '/news/1'
Chris@1494 133 news = News.find(1)
Chris@1494 134 assert_equal 'Description changed by test_post_edit', news.description
Chris@1494 135 end
Chris@1494 136
Chris@1494 137 def test_put_update_with_attachment
Chris@1494 138 set_tmp_attachments_directory
Chris@1494 139 @request.session[:user_id] = 2
Chris@1494 140 assert_no_difference 'News.count' do
Chris@1494 141 assert_difference 'Attachment.count' do
Chris@1494 142 put :update, :id => 1,
Chris@1494 143 :news => { :description => 'This is the description' },
Chris@1494 144 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
Chris@1494 145 end
Chris@1494 146 end
Chris@1494 147 attachment = Attachment.first(:order => 'id DESC')
Chris@1494 148 assert_equal News.find(1), attachment.container
Chris@1494 149 end
Chris@1494 150
Chris@1494 151 def test_update_with_failure
Chris@1494 152 @request.session[:user_id] = 2
Chris@1494 153 put :update, :id => 1, :news => { :description => '' }
Chris@1494 154 assert_response :success
Chris@1494 155 assert_template 'edit'
Chris@1494 156 assert_error_tag :content => /description can&#x27;t be blank/i
Chris@1494 157 end
Chris@1494 158
Chris@1494 159 def test_destroy
Chris@1494 160 @request.session[:user_id] = 2
Chris@1494 161 delete :destroy, :id => 1
Chris@1494 162 assert_redirected_to '/projects/ecookbook/news'
Chris@1494 163 assert_nil News.find_by_id(1)
Chris@1494 164 end
Chris@1494 165 end