]> source.dussan.org Git - redmine.git/commitdiff
Rails3: test: route: add private method to convert path parameter at repositories...
authorToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Wed, 4 Jan 2012 10:01:19 +0000 (10:01 +0000)
committerToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Wed, 4 Jan 2012 10:01:19 +0000 (10:01 +0000)
On Rails3, route returns "path/to/file.c" as :path parameter

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8498 e93f8b46-1217-0410-a6f0-8f06a7374b81

test/integration/routing/repositories_test.rb

index 8caa0e9e64cb9d8005e43ba240f752ab69b85a5f..2a88a9eae724ad1c11d3cfc34556faca929b01b1 100644 (file)
 require File.expand_path('../../../test_helper', __FILE__)
 
 class RoutingRepositoriesTest < ActionController::IntegrationTest
+  def setup
+    @path_hash  = repository_path_hash(%w[path to file.c])
+    assert_equal "path/to/file.c", @path_hash[:path]
+    assert_equal %w[path to file.c], @path_hash[:param]
+  end
+
   def test_repositories
     assert_routing(
         { :method => 'get',
@@ -70,60 +76,69 @@ class RoutingRepositoriesTest < ActionController::IntegrationTest
       )
     assert_routing(
         { :method => 'get',
-          :path => "/projects/redmine/repository/revisions/2/diff/path/to/file.c" },
+          :path => "/projects/redmine/repository/revisions/2/diff/#{@path_hash[:path]}" },
         { :controller => 'repositories', :action => 'diff', :id => 'redmine',
-          :path => %w[path to file.c], :rev => '2' }
+          :path => @path_hash[:param], :rev => '2' }
       )
     assert_routing(
         { :method => 'get',
-          :path => "/projects/redmine/repository/revisions/2/entry/path/to/file.c" },
+          :path => "/projects/redmine/repository/revisions/2/entry/#{@path_hash[:path]}" },
         { :controller => 'repositories', :action => 'entry', :id => 'redmine',
-          :path => %w[path to file.c], :rev => '2' }
+          :path => @path_hash[:param], :rev => '2' }
       )
     assert_routing(
         { :method => 'get',
-          :path => "/projects/redmine/repository/revisions/2/raw/path/to/file.c" },
+          :path => "/projects/redmine/repository/revisions/2/raw/#{@path_hash[:path]}" },
         { :controller => 'repositories', :action => 'entry', :id => 'redmine',
-          :path => %w[path to file.c], :rev => '2', :format => 'raw' }
+          :path => @path_hash[:param], :rev => '2', :format => 'raw' }
       )
   end
 
   def test_repositories_non_revisions_path
     assert_routing(
         { :method => 'get',
-          :path => "/projects/redmine/repository/diff/path/to/file.c" },
+          :path => "/projects/redmine/repository/diff/#{@path_hash[:path]}" },
         { :controller => 'repositories', :action => 'diff', :id => 'redmine',
-          :path => %w[path to file.c] }
+          :path => @path_hash[:param] }
       )
     assert_routing(
         { :method => 'get',
-          :path => "/projects/redmine/repository/browse/path/to/file.c" },
+          :path => "/projects/redmine/repository/browse/#{@path_hash[:path]}" },
         { :controller => 'repositories', :action => 'browse', :id => 'redmine',
-          :path => %w[path to file.c] }
+          :path => @path_hash[:param] }
       )
     assert_routing(
         { :method => 'get',
-          :path => "/projects/redmine/repository/entry/path/to/file.c" },
+          :path => "/projects/redmine/repository/entry/#{@path_hash[:path]}" },
         { :controller => 'repositories', :action => 'entry', :id => 'redmine',
-          :path => %w[path to file.c] }
+          :path => @path_hash[:param] }
       )
     assert_routing(
         { :method => 'get',
-          :path => "/projects/redmine/repository/raw/path/to/file.c" },
+          :path => "/projects/redmine/repository/raw/#{@path_hash[:path]}" },
         { :controller => 'repositories', :action => 'entry', :id => 'redmine',
-          :path => %w[path to file.c], :format => 'raw' }
+          :path => @path_hash[:param], :format => 'raw' }
       )
     assert_routing(
         { :method => 'get',
-          :path => "/projects/redmine/repository/annotate/path/to/file.c" },
+          :path => "/projects/redmine/repository/annotate/#{@path_hash[:path]}" },
         { :controller => 'repositories', :action => 'annotate', :id => 'redmine',
-          :path => %w[path to file.c] }
+          :path => @path_hash[:param] }
       )
     assert_routing(
         { :method => 'get',
-          :path => "/projects/redmine/repository/changes/path/to/file.c" },
+          :path => "/projects/redmine/repository/changes/#{@path_hash[:path]}" },
         { :controller => 'repositories', :action => 'changes', :id => 'redmine',
-          :path => %w[path to file.c] }
+          :path => @path_hash[:param] }
       )
   end
+
+private
+
+  def repository_path_hash(arr)
+    hs = {}
+    hs[:path]  = arr.join("/")
+    hs[:param] = arr
+    hs
+  end
 end