Chris@0
|
1 # redMine - project management software
|
Chris@0
|
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
|
Chris@0
|
3 #
|
Chris@0
|
4 # This program is free software; you can redistribute it and/or
|
Chris@0
|
5 # modify it under the terms of the GNU General Public License
|
Chris@0
|
6 # as published by the Free Software Foundation; either version 2
|
Chris@0
|
7 # of the License, or (at your option) any later version.
|
Chris@0
|
8 #
|
Chris@0
|
9 # This program is distributed in the hope that it will be useful,
|
Chris@0
|
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@0
|
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@0
|
12 # GNU General Public License for more details.
|
Chris@0
|
13 #
|
Chris@0
|
14 # You should have received a copy of the GNU General Public License
|
Chris@0
|
15 # along with this program; if not, write to the Free Software
|
Chris@0
|
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Chris@0
|
17
|
Chris@119
|
18 require File.expand_path('../../test_helper', __FILE__)
|
Chris@0
|
19 require 'repositories_controller'
|
Chris@0
|
20
|
Chris@0
|
21 # Re-raise errors caught by the controller.
|
Chris@0
|
22 class RepositoriesController; def rescue_action(e) raise e end; end
|
Chris@0
|
23
|
Chris@0
|
24 class RepositoriesDarcsControllerTest < ActionController::TestCase
|
Chris@0
|
25 fixtures :projects, :users, :roles, :members, :member_roles, :repositories, :enabled_modules
|
Chris@0
|
26
|
Chris@0
|
27 # No '..' in the repository path
|
Chris@0
|
28 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/darcs_repository'
|
Chris@245
|
29 PRJ_ID = 3
|
Chris@0
|
30
|
Chris@0
|
31 def setup
|
Chris@0
|
32 @controller = RepositoriesController.new
|
Chris@0
|
33 @request = ActionController::TestRequest.new
|
Chris@0
|
34 @response = ActionController::TestResponse.new
|
Chris@0
|
35 User.current = nil
|
Chris@245
|
36 @project = Project.find(PRJ_ID)
|
Chris@245
|
37 @repository = Repository::Darcs.create(
|
Chris@245
|
38 :project => @project, :url => REPOSITORY_PATH,
|
Chris@245
|
39 :log_encoding => 'UTF-8')
|
Chris@245
|
40 assert @repository
|
Chris@0
|
41 end
|
Chris@245
|
42
|
Chris@0
|
43 if File.directory?(REPOSITORY_PATH)
|
Chris@0
|
44 def test_show
|
Chris@245
|
45 @repository.fetch_changesets
|
Chris@245
|
46 @repository.reload
|
Chris@245
|
47 get :show, :id => PRJ_ID
|
Chris@0
|
48 assert_response :success
|
Chris@0
|
49 assert_template 'show'
|
Chris@0
|
50 assert_not_nil assigns(:entries)
|
Chris@0
|
51 assert_not_nil assigns(:changesets)
|
Chris@0
|
52 end
|
Chris@245
|
53
|
Chris@0
|
54 def test_browse_root
|
Chris@245
|
55 @repository.fetch_changesets
|
Chris@245
|
56 @repository.reload
|
Chris@245
|
57 get :show, :id => PRJ_ID
|
Chris@0
|
58 assert_response :success
|
Chris@0
|
59 assert_template 'show'
|
Chris@0
|
60 assert_not_nil assigns(:entries)
|
Chris@0
|
61 assert_equal 3, assigns(:entries).size
|
Chris@0
|
62 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
|
Chris@0
|
63 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
|
Chris@0
|
64 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
|
Chris@0
|
65 end
|
Chris@245
|
66
|
Chris@0
|
67 def test_browse_directory
|
Chris@245
|
68 @repository.fetch_changesets
|
Chris@245
|
69 @repository.reload
|
Chris@245
|
70 get :show, :id => PRJ_ID, :path => ['images']
|
Chris@0
|
71 assert_response :success
|
Chris@0
|
72 assert_template 'show'
|
Chris@0
|
73 assert_not_nil assigns(:entries)
|
Chris@0
|
74 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
|
Chris@0
|
75 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
|
Chris@0
|
76 assert_not_nil entry
|
Chris@0
|
77 assert_equal 'file', entry.kind
|
Chris@0
|
78 assert_equal 'images/edit.png', entry.path
|
Chris@0
|
79 end
|
Chris@245
|
80
|
Chris@0
|
81 def test_browse_at_given_revision
|
Chris@245
|
82 @repository.fetch_changesets
|
Chris@245
|
83 @repository.reload
|
Chris@245
|
84 get :show, :id => PRJ_ID, :path => ['images'], :rev => 1
|
Chris@0
|
85 assert_response :success
|
Chris@0
|
86 assert_template 'show'
|
Chris@0
|
87 assert_not_nil assigns(:entries)
|
Chris@0
|
88 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
|
Chris@0
|
89 end
|
Chris@245
|
90
|
Chris@0
|
91 def test_changes
|
Chris@245
|
92 @repository.fetch_changesets
|
Chris@245
|
93 @repository.reload
|
Chris@245
|
94 get :changes, :id => PRJ_ID, :path => ['images', 'edit.png']
|
Chris@0
|
95 assert_response :success
|
Chris@0
|
96 assert_template 'changes'
|
Chris@0
|
97 assert_tag :tag => 'h2', :content => 'edit.png'
|
Chris@0
|
98 end
|
Chris@245
|
99
|
Chris@0
|
100 def test_diff
|
Chris@245
|
101 @repository.fetch_changesets
|
Chris@245
|
102 @repository.reload
|
Chris@0
|
103 # Full diff of changeset 5
|
Chris@245
|
104 get :diff, :id => PRJ_ID, :rev => 5
|
Chris@0
|
105 assert_response :success
|
Chris@0
|
106 assert_template 'diff'
|
Chris@0
|
107 # Line 22 removed
|
Chris@0
|
108 assert_tag :tag => 'th',
|
Chris@0
|
109 :content => /22/,
|
Chris@0
|
110 :sibling => { :tag => 'td',
|
Chris@0
|
111 :attributes => { :class => /diff_out/ },
|
Chris@0
|
112 :content => /def remove/ }
|
Chris@0
|
113 end
|
Chris@0
|
114 else
|
Chris@0
|
115 puts "Darcs test repository NOT FOUND. Skipping functional tests !!!"
|
Chris@0
|
116 def test_fake; assert true end
|
Chris@0
|
117 end
|
Chris@0
|
118 end
|