@@ -1,103 +1,116 | |||
|
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 RepositoriesDarcsControllerTest < 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/darcs_repository' |
|
29 | PRJ_ID = 3 | |
|
29 | 30 | |
|
30 | 31 | def setup |
|
31 | 32 | @controller = RepositoriesController.new |
|
32 | 33 | @request = ActionController::TestRequest.new |
|
33 | 34 | @response = ActionController::TestResponse.new |
|
34 | 35 | User.current = nil |
|
35 | Repository::Darcs.create(:project => Project.find(3), :url => REPOSITORY_PATH) | |
|
36 | @project = Project.find(PRJ_ID) | |
|
37 | @repository = Repository::Darcs.create(:project => @project, :url => REPOSITORY_PATH) | |
|
38 | assert @repository | |
|
36 | 39 | end |
|
37 | 40 | |
|
38 | 41 | if File.directory?(REPOSITORY_PATH) |
|
39 | 42 | def test_show |
|
40 | get :show, :id => 3 | |
|
43 | @repository.fetch_changesets | |
|
44 | @repository.reload | |
|
45 | get :show, :id => PRJ_ID | |
|
41 | 46 | assert_response :success |
|
42 | 47 | assert_template 'show' |
|
43 | 48 | assert_not_nil assigns(:entries) |
|
44 | 49 | assert_not_nil assigns(:changesets) |
|
45 | 50 | end |
|
46 | 51 | |
|
47 | 52 | def test_browse_root |
|
48 | get :show, :id => 3 | |
|
53 | @repository.fetch_changesets | |
|
54 | @repository.reload | |
|
55 | get :show, :id => PRJ_ID | |
|
49 | 56 | assert_response :success |
|
50 | 57 | assert_template 'show' |
|
51 | 58 | assert_not_nil assigns(:entries) |
|
52 | 59 | assert_equal 3, assigns(:entries).size |
|
53 | 60 | assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'} |
|
54 | 61 | assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'} |
|
55 | 62 | assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'} |
|
56 | 63 | end |
|
57 | 64 | |
|
58 | 65 | def test_browse_directory |
|
59 | get :show, :id => 3, :path => ['images'] | |
|
66 | @repository.fetch_changesets | |
|
67 | @repository.reload | |
|
68 | get :show, :id => PRJ_ID, :path => ['images'] | |
|
60 | 69 | assert_response :success |
|
61 | 70 | assert_template 'show' |
|
62 | 71 | assert_not_nil assigns(:entries) |
|
63 | 72 | assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name) |
|
64 | 73 | entry = assigns(:entries).detect {|e| e.name == 'edit.png'} |
|
65 | 74 | assert_not_nil entry |
|
66 | 75 | assert_equal 'file', entry.kind |
|
67 | 76 | assert_equal 'images/edit.png', entry.path |
|
68 | 77 | end |
|
69 | 78 | |
|
70 | 79 | def test_browse_at_given_revision |
|
71 |
|
|
|
72 | get :show, :id => 3, :path => ['images'], :rev => 1 | |
|
80 | @repository.fetch_changesets | |
|
81 | @repository.reload | |
|
82 | get :show, :id => PRJ_ID, :path => ['images'], :rev => 1 | |
|
73 | 83 | assert_response :success |
|
74 | 84 | assert_template 'show' |
|
75 | 85 | assert_not_nil assigns(:entries) |
|
76 | 86 | assert_equal ['delete.png'], assigns(:entries).collect(&:name) |
|
77 | 87 | end |
|
78 | 88 | |
|
79 | 89 | def test_changes |
|
80 | get :changes, :id => 3, :path => ['images', 'edit.png'] | |
|
90 | @repository.fetch_changesets | |
|
91 | @repository.reload | |
|
92 | get :changes, :id => PRJ_ID, :path => ['images', 'edit.png'] | |
|
81 | 93 | assert_response :success |
|
82 | 94 | assert_template 'changes' |
|
83 | 95 | assert_tag :tag => 'h2', :content => 'edit.png' |
|
84 | 96 | end |
|
85 | 97 | |
|
86 | 98 | def test_diff |
|
87 |
|
|
|
99 | @repository.fetch_changesets | |
|
100 | @repository.reload | |
|
88 | 101 | # Full diff of changeset 5 |
|
89 |
get :diff, :id => |
|
|
102 | get :diff, :id => PRJ_ID, :rev => 5 | |
|
90 | 103 | assert_response :success |
|
91 | 104 | assert_template 'diff' |
|
92 | 105 | # Line 22 removed |
|
93 | 106 | assert_tag :tag => 'th', |
|
94 | 107 | :content => /22/, |
|
95 | 108 | :sibling => { :tag => 'td', |
|
96 | 109 | :attributes => { :class => /diff_out/ }, |
|
97 | 110 | :content => /def remove/ } |
|
98 | 111 | end |
|
99 | 112 | else |
|
100 | 113 | puts "Darcs test repository NOT FOUND. Skipping functional tests !!!" |
|
101 | 114 | def test_fake; assert true end |
|
102 | 115 | end |
|
103 | 116 | end |
General Comments 0
You need to be logged in to leave comments.
Login now