1 # redMine - project management software
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 require File.dirname(__FILE__) + '/../test_helper'
19 require 'repositories_controller'
21 # Re-raise errors caught by the controller.
22 class RepositoriesController; def rescue_action(e) raise e end; end
24 class RepositoriesGitControllerTest < Test::Unit::TestCase
25 fixtures :projects, :users, :roles, :members, :repositories, :enabled_modules
27 # No '..' in the repository path
28 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/git_repository'
29 REPOSITORY_PATH.gsub!(/\//, "\\") if RUBY_PLATFORM =~ /mswin/
32 @controller = RepositoriesController.new
33 @request = ActionController::TestRequest.new
34 @response = ActionController::TestResponse.new
36 Repository::Git.create(:project => Project.find(3), :url => REPOSITORY_PATH)
39 if File.directory?(REPOSITORY_PATH)
42 assert_response :success
43 assert_template 'show'
44 assert_not_nil assigns(:entries)
45 assert_not_nil assigns(:changesets)
50 assert_response :success
51 assert_template 'browse'
52 assert_not_nil assigns(:entries)
53 assert_equal 3, assigns(:entries).size
54 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
55 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
56 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
59 def test_browse_directory
60 get :browse, :id => 3, :path => ['images']
61 assert_response :success
62 assert_template 'browse'
63 assert_not_nil assigns(:entries)
64 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
65 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
67 assert_equal 'file', entry.kind
68 assert_equal 'images/edit.png', entry.path
71 def test_browse_at_given_revision
72 get :browse, :id => 3, :path => ['images'], :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518'
73 assert_response :success
74 assert_template 'browse'
75 assert_not_nil assigns(:entries)
76 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
80 get :changes, :id => 3, :path => ['images', 'edit.png']
81 assert_response :success
82 assert_template 'changes'
83 assert_tag :tag => 'h2', :content => 'edit.png'
87 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb']
88 assert_response :success
89 assert_template 'entry'
91 assert_tag :tag => 'th',
93 :attributes => { :class => /line-num/ },
94 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
97 def test_entry_download
98 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'], :format => 'raw'
99 assert_response :success
101 assert @response.body.include?('WITHOUT ANY WARRANTY')
105 # Full diff of changeset 2f9c0091
106 get :diff, :id => 3, :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
107 assert_response :success
108 assert_template 'diff'
110 assert_tag :tag => 'th',
112 :sibling => { :tag => 'td',
113 :attributes => { :class => /diff_out/ },
114 :content => /def remove/ }
118 get :annotate, :id => 3, :path => ['sources', 'watchers_controller.rb']
119 assert_response :success
120 assert_template 'annotate'
121 # Line 23, changeset 2f9c0091
122 assert_tag :tag => 'th', :content => /23/,
123 :sibling => { :tag => 'td', :child => { :tag => 'a', :content => /2f9c0091/ } },
124 :sibling => { :tag => 'td', :content => /jsmith/ },
125 :sibling => { :tag => 'td', :content => /watcher =/ }
128 def test_annotate_binary_file
129 get :annotate, :id => 3, :path => ['images', 'delete.png']
131 assert_tag :tag => 'div', :attributes => { :class => /error/ },
132 :content => /can not be annotated/
135 puts "Git test repository NOT FOUND. Skipping functional tests !!!"
136 def test_fake; assert true end