##// END OF EJS Templates
Merged r4631 from trunk....
Toshi MARUYAMA -
r4517:b0f0bd184817
parent child
Show More
@@ -1,157 +1,157
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2008 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19 require 'repositories_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class RepositoriesController; def rescue_action(e) raise e end; end
23 23
24 24 class RepositoriesMercurialControllerTest < ActionController::TestCase
25 25 fixtures :projects, :users, :roles, :members, :member_roles, :repositories, :enabled_modules
26 26
27 27 # No '..' in the repository path
28 28 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository'
29 29
30 30 def setup
31 31 @controller = RepositoriesController.new
32 32 @request = ActionController::TestRequest.new
33 33 @response = ActionController::TestResponse.new
34 34 User.current = nil
35 35 Repository::Mercurial.create(:project => Project.find(3), :url => REPOSITORY_PATH)
36 36 end
37 37
38 38 if File.directory?(REPOSITORY_PATH)
39 39 def test_show
40 40 get :show, :id => 3
41 41 assert_response :success
42 42 assert_template 'show'
43 43 assert_not_nil assigns(:entries)
44 44 assert_not_nil assigns(:changesets)
45 45 end
46 46
47 47 def test_show_root
48 48 get :show, :id => 3
49 49 assert_response :success
50 50 assert_template 'show'
51 51 assert_not_nil assigns(:entries)
52 52 assert_equal 3, assigns(:entries).size
53 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
53 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
54 54 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
55 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
55 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
56 56 end
57 57
58 58 def test_show_directory
59 59 get :show, :id => 3, :path => ['images']
60 60 assert_response :success
61 61 assert_template 'show'
62 62 assert_not_nil assigns(:entries)
63 63 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
64 64 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
65 65 assert_not_nil entry
66 66 assert_equal 'file', entry.kind
67 67 assert_equal 'images/edit.png', entry.path
68 68 end
69 69
70 70 def test_show_at_given_revision
71 71 get :show, :id => 3, :path => ['images'], :rev => 0
72 72 assert_response :success
73 73 assert_template 'show'
74 74 assert_not_nil assigns(:entries)
75 75 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
76 76 end
77 77
78 78 def test_changes
79 79 get :changes, :id => 3, :path => ['images', 'edit.png']
80 80 assert_response :success
81 81 assert_template 'changes'
82 82 assert_tag :tag => 'h2', :content => 'edit.png'
83 83 end
84 84
85 85 def test_entry_show
86 86 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb']
87 87 assert_response :success
88 88 assert_template 'entry'
89 # Line 19
89 # Line 10
90 90 assert_tag :tag => 'th',
91 :content => /10/,
92 :attributes => { :class => /line-num/ },
91 :content => '10',
92 :attributes => { :class => 'line-num' },
93 93 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
94 94 end
95 95
96 96 def test_entry_download
97 97 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'], :format => 'raw'
98 98 assert_response :success
99 99 # File content
100 100 assert @response.body.include?('WITHOUT ANY WARRANTY')
101 101 end
102 102
103 103 def test_directory_entry
104 104 get :entry, :id => 3, :path => ['sources']
105 105 assert_response :success
106 106 assert_template 'show'
107 107 assert_not_nil assigns(:entry)
108 108 assert_equal 'sources', assigns(:entry).name
109 109 end
110 110
111 111 def test_diff
112 112 # Full diff of changeset 4
113 113 get :diff, :id => 3, :rev => 4
114 114 assert_response :success
115 115 assert_template 'diff'
116 116 # Line 22 removed
117 117 assert_tag :tag => 'th',
118 :content => /22/,
118 :content => '22',
119 119 :sibling => { :tag => 'td',
120 120 :attributes => { :class => /diff_out/ },
121 121 :content => /def remove/ }
122 122 end
123 123
124 124 def test_annotate
125 125 get :annotate, :id => 3, :path => ['sources', 'watchers_controller.rb']
126 126 assert_response :success
127 127 assert_template 'annotate'
128 128 # Line 23, revision 4:def6d2f1254a
129 129 assert_tag :tag => 'th',
130 130 :content => '23',
131 131 :attributes => { :class => 'line-num' },
132 132 :sibling =>
133 133 {
134 134 :tag => 'td',
135 135 :attributes => { :class => 'revision' },
136 136 :child => { :tag => 'a', :content => '4' }
137 137 # :child => { :tag => 'a', :content => /4:def6d2f1/ }
138 138 }
139 139 assert_tag :tag => 'th',
140 140 :content => '23',
141 141 :attributes => { :class => 'line-num' },
142 142 :sibling =>
143 143 {
144 144 :tag => 'td' ,
145 145 :content => 'jsmith' ,
146 146 :attributes => { :class => 'author' },
147 147 }
148 148 assert_tag :tag => 'th',
149 149 :content => '23',
150 150 :attributes => { :class => 'line-num' },
151 151 :sibling => { :tag => 'td', :content => /watcher =/ }
152 152 end
153 153 else
154 154 puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!"
155 155 def test_fake; assert true end
156 156 end
157 157 end
General Comments 0
You need to be logged in to leave comments. Login now