Mercurial > hg > soundsoftware-site
comparison .svn/pristine/ae/aee184ea3c2f60b26adc710ea88ef60ae0429469.svn-base @ 1517:dffacf8a6908 redmine-2.5
Update to Redmine SVN revision 13367 on 2.5-stable branch
author | Chris Cannam |
---|---|
date | Tue, 09 Sep 2014 09:29:00 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1516:b450a9d58aed | 1517:dffacf8a6908 |
---|---|
1 # Redmine - project management software | |
2 # Copyright (C) 2006-2014 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 | |
20 class NewsControllerTest < ActionController::TestCase | |
21 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, :news, :comments | |
22 | |
23 def setup | |
24 User.current = nil | |
25 end | |
26 | |
27 def test_index | |
28 get :index | |
29 assert_response :success | |
30 assert_template 'index' | |
31 assert_not_nil assigns(:newss) | |
32 assert_nil assigns(:project) | |
33 end | |
34 | |
35 def test_index_with_project | |
36 get :index, :project_id => 1 | |
37 assert_response :success | |
38 assert_template 'index' | |
39 assert_not_nil assigns(:newss) | |
40 end | |
41 | |
42 def test_index_with_invalid_project_should_respond_with_404 | |
43 get :index, :project_id => 999 | |
44 assert_response 404 | |
45 end | |
46 | |
47 def test_show | |
48 get :show, :id => 1 | |
49 assert_response :success | |
50 assert_template 'show' | |
51 assert_tag :tag => 'h2', :content => /eCookbook first release/ | |
52 end | |
53 | |
54 def test_show_should_show_attachments | |
55 attachment = Attachment.first | |
56 attachment.container = News.find(1) | |
57 attachment.save! | |
58 | |
59 get :show, :id => 1 | |
60 assert_response :success | |
61 assert_tag 'a', :content => attachment.filename | |
62 end | |
63 | |
64 def test_show_not_found | |
65 get :show, :id => 999 | |
66 assert_response 404 | |
67 end | |
68 | |
69 def test_get_new | |
70 @request.session[:user_id] = 2 | |
71 get :new, :project_id => 1 | |
72 assert_response :success | |
73 assert_template 'new' | |
74 end | |
75 | |
76 def test_post_create | |
77 ActionMailer::Base.deliveries.clear | |
78 @request.session[:user_id] = 2 | |
79 | |
80 with_settings :notified_events => %w(news_added) do | |
81 post :create, :project_id => 1, :news => { :title => 'NewsControllerTest', | |
82 :description => 'This is the description', | |
83 :summary => '' } | |
84 end | |
85 assert_redirected_to '/projects/ecookbook/news' | |
86 | |
87 news = News.find_by_title('NewsControllerTest') | |
88 assert_not_nil news | |
89 assert_equal 'This is the description', news.description | |
90 assert_equal User.find(2), news.author | |
91 assert_equal Project.find(1), news.project | |
92 assert_equal 1, ActionMailer::Base.deliveries.size | |
93 end | |
94 | |
95 def test_post_create_with_attachment | |
96 set_tmp_attachments_directory | |
97 @request.session[:user_id] = 2 | |
98 assert_difference 'News.count' do | |
99 assert_difference 'Attachment.count' do | |
100 post :create, :project_id => 1, | |
101 :news => { :title => 'Test', :description => 'This is the description' }, | |
102 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} | |
103 end | |
104 end | |
105 attachment = Attachment.order('id DESC').first | |
106 news = News.order('id DESC').first | |
107 assert_equal news, attachment.container | |
108 end | |
109 | |
110 def test_post_create_with_validation_failure | |
111 @request.session[:user_id] = 2 | |
112 post :create, :project_id => 1, :news => { :title => '', | |
113 :description => 'This is the description', | |
114 :summary => '' } | |
115 assert_response :success | |
116 assert_template 'new' | |
117 assert_not_nil assigns(:news) | |
118 assert assigns(:news).new_record? | |
119 assert_error_tag :content => /title #{ESCAPED_CANT} be blank/i | |
120 end | |
121 | |
122 def test_get_edit | |
123 @request.session[:user_id] = 2 | |
124 get :edit, :id => 1 | |
125 assert_response :success | |
126 assert_template 'edit' | |
127 end | |
128 | |
129 def test_put_update | |
130 @request.session[:user_id] = 2 | |
131 put :update, :id => 1, :news => { :description => 'Description changed by test_post_edit' } | |
132 assert_redirected_to '/news/1' | |
133 news = News.find(1) | |
134 assert_equal 'Description changed by test_post_edit', news.description | |
135 end | |
136 | |
137 def test_put_update_with_attachment | |
138 set_tmp_attachments_directory | |
139 @request.session[:user_id] = 2 | |
140 assert_no_difference 'News.count' do | |
141 assert_difference 'Attachment.count' do | |
142 put :update, :id => 1, | |
143 :news => { :description => 'This is the description' }, | |
144 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} | |
145 end | |
146 end | |
147 attachment = Attachment.order('id DESC').first | |
148 assert_equal News.find(1), attachment.container | |
149 end | |
150 | |
151 def test_update_with_failure | |
152 @request.session[:user_id] = 2 | |
153 put :update, :id => 1, :news => { :description => '' } | |
154 assert_response :success | |
155 assert_template 'edit' | |
156 assert_error_tag :content => /description #{ESCAPED_CANT} be blank/i | |
157 end | |
158 | |
159 def test_destroy | |
160 @request.session[:user_id] = 2 | |
161 delete :destroy, :id => 1 | |
162 assert_redirected_to '/projects/ecookbook/news' | |
163 assert_nil News.find_by_id(1) | |
164 end | |
165 end |