diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2011-12-05 18:56:00 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2011-12-05 18:56:00 +0000 |
commit | fe4c7237fbb130166cbb946f3da9a38d292a0e92 (patch) | |
tree | dbaf4c899fb431b5e02cde1a5095f6e43f0413b7 | |
parent | e5bea933a848ced4535c39619ed950801f015f7c (diff) | |
download | redmine-fe4c7237fbb130166cbb946f3da9a38d292a0e92.tar.gz redmine-fe4c7237fbb130166cbb946f3da9a38d292a0e92.zip |
Adds tests for MailHandler.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8095 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | test/functional/mail_handler_controller_test.rb | 33 |
1 files 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 |