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