From fe4c7237fbb130166cbb946f3da9a38d292a0e92 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Mon, 5 Dec 2011 18:56:00 +0000 Subject: Adds tests for MailHandler. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8095 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- test/functional/mail_handler_controller_test.rb | 33 ++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/test/functional/mail_handler_controller_test.rb b/test/functional/mail_handler_controller_test.rb index 54422ef67..bbe79694f 100644 --- a/test/functional/mail_handler_controller_test.rb +++ b/test/functional/mail_handler_controller_test.rb @@ -38,16 +38,43 @@ class MailHandlerControllerTest < ActionController::TestCase Setting.mail_handler_api_enabled = 1 Setting.mail_handler_api_key = 'secret' - post :index, :key => 'secret', :email => IO.read(File.join(FIXTURES_PATH, 'ticket_on_given_project.eml')) + assert_difference 'Issue.count' do + post :index, :key => 'secret', :email => IO.read(File.join(FIXTURES_PATH, 'ticket_on_given_project.eml')) + end assert_response 201 end - def test_should_not_allow + def test_should_respond_with_422_if_not_created + Project.find('onlinestore').destroy + + Setting.mail_handler_api_enabled = 1 + Setting.mail_handler_api_key = 'secret' + + assert_no_difference 'Issue.count' do + post :index, :key => 'secret', :email => IO.read(File.join(FIXTURES_PATH, 'ticket_on_given_project.eml')) + end + assert_response 422 + end + + def test_should_not_allow_with_api_disabled # Disable API Setting.mail_handler_api_enabled = 0 Setting.mail_handler_api_key = 'secret' - post :index, :key => 'secret', :email => IO.read(File.join(FIXTURES_PATH, 'ticket_on_given_project.eml')) + assert_no_difference 'Issue.count' do + post :index, :key => 'secret', :email => IO.read(File.join(FIXTURES_PATH, 'ticket_on_given_project.eml')) + end + assert_response 403 + end + + def test_should_not_allow_with_wrong_key + # Disable API + Setting.mail_handler_api_enabled = 1 + Setting.mail_handler_api_key = 'secret' + + assert_no_difference 'Issue.count' do + post :index, :key => 'wrong', :email => IO.read(File.join(FIXTURES_PATH, 'ticket_on_given_project.eml')) + end assert_response 403 end end -- cgit v1.2.3