Mercurial > hg > soundsoftware-site
comparison test/functional/news_controller_test.rb @ 1526:404aa68d4227
Merge from live branch
author | Chris Cannam |
---|---|
date | Thu, 11 Sep 2014 12:46:20 +0100 |
parents | dffacf8a6908 |
children |
comparison
equal
deleted
inserted
replaced
1493:a5f2bdf3b486 | 1526:404aa68d4227 |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2012 Jean-Philippe Lang | 2 # Copyright (C) 2006-2014 Jean-Philippe Lang |
3 # | 3 # |
4 # This program is free software; you can redistribute it and/or | 4 # This program is free software; you can redistribute it and/or |
5 # modify it under the terms of the GNU General Public License | 5 # modify it under the terms of the GNU General Public License |
6 # as published by the Free Software Foundation; either version 2 | 6 # as published by the Free Software Foundation; either version 2 |
7 # of the License, or (at your option) any later version. | 7 # of the License, or (at your option) any later version. |
14 # You should have received a copy of the GNU General Public License | 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 | 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. | 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | 17 |
18 require File.expand_path('../../test_helper', __FILE__) | 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 | 19 |
24 class NewsControllerTest < ActionController::TestCase | 20 class NewsControllerTest < ActionController::TestCase |
25 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, :news, :comments | 21 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, :news, :comments |
26 | 22 |
27 def setup | 23 def setup |
28 @controller = NewsController.new | |
29 @request = ActionController::TestRequest.new | |
30 @response = ActionController::TestResponse.new | |
31 User.current = nil | 24 User.current = nil |
32 end | 25 end |
33 | 26 |
34 def test_index | 27 def test_index |
35 get :index | 28 get :index |
107 post :create, :project_id => 1, | 100 post :create, :project_id => 1, |
108 :news => { :title => 'Test', :description => 'This is the description' }, | 101 :news => { :title => 'Test', :description => 'This is the description' }, |
109 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} | 102 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} |
110 end | 103 end |
111 end | 104 end |
112 attachment = Attachment.first(:order => 'id DESC') | 105 attachment = Attachment.order('id DESC').first |
113 news = News.first(:order => 'id DESC') | 106 news = News.order('id DESC').first |
114 assert_equal news, attachment.container | 107 assert_equal news, attachment.container |
115 end | 108 end |
116 | 109 |
117 def test_post_create_with_validation_failure | 110 def test_post_create_with_validation_failure |
118 @request.session[:user_id] = 2 | 111 @request.session[:user_id] = 2 |
121 :summary => '' } | 114 :summary => '' } |
122 assert_response :success | 115 assert_response :success |
123 assert_template 'new' | 116 assert_template 'new' |
124 assert_not_nil assigns(:news) | 117 assert_not_nil assigns(:news) |
125 assert assigns(:news).new_record? | 118 assert assigns(:news).new_record? |
126 assert_error_tag :content => /title can't be blank/i | 119 assert_error_tag :content => /title #{ESCAPED_CANT} be blank/i |
127 end | 120 end |
128 | 121 |
129 def test_get_edit | 122 def test_get_edit |
130 @request.session[:user_id] = 2 | 123 @request.session[:user_id] = 2 |
131 get :edit, :id => 1 | 124 get :edit, :id => 1 |
149 put :update, :id => 1, | 142 put :update, :id => 1, |
150 :news => { :description => 'This is the description' }, | 143 :news => { :description => 'This is the description' }, |
151 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} | 144 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} |
152 end | 145 end |
153 end | 146 end |
154 attachment = Attachment.first(:order => 'id DESC') | 147 attachment = Attachment.order('id DESC').first |
155 assert_equal News.find(1), attachment.container | 148 assert_equal News.find(1), attachment.container |
156 end | 149 end |
157 | 150 |
158 def test_update_with_failure | 151 def test_update_with_failure |
159 @request.session[:user_id] = 2 | 152 @request.session[:user_id] = 2 |
160 put :update, :id => 1, :news => { :description => '' } | 153 put :update, :id => 1, :news => { :description => '' } |
161 assert_response :success | 154 assert_response :success |
162 assert_template 'edit' | 155 assert_template 'edit' |
163 assert_error_tag :content => /description can't be blank/i | 156 assert_error_tag :content => /description #{ESCAPED_CANT} be blank/i |
164 end | 157 end |
165 | 158 |
166 def test_destroy | 159 def test_destroy |
167 @request.session[:user_id] = 2 | 160 @request.session[:user_id] = 2 |
168 delete :destroy, :id => 1 | 161 delete :destroy, :id => 1 |