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