diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2014-11-16 10:54:33 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2014-11-16 10:54:33 +0000 |
commit | eae9c9ab2be43c64c830a03e414b51a08571c957 (patch) | |
tree | cbe6b20000d60ad854ad8f2e245cbdfeca4b4787 /test/test_helper.rb | |
parent | cd6b2f2268d3e02ae652d3ad37f02170e3647a72 (diff) | |
download | redmine-eae9c9ab2be43c64c830a03e414b51a08571c957.tar.gz redmine-eae9c9ab2be43c64c830a03e414b51a08571c957.zip |
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
Diffstat (limited to 'test/test_helper.rb')
-rw-r--r-- | test/test_helper.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/test/test_helper.rb b/test/test_helper.rb index 3534c5746..a894a60ad 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -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 |