OSDN Git Service

Fix repository browsing at given revision for various scm and add tests for this.
[redminele/redmine.git] / test / functional / repositories_git_controller_test.rb
1 # redMine - project management software
2 # Copyright (C) 2006-2008  Jean-Philippe Lang
3 #
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.
8
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.
13
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.
17
18 require File.dirname(__FILE__) + '/../test_helper'
19 require 'repositories_controller'
20
21 # Re-raise errors caught by the controller.
22 class RepositoriesController; def rescue_action(e) raise e end; end
23
24 class RepositoriesGitControllerTest < Test::Unit::TestCase
25   fixtures :projects, :users, :roles, :members, :repositories, :enabled_modules
26
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/
30
31   def setup
32     @controller = RepositoriesController.new
33     @request    = ActionController::TestRequest.new
34     @response   = ActionController::TestResponse.new
35     User.current = nil
36     Repository::Git.create(:project => Project.find(3), :url => REPOSITORY_PATH)
37   end
38   
39   if File.directory?(REPOSITORY_PATH)
40     def test_show
41       get :show, :id => 3
42       assert_response :success
43       assert_template 'show'
44       assert_not_nil assigns(:entries)
45       assert_not_nil assigns(:changesets)
46     end
47     
48     def test_browse_root
49       get :browse, :id => 3
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'}
57     end
58     
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'}
66       assert_not_nil entry
67       assert_equal 'file', entry.kind
68       assert_equal 'images/edit.png', entry.path
69     end
70     
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)
77     end
78
79     def test_changes
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'
84     end
85     
86     def test_entry_show
87       get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb']
88       assert_response :success
89       assert_template 'entry'
90       # Line 19
91       assert_tag :tag => 'th',
92                  :content => /10/,
93                  :attributes => { :class => /line-num/ },
94                  :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
95     end
96     
97     def test_entry_download
98       get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'], :format => 'raw'
99       assert_response :success
100       # File content
101       assert @response.body.include?('WITHOUT ANY WARRANTY')
102     end
103   
104     def test_diff
105       # Full diff of changeset 2f9c0091
106       get :diff, :id => 3, :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
107       assert_response :success
108       assert_template 'diff'
109       # Line 22 removed
110       assert_tag :tag => 'th',
111                  :content => /22/,
112                  :sibling => { :tag => 'td', 
113                                :attributes => { :class => /diff_out/ },
114                                :content => /def remove/ }
115     end
116
117     def test_annotate
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 =/ }
126     end
127     
128     def test_annotate_binary_file
129       get :annotate, :id => 3, :path => ['images', 'delete.png']
130       assert_response 500
131       assert_tag :tag => 'div', :attributes => { :class => /error/ },
132                                 :content => /can not be annotated/
133     end
134   else
135     puts "Git test repository NOT FOUND. Skipping functional tests !!!"
136     def test_fake; assert true end
137   end
138 end