@@ -1,155 +1,153 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2011 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 RepositoriesBazaarControllerTest < ActionController::TestCase |
|
25 | 25 | fixtures :projects, :users, :roles, :members, :member_roles, |
|
26 | 26 | :repositories, :enabled_modules |
|
27 | 27 | |
|
28 | # No '..' in the repository path | |
|
29 | REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + | |
|
30 | '/tmp/test/bazaar_repository/trunk' | |
|
28 | REPOSITORY_PATH = Rails.root.join('tmp/test/bazaar_repository/trunk').to_s | |
|
31 | 29 | PRJ_ID = 3 |
|
32 | 30 | |
|
33 | 31 | def setup |
|
34 | 32 | @controller = RepositoriesController.new |
|
35 | 33 | @request = ActionController::TestRequest.new |
|
36 | 34 | @response = ActionController::TestResponse.new |
|
37 | 35 | User.current = nil |
|
38 | 36 | @project = Project.find(PRJ_ID) |
|
39 | 37 | @repository = Repository::Bazaar.create( |
|
40 | 38 | :project => @project, |
|
41 | 39 | :url => REPOSITORY_PATH, |
|
42 | 40 | :log_encoding => 'UTF-8') |
|
43 | 41 | assert @repository |
|
44 | 42 | end |
|
45 | 43 | |
|
46 | 44 | if File.directory?(REPOSITORY_PATH) |
|
47 | 45 | def test_browse_root |
|
48 | 46 | get :show, :id => PRJ_ID |
|
49 | 47 | assert_response :success |
|
50 | 48 | assert_template 'show' |
|
51 | 49 | assert_not_nil assigns(:entries) |
|
52 | 50 | assert_equal 2, assigns(:entries).size |
|
53 | 51 | assert assigns(:entries).detect {|e| e.name == 'directory' && e.kind == 'dir'} |
|
54 | 52 | assert assigns(:entries).detect {|e| e.name == 'doc-mkdir.txt' && e.kind == 'file'} |
|
55 | 53 | end |
|
56 | 54 | |
|
57 | 55 | def test_browse_directory |
|
58 | 56 | get :show, :id => PRJ_ID, :path => ['directory'] |
|
59 | 57 | assert_response :success |
|
60 | 58 | assert_template 'show' |
|
61 | 59 | assert_not_nil assigns(:entries) |
|
62 | 60 | assert_equal ['doc-ls.txt', 'document.txt', 'edit.png'], assigns(:entries).collect(&:name) |
|
63 | 61 | entry = assigns(:entries).detect {|e| e.name == 'edit.png'} |
|
64 | 62 | assert_not_nil entry |
|
65 | 63 | assert_equal 'file', entry.kind |
|
66 | 64 | assert_equal 'directory/edit.png', entry.path |
|
67 | 65 | end |
|
68 | 66 | |
|
69 | 67 | def test_browse_at_given_revision |
|
70 | 68 | get :show, :id => PRJ_ID, :path => [], :rev => 3 |
|
71 | 69 | assert_response :success |
|
72 | 70 | assert_template 'show' |
|
73 | 71 | assert_not_nil assigns(:entries) |
|
74 | 72 | assert_equal ['directory', 'doc-deleted.txt', 'doc-ls.txt', 'doc-mkdir.txt'], |
|
75 | 73 | assigns(:entries).collect(&:name) |
|
76 | 74 | end |
|
77 | 75 | |
|
78 | 76 | def test_changes |
|
79 | 77 | get :changes, :id => PRJ_ID, :path => ['doc-mkdir.txt'] |
|
80 | 78 | assert_response :success |
|
81 | 79 | assert_template 'changes' |
|
82 | 80 | assert_tag :tag => 'h2', :content => 'doc-mkdir.txt' |
|
83 | 81 | end |
|
84 | 82 | |
|
85 | 83 | def test_entry_show |
|
86 | 84 | get :entry, :id => PRJ_ID, :path => ['directory', 'doc-ls.txt'] |
|
87 | 85 | assert_response :success |
|
88 | 86 | assert_template 'entry' |
|
89 | 87 | # Line 19 |
|
90 | 88 | assert_tag :tag => 'th', |
|
91 | 89 | :content => /29/, |
|
92 | 90 | :attributes => { :class => /line-num/ }, |
|
93 | 91 | :sibling => { :tag => 'td', :content => /Show help message/ } |
|
94 | 92 | end |
|
95 | 93 | |
|
96 | 94 | def test_entry_download |
|
97 | 95 | get :entry, :id => PRJ_ID, :path => ['directory', 'doc-ls.txt'], :format => 'raw' |
|
98 | 96 | assert_response :success |
|
99 | 97 | # File content |
|
100 | 98 | assert @response.body.include?('Show help message') |
|
101 | 99 | end |
|
102 | 100 | |
|
103 | 101 | def test_directory_entry |
|
104 | 102 | get :entry, :id => PRJ_ID, :path => ['directory'] |
|
105 | 103 | assert_response :success |
|
106 | 104 | assert_template 'show' |
|
107 | 105 | assert_not_nil assigns(:entry) |
|
108 | 106 | assert_equal 'directory', assigns(:entry).name |
|
109 | 107 | end |
|
110 | 108 | |
|
111 | 109 | def test_diff |
|
112 | 110 | # Full diff of changeset 3 |
|
113 | 111 | ['inline', 'sbs'].each do |dt| |
|
114 | 112 | get :diff, :id => PRJ_ID, :rev => 3, :type => dt |
|
115 | 113 | assert_response :success |
|
116 | 114 | assert_template 'diff' |
|
117 | 115 | # Line 11 removed |
|
118 | 116 | assert_tag :tag => 'th', |
|
119 | 117 | :content => '11', |
|
120 | 118 | :sibling => { :tag => 'td', |
|
121 | 119 | :attributes => { :class => /diff_out/ }, |
|
122 | 120 | :content => /Display more information/ } |
|
123 | 121 | end |
|
124 | 122 | end |
|
125 | 123 | |
|
126 | 124 | def test_annotate |
|
127 | 125 | get :annotate, :id => PRJ_ID, :path => ['doc-mkdir.txt'] |
|
128 | 126 | assert_response :success |
|
129 | 127 | assert_template 'annotate' |
|
130 | 128 | assert_tag :tag => 'th', :content => '2', |
|
131 | 129 | :sibling => { |
|
132 | 130 | :tag => 'td', |
|
133 | 131 | :child => { |
|
134 | 132 | :tag => 'a', |
|
135 | 133 | :content => '3' |
|
136 | 134 | } |
|
137 | 135 | } |
|
138 | 136 | assert_tag :tag => 'th', :content => '2', |
|
139 | 137 | :sibling => { :tag => 'td', :content => /jsmith/ } |
|
140 | 138 | assert_tag :tag => 'th', :content => '2', |
|
141 | 139 | :sibling => { |
|
142 | 140 | :tag => 'td', |
|
143 | 141 | :child => { |
|
144 | 142 | :tag => 'a', |
|
145 | 143 | :content => '3' |
|
146 | 144 | } |
|
147 | 145 | } |
|
148 | 146 | assert_tag :tag => 'th', :content => '2', |
|
149 | 147 | :sibling => { :tag => 'td', :content => /Main purpose/ } |
|
150 | 148 | end |
|
151 | 149 | else |
|
152 | 150 | puts "Bazaar test repository NOT FOUND. Skipping functional tests !!!" |
|
153 | 151 | def test_fake; assert true end |
|
154 | 152 | end |
|
155 | 153 | end |
General Comments 0
You need to be logged in to leave comments.
Login now