| 
									
										
										
										
											2011-03-20 18:25:38 +00:00
										 |  |  | # Redmine - project management software | 
					
						
							| 
									
										
										
										
											2014-01-29 22:45:39 +00:00
										 |  |  | # Copyright (C) 2006-2014  Jean-Philippe Lang | 
					
						
							| 
									
										
										
										
											2006-07-09 16:30:01 +00:00
										 |  |  | # | 
					
						
							|  |  |  | # This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  | # modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  | # as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  | # of the License, or (at your option) any later version. | 
					
						
							| 
									
										
										
										
											2011-06-23 11:19:05 +00:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2006-07-09 16:30:01 +00:00
										 |  |  | # This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  | # but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  | # GNU General Public License for more details. | 
					
						
							| 
									
										
										
										
											2011-06-23 11:19:05 +00:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2006-07-09 16:30:01 +00:00
										 |  |  | # You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  | # along with this program; if not, write to the Free Software | 
					
						
							|  |  |  | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-09 13:46:20 +00:00
										 |  |  | ENV["RAILS_ENV"] = "test" | 
					
						
							| 
									
										
										
										
											2006-06-28 18:11:03 +00:00
										 |  |  | require File.expand_path(File.dirname(__FILE__) + "/../config/environment") | 
					
						
							| 
									
										
										
										
											2012-04-25 17:17:49 +00:00
										 |  |  | require 'rails/test_help' | 
					
						
							| 
									
										
										
										
											2011-11-13 11:47:08 +00:00
										 |  |  | require Rails.root.join('test', 'mocks', 'open_id_authentication_mock.rb').to_s | 
					
						
							| 
									
										
										
										
											2006-06-28 18:11:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-22 11:58:05 +00:00
										 |  |  | require File.expand_path(File.dirname(__FILE__) + '/object_helpers') | 
					
						
							|  |  |  | include ObjectHelpers | 
					
						
							| 
									
										
										
										
											2009-10-20 00:36:51 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-24 16:26:50 +00:00
										 |  |  | require 'awesome_nested_set/version' | 
					
						
							| 
									
										
										
										
											2014-10-28 18:29:44 +00:00
										 |  |  | require 'net/ldap' | 
					
						
							| 
									
										
										
										
											2014-01-24 16:26:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-22 17:37:16 +00:00
										 |  |  | class ActionView::TestCase | 
					
						
							|  |  |  |   helper :application | 
					
						
							|  |  |  |   include ApplicationHelper | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-13 17:14:35 +00:00
										 |  |  | class ActiveSupport::TestCase | 
					
						
							| 
									
										
										
										
											2012-04-25 17:17:49 +00:00
										 |  |  |   include ActionDispatch::TestProcess | 
					
						
							| 
									
										
										
										
											2006-06-28 18:11:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-22 18:31:25 +00:00
										 |  |  |   self.use_transactional_fixtures = true | 
					
						
							| 
									
										
										
										
											2006-06-28 18:11:03 +00:00
										 |  |  |   self.use_instantiated_fixtures  = false | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-22 17:37:16 +00:00
										 |  |  |   #ESCAPED_CANT  = 'can't' | 
					
						
							|  |  |  |   #ESCAPED_UCANT = 'Can't' | 
					
						
							| 
									
										
										
										
											2014-02-04 04:32:04 +00:00
										 |  |  |   # Rails 4.0.2 | 
					
						
							| 
									
										
										
										
											2014-10-22 17:37:16 +00:00
										 |  |  |   ESCAPED_CANT  = 'can't' | 
					
						
							|  |  |  |   ESCAPED_UCANT = 'Can't' | 
					
						
							| 
									
										
										
										
											2014-02-04 04:32:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-07-09 16:30:01 +00:00
										 |  |  |   def log_user(login, password) | 
					
						
							| 
									
										
										
										
											2009-12-06 10:28:20 +00:00
										 |  |  |     User.anonymous | 
					
						
							| 
									
										
										
										
											2009-02-21 11:04:50 +00:00
										 |  |  |     get "/login" | 
					
						
							| 
									
										
										
										
											2006-07-29 09:32:58 +00:00
										 |  |  |     assert_equal nil, session[:user_id] | 
					
						
							| 
									
										
										
										
											2006-07-09 16:30:01 +00:00
										 |  |  |     assert_response :success | 
					
						
							|  |  |  |     assert_template "account/login" | 
					
						
							| 
									
										
										
										
											2009-02-21 11:04:50 +00:00
										 |  |  |     post "/login", :username => login, :password => password | 
					
						
							| 
									
										
										
										
											2006-07-29 09:32:58 +00:00
										 |  |  |     assert_equal login, User.find(session[:user_id]).login | 
					
						
							| 
									
										
										
										
											2006-07-09 16:30:01 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-09-01 00:50:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-10 14:56:29 +00:00
										 |  |  |   def uploaded_test_file(name, mime) | 
					
						
							| 
									
										
										
										
											2012-04-25 17:17:49 +00:00
										 |  |  |     fixture_file_upload("files/#{name}", mime, true) | 
					
						
							| 
									
										
										
										
											2008-01-06 17:06:14 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2010-06-19 03:54:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-02 19:44:37 +00:00
										 |  |  |   def credentials(user, password=nil) | 
					
						
							| 
									
										
										
										
											2012-04-25 17:17:49 +00:00
										 |  |  |     {'HTTP_AUTHORIZATION' => ActionController::HttpAuthentication::Basic.encode_credentials(user, password || user)} | 
					
						
							| 
									
										
										
										
											2012-01-02 19:44:37 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-19 03:54:23 +00:00
										 |  |  |   # Mock out a file | 
					
						
							| 
									
										
										
										
											2010-08-19 22:24:42 +00:00
										 |  |  |   def self.mock_file | 
					
						
							| 
									
										
										
										
											2010-06-19 03:54:23 +00:00
										 |  |  |     file = 'a_file.png' | 
					
						
							|  |  |  |     file.stubs(:size).returns(32) | 
					
						
							|  |  |  |     file.stubs(:original_filename).returns('a_file.png') | 
					
						
							|  |  |  |     file.stubs(:content_type).returns('image/png') | 
					
						
							|  |  |  |     file.stubs(:read).returns(false) | 
					
						
							|  |  |  |     file | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2010-08-19 22:24:42 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def mock_file | 
					
						
							|  |  |  |     self.class.mock_file | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-23 05:30:53 +00:00
										 |  |  |   def mock_file_with_options(options={}) | 
					
						
							|  |  |  |     file = '' | 
					
						
							|  |  |  |     file.stubs(:size).returns(32) | 
					
						
							|  |  |  |     original_filename = options[:original_filename] || nil | 
					
						
							|  |  |  |     file.stubs(:original_filename).returns(original_filename) | 
					
						
							|  |  |  |     content_type = options[:content_type] || nil | 
					
						
							|  |  |  |     file.stubs(:content_type).returns(content_type) | 
					
						
							|  |  |  |     file.stubs(:read).returns(false) | 
					
						
							|  |  |  |     file | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-09 18:40:59 +00:00
										 |  |  |   # Use a temporary directory for attachment related tests | 
					
						
							|  |  |  |   def set_tmp_attachments_directory | 
					
						
							| 
									
										
										
										
											2011-06-16 04:02:31 +00:00
										 |  |  |     Dir.mkdir "#{Rails.root}/tmp/test" unless File.directory?("#{Rails.root}/tmp/test") | 
					
						
							|  |  |  |     unless File.directory?("#{Rails.root}/tmp/test/attachments") | 
					
						
							|  |  |  |       Dir.mkdir "#{Rails.root}/tmp/test/attachments" | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |     Attachment.storage_path = "#{Rails.root}/tmp/test/attachments" | 
					
						
							| 
									
										
										
										
											2008-06-09 18:40:59 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-06-16 04:02:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-16 17:52:47 +00:00
										 |  |  |   def set_fixtures_attachments_directory | 
					
						
							|  |  |  |     Attachment.storage_path = "#{Rails.root}/test/fixtures/files" | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-21 16:04:51 +00:00
										 |  |  |   def with_settings(options, &block) | 
					
						
							| 
									
										
										
										
											2013-02-15 08:28:34 +00:00
										 |  |  |     saved_settings = options.keys.inject({}) do |h, k| | 
					
						
							|  |  |  |       h[k] = case Setting[k] | 
					
						
							|  |  |  |         when Symbol, false, true, nil | 
					
						
							|  |  |  |           Setting[k] | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |           Setting[k].dup | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       h | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2009-02-21 16:04:51 +00:00
										 |  |  |     options.each {|k, v| Setting[k] = v} | 
					
						
							|  |  |  |     yield | 
					
						
							| 
									
										
										
										
											2011-03-27 15:41:05 +00:00
										 |  |  |   ensure | 
					
						
							| 
									
										
										
										
											2011-11-26 17:37:20 +00:00
										 |  |  |     saved_settings.each {|k, v| Setting[k] = v} if saved_settings | 
					
						
							| 
									
										
										
										
											2009-02-21 16:04:51 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2009-12-30 19:42:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-18 17:08:42 +00:00
										 |  |  |   # Yields the block with user as the current user | 
					
						
							|  |  |  |   def with_current_user(user, &block) | 
					
						
							|  |  |  |     saved_user = User.current | 
					
						
							|  |  |  |     User.current = user | 
					
						
							|  |  |  |     yield | 
					
						
							|  |  |  |   ensure | 
					
						
							|  |  |  |     User.current = saved_user | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-15 09:18:01 +00:00
										 |  |  |   def with_locale(locale, &block) | 
					
						
							|  |  |  |     saved_localed = ::I18n.locale | 
					
						
							|  |  |  |     ::I18n.locale = locale | 
					
						
							|  |  |  |     yield | 
					
						
							|  |  |  |   ensure | 
					
						
							|  |  |  |     ::I18n.locale = saved_localed | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-16 16:40:50 +00:00
										 |  |  |   def self.ldap_configured? | 
					
						
							|  |  |  |     @test_ldap = Net::LDAP.new(:host => '127.0.0.1', :port => 389) | 
					
						
							|  |  |  |     return @test_ldap.bind | 
					
						
							| 
									
										
										
										
											2010-02-17 18:08:15 +00:00
										 |  |  |   rescue Exception => e | 
					
						
							|  |  |  |     # LDAP is not listening | 
					
						
							|  |  |  |     return nil | 
					
						
							| 
									
										
										
										
											2010-02-16 16:40:50 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-06-20 12:33:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-07 13:48:07 +00:00
										 |  |  |   def self.convert_installed? | 
					
						
							| 
									
										
										
										
											2012-07-16 17:37:24 +00:00
										 |  |  |     Redmine::Thumbnail.convert_available? | 
					
						
							| 
									
										
										
										
											2012-07-07 13:48:07 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-01 08:32:21 +00:00
										 |  |  |   # Returns the path to the test +vendor+ repository | 
					
						
							|  |  |  |   def self.repository_path(vendor) | 
					
						
							| 
									
										
										
										
											2014-10-22 17:37:16 +00:00
										 |  |  |     path = Rails.root.join("tmp/test/#{vendor.downcase}_repository").to_s | 
					
						
							|  |  |  |     # Unlike ruby, JRuby returns Rails.root with backslashes under Windows | 
					
						
							|  |  |  |     path.tr("\\", "/") | 
					
						
							| 
									
										
										
										
											2010-05-01 08:32:21 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-06-20 12:33:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-20 23:10:11 +00:00
										 |  |  |   # Returns the url of the subversion test repository | 
					
						
							| 
									
										
										
										
											2011-03-20 18:25:38 +00:00
										 |  |  |   def self.subversion_repository_url | 
					
						
							|  |  |  |     path = repository_path('subversion') | 
					
						
							|  |  |  |     path = '/' + path unless path.starts_with?('/') | 
					
						
							|  |  |  |     "file://#{path}" | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-06-20 12:33:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-01 08:32:21 +00:00
										 |  |  |   # Returns true if the +vendor+ test repository is configured | 
					
						
							|  |  |  |   def self.repository_configured?(vendor) | 
					
						
							|  |  |  |     File.directory?(repository_path(vendor)) | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-06-20 12:33:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-23 06:11:59 +00:00
										 |  |  |   def repository_path_hash(arr) | 
					
						
							|  |  |  |     hs = {} | 
					
						
							|  |  |  |     hs[:path]  = arr.join("/") | 
					
						
							| 
									
										
										
										
											2012-04-25 17:17:49 +00:00
										 |  |  |     hs[:param] = arr.join("/") | 
					
						
							| 
									
										
										
										
											2012-02-23 06:11:59 +00:00
										 |  |  |     hs | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-10 17:38:17 +00:00
										 |  |  |   def assert_save(object) | 
					
						
							|  |  |  |     saved = object.save | 
					
						
							|  |  |  |     message = "#{object.class} could not be saved" | 
					
						
							|  |  |  |     errors = object.errors.full_messages.map {|m| "- #{m}"} | 
					
						
							|  |  |  |     message << ":\n#{errors.join("\n")}" if errors.any? | 
					
						
							|  |  |  |     assert_equal true, saved, message | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-22 09:38:21 +00:00
										 |  |  |   def assert_select_error(arg) | 
					
						
							|  |  |  |     assert_select '#errorExplanation', :text => arg | 
					
						
							| 
									
										
										
										
											2010-10-23 11:07:04 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-09-01 00:50:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-21 06:35:49 +00:00
										 |  |  |   def assert_include(expected, s, message=nil) | 
					
						
							|  |  |  |     assert s.include?(expected), (message || "\"#{expected}\" not found in \"#{s}\"") | 
					
						
							| 
									
										
										
										
											2011-07-10 08:00:25 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2010-02-16 16:40:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-13 09:20:11 +00:00
										 |  |  |   def assert_not_include(expected, s, message=nil) | 
					
						
							|  |  |  |     assert !s.include?(expected), (message || "\"#{expected}\" found in \"#{s}\"") | 
					
						
							| 
									
										
										
										
											2012-03-04 13:28:18 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-20 14:49:32 +00:00
										 |  |  |   def assert_select_in(text, *args, &block) | 
					
						
							|  |  |  |     d = HTML::Document.new(CGI::unescapeHTML(String.new(text))).root | 
					
						
							|  |  |  |     assert_select(d, *args, &block) | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-13 09:20:11 +00:00
										 |  |  |   def assert_mail_body_match(expected, mail, message=nil) | 
					
						
							| 
									
										
										
										
											2012-03-04 13:28:18 +00:00
										 |  |  |     if expected.is_a?(String) | 
					
						
							| 
									
										
										
										
											2013-07-13 09:20:11 +00:00
										 |  |  |       assert_include expected, mail_body(mail), message | 
					
						
							| 
									
										
										
										
											2012-03-04 13:28:18 +00:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2013-07-13 09:20:11 +00:00
										 |  |  |       assert_match expected, mail_body(mail), message | 
					
						
							| 
									
										
										
										
											2012-03-04 13:28:18 +00:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-13 09:20:11 +00:00
										 |  |  |   def assert_mail_body_no_match(expected, mail, message=nil) | 
					
						
							| 
									
										
										
										
											2012-03-04 13:28:18 +00:00
										 |  |  |     if expected.is_a?(String) | 
					
						
							| 
									
										
										
										
											2013-07-13 09:20:11 +00:00
										 |  |  |       assert_not_include expected, mail_body(mail), message | 
					
						
							| 
									
										
										
										
											2012-03-04 13:28:18 +00:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2013-07-13 09:20:11 +00:00
										 |  |  |       assert_no_match expected, mail_body(mail), message | 
					
						
							| 
									
										
										
										
											2012-03-04 13:28:18 +00:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-04 14:01:54 +00:00
										 |  |  |   def mail_body(mail) | 
					
						
							| 
									
										
										
										
											2012-04-25 17:17:49 +00:00
										 |  |  |     mail.parts.first.body.encoded | 
					
						
							| 
									
										
										
										
											2012-03-04 14:01:54 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2014-01-24 16:26:50 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   # awesome_nested_set new node lft and rgt value changed this refactor revision. | 
					
						
							|  |  |  |   #   https://github.com/collectiveidea/awesome_nested_set/commit/199fca9bb938e40200cd90714dc69247ef017c61 | 
					
						
							| 
									
										
										
										
											2014-01-24 16:40:06 +00:00
										 |  |  |   # The reason of behavior change is that "self.class.base_class.unscoped" was added to this line. | 
					
						
							| 
									
										
										
										
											2014-01-24 16:26:50 +00:00
										 |  |  |   #   https://github.com/collectiveidea/awesome_nested_set/commit/199fca9bb9#diff-f61b59a5e6319024e211b0ffdd0e4ef1R273 | 
					
						
							|  |  |  |   # It seems correct behavior because of this line comment. | 
					
						
							|  |  |  |   #   https://github.com/collectiveidea/awesome_nested_set/blame/199fca9bb9/lib/awesome_nested_set/model.rb#L278 | 
					
						
							|  |  |  |   def new_issue_lft | 
					
						
							| 
									
										
										
										
											2014-03-26 01:47:48 +00:00
										 |  |  |     # ::AwesomeNestedSet::VERSION > "2.1.6" ? Issue.maximum(:rgt) + 1 : 1 | 
					
						
							|  |  |  |     Issue.maximum(:rgt) + 1
 | 
					
						
							| 
									
										
										
										
											2014-01-24 16:26:50 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-01-22 18:26:04 +00:00
										 |  |  | end | 
					
						
							| 
									
										
										
										
											2010-03-08 16:47:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-22 18:26:04 +00:00
										 |  |  | module Redmine | 
					
						
							| 
									
										
										
										
											2014-11-16 10:54:33 +00:00
										 |  |  |   class RoutingTest < ActionDispatch::IntegrationTest | 
					
						
							|  |  |  |     def should_route(arg) | 
					
						
							|  |  |  |       arg = arg.dup | 
					
						
							|  |  |  |       request = arg.keys.detect {|key| key.is_a?(String)} | 
					
						
							|  |  |  |       raise ArgumentError unless request | 
					
						
							|  |  |  |       options = arg.slice!(request) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       raise ArgumentError unless request =~ /\A(GET|POST|PUT|PATCH|DELETE)\s+(.+)\z/ | 
					
						
							|  |  |  |       method, path = $1.downcase.to_sym, $2 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       raise ArgumentError unless arg.values.first =~ /\A(.+)#(.+)\z/ | 
					
						
							|  |  |  |       controller, action = $1, $2 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       assert_routing( | 
					
						
							|  |  |  |         {:method => method, :path => path}, | 
					
						
							|  |  |  |         options.merge(:controller => controller, :action => action) | 
					
						
							|  |  |  |       ) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-22 18:26:04 +00:00
										 |  |  |   module ApiTest | 
					
						
							| 
									
										
										
										
											2014-11-16 10:54:33 +00:00
										 |  |  |     API_FORMATS = %w(json xml).freeze | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-22 18:26:04 +00:00
										 |  |  |     # Base class for API tests | 
					
						
							|  |  |  |     class Base < ActionDispatch::IntegrationTest | 
					
						
							| 
									
										
										
										
											2014-11-30 15:10:56 +00:00
										 |  |  |       def setup | 
					
						
							|  |  |  |         Setting.rest_api_enabled = '1' | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def teardown | 
					
						
							|  |  |  |         Setting.rest_api_enabled = '0' | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2010-12-23 14:49:14 +00:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2014-11-16 10:54:33 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     class Routing < Redmine::RoutingTest | 
					
						
							|  |  |  |       def should_route(arg) | 
					
						
							|  |  |  |         arg = arg.dup | 
					
						
							|  |  |  |         request = arg.keys.detect {|key| key.is_a?(String)} | 
					
						
							|  |  |  |         raise ArgumentError unless request | 
					
						
							|  |  |  |         options = arg.slice!(request) | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  |         API_FORMATS.each do |format| | 
					
						
							|  |  |  |           format_request = request.sub /$/, ".#{format}" | 
					
						
							|  |  |  |           super options.merge(format_request => arg[request], :format => format) | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2010-11-01 15:45:03 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2010-11-01 15:26:05 +00:00
										 |  |  | end | 
					
						
							| 
									
										
										
										
											2012-12-02 18:07:35 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | # URL helpers do not work with config.threadsafe! | 
					
						
							|  |  |  | # https://github.com/rspec/rspec-rails/issues/476#issuecomment-4705454 | 
					
						
							|  |  |  | ActionView::TestCase::TestController.instance_eval do | 
					
						
							|  |  |  |   helper Rails.application.routes.url_helpers | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | ActionView::TestCase::TestController.class_eval do | 
					
						
							|  |  |  |   def _routes | 
					
						
							|  |  |  |     Rails.application.routes | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |