annotate test/functional/mail_handler_controller_test.rb @ 1459:cf78a7ade302 luisf

Merge from branch "bug_794"
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Mon, 11 Nov 2013 18:25:50 +0000
parents 433d4f72a19b
children 622f24f53b42
rev   line source
Chris@909 1 # Redmine - project management software
Chris@1115 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
Chris@0 3 #
Chris@0 4 # This program is free software; you can redistribute it and/or
Chris@0 5 # modify it under the terms of the GNU General Public License
Chris@0 6 # as published by the Free Software Foundation; either version 2
Chris@0 7 # of the License, or (at your option) any later version.
Chris@909 8 #
Chris@0 9 # This program is distributed in the hope that it will be useful,
Chris@0 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 12 # GNU General Public License for more details.
Chris@909 13 #
Chris@0 14 # You should have received a copy of the GNU General Public License
Chris@0 15 # along with this program; if not, write to the Free Software
Chris@0 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0 17
Chris@119 18 require File.expand_path('../../test_helper', __FILE__)
Chris@0 19 require 'mail_handler_controller'
Chris@0 20
Chris@0 21 # Re-raise errors caught by the controller.
Chris@0 22 class MailHandlerController; def rescue_action(e) raise e end; end
Chris@0 23
Chris@0 24 class MailHandlerControllerTest < ActionController::TestCase
Chris@1115 25 fixtures :users, :projects, :enabled_modules, :roles, :members, :member_roles, :issues, :issue_statuses,
Chris@1115 26 :trackers, :projects_trackers, :enumerations
Chris@909 27
Chris@0 28 FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures/mail_handler'
Chris@909 29
Chris@0 30 def setup
Chris@0 31 @controller = MailHandlerController.new
Chris@0 32 @request = ActionController::TestRequest.new
Chris@0 33 @response = ActionController::TestResponse.new
Chris@0 34 User.current = nil
Chris@0 35 end
Chris@909 36
Chris@0 37 def test_should_create_issue
Chris@0 38 # Enable API and set a key
Chris@0 39 Setting.mail_handler_api_enabled = 1
Chris@0 40 Setting.mail_handler_api_key = 'secret'
Chris@909 41
Chris@1115 42 assert_difference 'Issue.count' do
Chris@1115 43 post :index, :key => 'secret', :email => IO.read(File.join(FIXTURES_PATH, 'ticket_on_given_project.eml'))
Chris@1115 44 end
Chris@0 45 assert_response 201
Chris@0 46 end
Chris@909 47
Chris@1115 48 def test_should_respond_with_422_if_not_created
Chris@1115 49 Project.find('onlinestore').destroy
Chris@1115 50
Chris@1115 51 Setting.mail_handler_api_enabled = 1
Chris@1115 52 Setting.mail_handler_api_key = 'secret'
Chris@1115 53
Chris@1115 54 assert_no_difference 'Issue.count' do
Chris@1115 55 post :index, :key => 'secret', :email => IO.read(File.join(FIXTURES_PATH, 'ticket_on_given_project.eml'))
Chris@1115 56 end
Chris@1115 57 assert_response 422
Chris@1115 58 end
Chris@1115 59
Chris@1115 60 def test_should_not_allow_with_api_disabled
Chris@0 61 # Disable API
Chris@0 62 Setting.mail_handler_api_enabled = 0
Chris@0 63 Setting.mail_handler_api_key = 'secret'
Chris@909 64
Chris@1115 65 assert_no_difference 'Issue.count' do
Chris@1115 66 post :index, :key => 'secret', :email => IO.read(File.join(FIXTURES_PATH, 'ticket_on_given_project.eml'))
Chris@1115 67 end
Chris@1115 68 assert_response 403
Chris@1115 69 end
Chris@1115 70
Chris@1115 71 def test_should_not_allow_with_wrong_key
Chris@1115 72 # Disable API
Chris@1115 73 Setting.mail_handler_api_enabled = 1
Chris@1115 74 Setting.mail_handler_api_key = 'secret'
Chris@1115 75
Chris@1115 76 assert_no_difference 'Issue.count' do
Chris@1115 77 post :index, :key => 'wrong', :email => IO.read(File.join(FIXTURES_PATH, 'ticket_on_given_project.eml'))
Chris@1115 78 end
Chris@0 79 assert_response 403
Chris@0 80 end
Chris@0 81 end