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