Isolates all API routing tests to a specific test case.

git-svn-id: http://svn.redmine.org/redmine/trunk@13604 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang
2014-11-16 10:54:33 +00:00
parent cd6b2f2268
commit eae9c9ab2b
22 changed files with 207 additions and 438 deletions

View File

@@ -238,7 +238,29 @@ class ActiveSupport::TestCase
end
module Redmine
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
module ApiTest
API_FORMATS = %w(json xml).freeze
# Base class for API tests
class Base < ActionDispatch::IntegrationTest
# Test that a request allows the three types of API authentication
@@ -491,6 +513,20 @@ module Redmine
end
end
end
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
end
end