summaryrefslogtreecommitdiffstats
path: root/test/functional
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional')
-rw-r--r--test/functional/mail_handler_controller_test.rb33
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