2011-08-30 16:03:18 +00:00
|
|
|
# Redmine - project management software
|
2017-06-25 08:40:31 +00:00
|
|
|
# Copyright (C) 2006-2017 Jean-Philippe Lang
|
2007-03-17 15:18:50 +00:00
|
|
|
#
|
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
|
# of the License, or (at your option) any later version.
|
2011-08-30 16:03:18 +00:00
|
|
|
#
|
2007-03-17 15:18:50 +00:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
# GNU General Public License for more details.
|
2011-08-30 16:03:18 +00:00
|
|
|
#
|
2007-03-17 15:18:50 +00:00
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
2010-12-12 23:24:34 +00:00
|
|
|
require File.expand_path('../../test_helper', __FILE__)
|
2007-03-17 15:18:50 +00:00
|
|
|
|
2016-07-14 09:35:49 +00:00
|
|
|
class NewsControllerTest < Redmine::ControllerTest
|
2015-01-17 14:14:12 +00:00
|
|
|
fixtures :projects, :users, :email_addresses, :roles, :members, :member_roles,
|
2014-09-11 17:19:42 +00:00
|
|
|
:enabled_modules, :news, :comments,
|
|
|
|
|
:attachments
|
2011-08-30 16:03:18 +00:00
|
|
|
|
2007-03-17 15:18:50 +00:00
|
|
|
def setup
|
2007-11-05 22:22:51 +00:00
|
|
|
User.current = nil
|
2007-03-17 15:18:50 +00:00
|
|
|
end
|
2011-08-30 16:03:18 +00:00
|
|
|
|
2007-11-05 22:22:51 +00:00
|
|
|
def test_index
|
|
|
|
|
get :index
|
2007-03-17 15:18:50 +00:00
|
|
|
assert_response :success
|
2016-07-19 20:06:01 +00:00
|
|
|
assert_select 'h3 a', :text => 'eCookbook first release !'
|
2007-03-17 15:18:50 +00:00
|
|
|
end
|
2011-08-30 16:03:18 +00:00
|
|
|
|
2007-11-05 22:22:51 +00:00
|
|
|
def test_index_with_project
|
2017-05-31 17:32:34 +00:00
|
|
|
get :index, :params => {
|
|
|
|
|
:project_id => 1
|
|
|
|
|
}
|
2007-03-17 15:18:50 +00:00
|
|
|
assert_response :success
|
2016-07-19 20:06:01 +00:00
|
|
|
assert_select 'h3 a', :text => 'eCookbook first release !'
|
2007-03-17 15:18:50 +00:00
|
|
|
end
|
2011-08-30 16:03:18 +00:00
|
|
|
|
2012-03-10 13:47:28 +00:00
|
|
|
def test_index_with_invalid_project_should_respond_with_404
|
2017-05-31 17:32:34 +00:00
|
|
|
get :index, :params => {
|
|
|
|
|
:project_id => 999
|
|
|
|
|
}
|
2012-03-10 13:47:28 +00:00
|
|
|
assert_response 404
|
|
|
|
|
end
|
|
|
|
|
|
2017-06-26 19:49:02 +00:00
|
|
|
def test_index_without_permission_should_fail
|
|
|
|
|
Role.all.each {|r| r.remove_permission! :view_news}
|
|
|
|
|
@request.session[:user_id] = 2
|
|
|
|
|
|
|
|
|
|
get :index
|
|
|
|
|
assert_response 403
|
|
|
|
|
end
|
|
|
|
|
|
2008-03-17 20:48:22 +00:00
|
|
|
def test_show
|
2017-05-31 17:32:34 +00:00
|
|
|
get :show, :params => {
|
|
|
|
|
:id => 1
|
|
|
|
|
}
|
2008-03-17 20:48:22 +00:00
|
|
|
assert_response :success
|
2016-07-19 20:06:01 +00:00
|
|
|
assert_select 'h2', :text => 'eCookbook first release !'
|
2008-03-17 20:48:22 +00:00
|
|
|
end
|
2011-08-30 16:03:18 +00:00
|
|
|
|
2012-01-29 22:39:06 +00:00
|
|
|
def test_show_should_show_attachments
|
|
|
|
|
attachment = Attachment.first
|
|
|
|
|
attachment.container = News.find(1)
|
|
|
|
|
attachment.save!
|
|
|
|
|
|
2017-05-31 17:32:34 +00:00
|
|
|
get :show, :params => {
|
|
|
|
|
:id => 1
|
|
|
|
|
}
|
2012-01-29 22:39:06 +00:00
|
|
|
assert_response :success
|
2014-11-22 09:38:21 +00:00
|
|
|
assert_select 'a', :text => attachment.filename
|
2012-01-29 22:39:06 +00:00
|
|
|
end
|
|
|
|
|
|
2014-11-14 20:53:14 +00:00
|
|
|
def test_show_with_comments_in_reverse_order
|
|
|
|
|
user = User.find(1)
|
|
|
|
|
user.pref[:comments_sorting] = 'desc'
|
|
|
|
|
user.pref.save!
|
|
|
|
|
|
|
|
|
|
@request.session[:user_id] = 1
|
2017-05-31 17:32:34 +00:00
|
|
|
get :show, :params => {
|
|
|
|
|
:id => 1
|
|
|
|
|
}
|
2014-11-14 20:53:14 +00:00
|
|
|
assert_response :success
|
2016-07-19 20:06:01 +00:00
|
|
|
|
|
|
|
|
comments = css_select('#comments .wiki').map(&:text).map(&:strip)
|
|
|
|
|
assert_equal ["This is an other comment", "my first comment"], comments
|
2014-11-14 20:53:14 +00:00
|
|
|
end
|
|
|
|
|
|
2008-03-17 20:48:22 +00:00
|
|
|
def test_show_not_found
|
2017-05-31 17:32:34 +00:00
|
|
|
get :show, :params => {
|
|
|
|
|
:id => 999
|
|
|
|
|
}
|
2008-03-17 20:48:22 +00:00
|
|
|
assert_response 404
|
|
|
|
|
end
|
2011-08-30 16:03:18 +00:00
|
|
|
|
2008-03-17 20:48:22 +00:00
|
|
|
def test_get_new
|
|
|
|
|
@request.session[:user_id] = 2
|
2017-05-31 17:32:34 +00:00
|
|
|
get :new, :params => {
|
|
|
|
|
:project_id => 1
|
|
|
|
|
}
|
2008-03-17 20:48:22 +00:00
|
|
|
assert_response :success
|
2016-07-19 20:06:01 +00:00
|
|
|
assert_select 'input[name=?]', 'news[title]'
|
2008-03-17 20:48:22 +00:00
|
|
|
end
|
2011-08-30 16:03:18 +00:00
|
|
|
|
2010-09-20 15:13:48 +00:00
|
|
|
def test_post_create
|
2009-03-28 00:38:57 +00:00
|
|
|
ActionMailer::Base.deliveries.clear
|
2008-03-17 20:48:22 +00:00
|
|
|
@request.session[:user_id] = 2
|
2012-07-08 12:23:47 +00:00
|
|
|
|
|
|
|
|
with_settings :notified_events => %w(news_added) do
|
2017-05-31 17:32:34 +00:00
|
|
|
post :create, :params => {
|
|
|
|
|
:project_id => 1,
|
|
|
|
|
:news => {
|
|
|
|
|
:title => 'NewsControllerTest',
|
|
|
|
|
:description => 'This is the description',
|
|
|
|
|
:summary => ''
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-07-08 12:23:47 +00:00
|
|
|
end
|
2010-11-14 16:45:32 +00:00
|
|
|
assert_redirected_to '/projects/ecookbook/news'
|
2011-08-30 16:03:18 +00:00
|
|
|
|
2008-03-17 20:48:22 +00:00
|
|
|
news = News.find_by_title('NewsControllerTest')
|
|
|
|
|
assert_not_nil news
|
|
|
|
|
assert_equal 'This is the description', news.description
|
|
|
|
|
assert_equal User.find(2), news.author
|
|
|
|
|
assert_equal Project.find(1), news.project
|
2018-10-06 13:08:52 +00:00
|
|
|
assert_equal 2, ActionMailer::Base.deliveries.size
|
2008-03-17 20:48:22 +00:00
|
|
|
end
|
2011-08-30 16:03:18 +00:00
|
|
|
|
2012-01-29 22:39:06 +00:00
|
|
|
def test_post_create_with_attachment
|
|
|
|
|
set_tmp_attachments_directory
|
|
|
|
|
@request.session[:user_id] = 2
|
|
|
|
|
assert_difference 'News.count' do
|
|
|
|
|
assert_difference 'Attachment.count' do
|
2017-05-31 17:32:34 +00:00
|
|
|
post :create, :params => {
|
|
|
|
|
:project_id => 1,
|
|
|
|
|
:news => {
|
|
|
|
|
:title => 'Test',
|
|
|
|
|
:description => 'This is the description'
|
|
|
|
|
},
|
|
|
|
|
:attachments => {
|
|
|
|
|
'1' => {
|
|
|
|
|
'file' => uploaded_test_file('testfile.txt', 'text/plain')}
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-01-29 22:39:06 +00:00
|
|
|
end
|
|
|
|
|
end
|
2014-01-08 06:26:25 +00:00
|
|
|
attachment = Attachment.order('id DESC').first
|
|
|
|
|
news = News.order('id DESC').first
|
2012-01-29 22:39:06 +00:00
|
|
|
assert_equal news, attachment.container
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_post_create_with_validation_failure
|
|
|
|
|
@request.session[:user_id] = 2
|
2017-05-31 17:32:34 +00:00
|
|
|
post :create, :params => {
|
|
|
|
|
:project_id => 1,
|
|
|
|
|
:news => {
|
|
|
|
|
:title => '',
|
|
|
|
|
:description => 'This is the description',
|
|
|
|
|
:summary => ''
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-01-29 22:39:06 +00:00
|
|
|
assert_response :success
|
2014-12-21 12:39:48 +00:00
|
|
|
assert_select_error /title cannot be blank/i
|
2012-01-29 22:39:06 +00:00
|
|
|
end
|
|
|
|
|
|
2008-03-17 20:48:22 +00:00
|
|
|
def test_get_edit
|
|
|
|
|
@request.session[:user_id] = 2
|
2017-05-31 17:32:34 +00:00
|
|
|
get :edit, :params => {
|
|
|
|
|
:id => 1
|
|
|
|
|
}
|
2008-03-17 20:48:22 +00:00
|
|
|
assert_response :success
|
2016-07-19 20:06:01 +00:00
|
|
|
assert_select 'input[name=?][value=?]', 'news[title]', 'eCookbook first release !'
|
2008-03-17 20:48:22 +00:00
|
|
|
end
|
2011-08-30 16:03:18 +00:00
|
|
|
|
2010-09-21 15:20:37 +00:00
|
|
|
def test_put_update
|
2008-03-17 20:48:22 +00:00
|
|
|
@request.session[:user_id] = 2
|
2017-05-31 17:32:34 +00:00
|
|
|
put :update, :params => {
|
|
|
|
|
:id => 1,
|
|
|
|
|
:news => {
|
|
|
|
|
:description => 'Description changed by test_post_edit'
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-11-14 16:45:32 +00:00
|
|
|
assert_redirected_to '/news/1'
|
2008-03-17 20:48:22 +00:00
|
|
|
news = News.find(1)
|
|
|
|
|
assert_equal 'Description changed by test_post_edit', news.description
|
|
|
|
|
end
|
|
|
|
|
|
2012-01-29 22:39:06 +00:00
|
|
|
def test_put_update_with_attachment
|
|
|
|
|
set_tmp_attachments_directory
|
2008-03-17 20:48:22 +00:00
|
|
|
@request.session[:user_id] = 2
|
2012-01-29 22:39:06 +00:00
|
|
|
assert_no_difference 'News.count' do
|
|
|
|
|
assert_difference 'Attachment.count' do
|
2017-05-31 17:32:34 +00:00
|
|
|
put :update, :params => {
|
|
|
|
|
:id => 1,
|
|
|
|
|
:news => {
|
|
|
|
|
:description => 'This is the description'
|
|
|
|
|
},
|
|
|
|
|
:attachments => {
|
|
|
|
|
'1' => {
|
|
|
|
|
'file' => uploaded_test_file('testfile.txt', 'text/plain')}
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-01-29 22:39:06 +00:00
|
|
|
end
|
|
|
|
|
end
|
2014-01-08 06:23:43 +00:00
|
|
|
attachment = Attachment.order('id DESC').first
|
2012-01-29 22:39:06 +00:00
|
|
|
assert_equal News.find(1), attachment.container
|
2008-03-17 20:48:22 +00:00
|
|
|
end
|
2011-08-30 16:03:18 +00:00
|
|
|
|
2012-03-02 11:43:33 +00:00
|
|
|
def test_update_with_failure
|
|
|
|
|
@request.session[:user_id] = 2
|
2017-05-31 17:32:34 +00:00
|
|
|
put :update, :params => {
|
|
|
|
|
:id => 1,
|
|
|
|
|
:news => {
|
|
|
|
|
:description => ''
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-03-02 11:43:33 +00:00
|
|
|
assert_response :success
|
2014-12-21 12:39:48 +00:00
|
|
|
assert_select_error /description cannot be blank/i
|
2012-03-02 11:43:33 +00:00
|
|
|
end
|
|
|
|
|
|
2008-03-17 20:48:22 +00:00
|
|
|
def test_destroy
|
|
|
|
|
@request.session[:user_id] = 2
|
2017-05-31 17:32:34 +00:00
|
|
|
delete :destroy, :params => {
|
|
|
|
|
:id => 1
|
|
|
|
|
}
|
2010-11-14 16:45:32 +00:00
|
|
|
assert_redirected_to '/projects/ecookbook/news'
|
2008-03-17 20:48:22 +00:00
|
|
|
assert_nil News.find_by_id(1)
|
|
|
|
|
end
|
2007-03-17 15:18:50 +00:00
|
|
|
end
|