annotate .svn/pristine/ae/aee184ea3c2f60b26adc710ea88ef60ae0429469.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

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