diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/functional/news_controller_test.rb | 49 | ||||
-rw-r--r-- | test/integration/routing/news_test.rb | 2 |
2 files changed, 50 insertions, 1 deletions
diff --git a/test/functional/news_controller_test.rb b/test/functional/news_controller_test.rb index 76517e1a1..c6545fa15 100644 --- a/test/functional/news_controller_test.rb +++ b/test/functional/news_controller_test.rb @@ -87,13 +87,32 @@ class NewsControllerTest < Redmine::ControllerTest assert_response 404 end - def test_get_new + def test_get_new_with_project_id @request.session[:user_id] = 2 get(:new, :params => {:project_id => 1}) assert_response :success + assert_select 'select[name=project_id]', false assert_select 'input[name=?]', 'news[title]' end + def test_get_new_without_project_id + @request.session[:user_id] = 2 + get(:new) + assert_response :success + assert_select 'select[name=project_id]' + assert_select 'input[name=?]', 'news[title]' + end + + def test_get_new_if_user_does_not_have_permission + @request.session[:user_id] = 2 + User.find(2).roles.each{|u| u.remove_permission! :manage_news } + + get(:new) + assert_response :forbidden + assert_select 'select[name=project_id]', false + assert_select 'input[name=?]', 'news[title]', count: 0 + end + def test_post_create ActionMailer::Base.deliveries.clear @request.session[:user_id] = 2 @@ -121,6 +140,34 @@ class NewsControllerTest < Redmine::ControllerTest assert_equal 2, ActionMailer::Base.deliveries.size end + def test_post_create_with_cross_project_param + ActionMailer::Base.deliveries.clear + @request.session[:user_id] = 2 + + with_settings :notified_events => %w(news_added) do + post( + :create, + :params => { + :project_id => 1, + :cross_project => '1', + :news => { + :title => 'NewsControllerTest', + :description => 'This is the description', + :summary => '' + } + } + ) + end + assert_redirected_to '/news' + + 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 + assert_equal 2, ActionMailer::Base.deliveries.size + end + def test_post_create_with_attachment set_tmp_attachments_directory ActionMailer::Base.deliveries.clear diff --git a/test/integration/routing/news_test.rb b/test/integration/routing/news_test.rb index 8e62da774..7863fad5f 100644 --- a/test/integration/routing/news_test.rb +++ b/test/integration/routing/news_test.rb @@ -29,6 +29,8 @@ class RoutingNewsTest < Redmine::RoutingTest def test_news should_route 'GET /news' => 'news#index' + should_route 'GET /news/new' => 'news#new' + should_route 'POST /news' => 'news#create' should_route 'GET /news.atom' => 'news#index', :format => 'atom' should_route 'GET /news/2' => 'news#show', :id => '2' should_route 'GET /news/2/edit' => 'news#edit', :id => '2' |