Mercurial > hg > soundsoftware-site
comparison test/functional/.svn/text-base/repositories_git_controller_test.rb.svn-base @ 0:513646585e45
* Import Redmine trunk SVN rev 3859
author | Chris Cannam |
---|---|
date | Fri, 23 Jul 2010 15:52:44 +0100 |
parents | |
children | 94944d00e43c |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:513646585e45 |
---|---|
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 < ActionController::TestCase | |
25 fixtures :projects, :users, :roles, :members, :member_roles, :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 Redmine::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 :show, :id => 3 | |
50 assert_response :success | |
51 assert_template 'show' | |
52 assert_not_nil assigns(:entries) | |
53 assert_equal 7, assigns(:entries).size | |
54 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'} | |
55 assert assigns(:entries).detect {|e| e.name == 'this_is_a_really_long_and_verbose_directory_name' && e.kind == 'dir'} | |
56 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'} | |
57 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'} | |
58 assert assigns(:entries).detect {|e| e.name == 'copied_README' && e.kind == 'file'} | |
59 assert assigns(:entries).detect {|e| e.name == 'new_file.txt' && e.kind == 'file'} | |
60 assert assigns(:entries).detect {|e| e.name == 'renamed_test.txt' && e.kind == 'file'} | |
61 end | |
62 | |
63 def test_browse_branch | |
64 get :show, :id => 3, :rev => 'test_branch' | |
65 assert_response :success | |
66 assert_template 'show' | |
67 assert_not_nil assigns(:entries) | |
68 assert_equal 4, assigns(:entries).size | |
69 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'} | |
70 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'} | |
71 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'} | |
72 assert assigns(:entries).detect {|e| e.name == 'test.txt' && e.kind == 'file'} | |
73 end | |
74 | |
75 def test_browse_directory | |
76 get :show, :id => 3, :path => ['images'] | |
77 assert_response :success | |
78 assert_template 'show' | |
79 assert_not_nil assigns(:entries) | |
80 assert_equal ['edit.png'], assigns(:entries).collect(&:name) | |
81 entry = assigns(:entries).detect {|e| e.name == 'edit.png'} | |
82 assert_not_nil entry | |
83 assert_equal 'file', entry.kind | |
84 assert_equal 'images/edit.png', entry.path | |
85 end | |
86 | |
87 def test_browse_at_given_revision | |
88 get :show, :id => 3, :path => ['images'], :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518' | |
89 assert_response :success | |
90 assert_template 'show' | |
91 assert_not_nil assigns(:entries) | |
92 assert_equal ['delete.png'], assigns(:entries).collect(&:name) | |
93 end | |
94 | |
95 def test_changes | |
96 get :changes, :id => 3, :path => ['images', 'edit.png'] | |
97 assert_response :success | |
98 assert_template 'changes' | |
99 assert_tag :tag => 'h2', :content => 'edit.png' | |
100 end | |
101 | |
102 def test_entry_show | |
103 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'] | |
104 assert_response :success | |
105 assert_template 'entry' | |
106 # Line 19 | |
107 assert_tag :tag => 'th', | |
108 :content => /11/, | |
109 :attributes => { :class => /line-num/ }, | |
110 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ } | |
111 end | |
112 | |
113 def test_entry_download | |
114 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'], :format => 'raw' | |
115 assert_response :success | |
116 # File content | |
117 assert @response.body.include?('WITHOUT ANY WARRANTY') | |
118 end | |
119 | |
120 def test_directory_entry | |
121 get :entry, :id => 3, :path => ['sources'] | |
122 assert_response :success | |
123 assert_template 'show' | |
124 assert_not_nil assigns(:entry) | |
125 assert_equal 'sources', assigns(:entry).name | |
126 end | |
127 | |
128 def test_diff | |
129 # Full diff of changeset 2f9c0091 | |
130 get :diff, :id => 3, :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7' | |
131 assert_response :success | |
132 assert_template 'diff' | |
133 # Line 22 removed | |
134 assert_tag :tag => 'th', | |
135 :content => /22/, | |
136 :sibling => { :tag => 'td', | |
137 :attributes => { :class => /diff_out/ }, | |
138 :content => /def remove/ } | |
139 end | |
140 | |
141 def test_annotate | |
142 get :annotate, :id => 3, :path => ['sources', 'watchers_controller.rb'] | |
143 assert_response :success | |
144 assert_template 'annotate' | |
145 # Line 23, changeset 2f9c0091 | |
146 assert_tag :tag => 'th', :content => /24/, | |
147 :sibling => { :tag => 'td', :child => { :tag => 'a', :content => /2f9c0091/ } }, | |
148 :sibling => { :tag => 'td', :content => /jsmith/ }, | |
149 :sibling => { :tag => 'td', :content => /watcher =/ } | |
150 end | |
151 | |
152 def test_annotate_binary_file | |
153 get :annotate, :id => 3, :path => ['images', 'edit.png'] | |
154 assert_response 500 | |
155 assert_tag :tag => 'div', :attributes => { :class => /error/ }, | |
156 :content => /can not be annotated/ | |
157 end | |
158 else | |
159 puts "Git test repository NOT FOUND. Skipping functional tests !!!" | |
160 def test_fake; assert true end | |
161 end | |
162 end |