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