@@ -1,163 +1,165 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
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 |
|
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. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | require File.expand_path('../../test_helper', __FILE__) |
|
18 | require File.expand_path('../../test_helper', __FILE__) | |
19 |
|
19 | |||
20 | class RepositoriesDarcsControllerTest < ActionController::TestCase |
|
20 | class RepositoriesDarcsControllerTest < ActionController::TestCase | |
21 | tests RepositoriesController |
|
21 | tests RepositoriesController | |
22 |
|
22 | |||
23 | fixtures :projects, :users, :roles, :members, :member_roles, |
|
23 | fixtures :projects, :users, :roles, :members, :member_roles, | |
24 | :repositories, :enabled_modules |
|
24 | :repositories, :enabled_modules | |
25 |
|
25 | |||
26 | REPOSITORY_PATH = Rails.root.join('tmp/test/darcs_repository').to_s |
|
26 | REPOSITORY_PATH = Rails.root.join('tmp/test/darcs_repository').to_s | |
27 | PRJ_ID = 3 |
|
27 | PRJ_ID = 3 | |
28 | NUM_REV = 6 |
|
28 | NUM_REV = 6 | |
29 |
|
29 | |||
30 | def setup |
|
30 | def setup | |
31 | User.current = nil |
|
31 | User.current = nil | |
32 | @project = Project.find(PRJ_ID) |
|
32 | @project = Project.find(PRJ_ID) | |
33 | @repository = Repository::Darcs.create( |
|
33 | @repository = Repository::Darcs.create( | |
34 | :project => @project, |
|
34 | :project => @project, | |
35 | :url => REPOSITORY_PATH, |
|
35 | :url => REPOSITORY_PATH, | |
36 | :log_encoding => 'UTF-8' |
|
36 | :log_encoding => 'UTF-8' | |
37 | ) |
|
37 | ) | |
38 | assert @repository |
|
38 | assert @repository | |
39 | end |
|
39 | end | |
40 |
|
40 | |||
41 | if File.directory?(REPOSITORY_PATH) |
|
41 | if File.directory?(REPOSITORY_PATH) | |
42 | def test_get_new |
|
42 | def test_get_new | |
43 | @request.session[:user_id] = 1 |
|
43 | @request.session[:user_id] = 1 | |
44 | @project.repository.destroy |
|
44 | @project.repository.destroy | |
45 | get :new, :project_id => 'subproject1', :repository_scm => 'Darcs' |
|
45 | get :new, :project_id => 'subproject1', :repository_scm => 'Darcs' | |
46 | assert_response :success |
|
46 | assert_response :success | |
47 | assert_template 'new' |
|
47 | assert_template 'new' | |
48 | assert_kind_of Repository::Darcs, assigns(:repository) |
|
48 | assert_kind_of Repository::Darcs, assigns(:repository) | |
49 | assert assigns(:repository).new_record? |
|
49 | assert assigns(:repository).new_record? | |
50 | end |
|
50 | end | |
51 |
|
51 | |||
52 | def test_browse_root |
|
52 | def test_browse_root | |
53 | assert_equal 0, @repository.changesets.count |
|
53 | assert_equal 0, @repository.changesets.count | |
54 | @repository.fetch_changesets |
|
54 | @repository.fetch_changesets | |
55 | @project.reload |
|
55 | @project.reload | |
56 | assert_equal NUM_REV, @repository.changesets.count |
|
56 | assert_equal NUM_REV, @repository.changesets.count | |
57 | get :show, :id => PRJ_ID |
|
57 | get :show, :id => PRJ_ID | |
58 | assert_response :success |
|
58 | assert_response :success | |
59 | assert_template 'show' |
|
59 | assert_template 'show' | |
60 | assert_not_nil assigns(:entries) |
|
60 | assert_not_nil assigns(:entries) | |
61 | assert_equal 3, assigns(:entries).size |
|
61 | assert_equal 3, assigns(:entries).size | |
62 | assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'} |
|
62 | assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'} | |
63 | assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'} |
|
63 | assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'} | |
64 | assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'} |
|
64 | assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'} | |
65 | end |
|
65 | end | |
66 |
|
66 | |||
67 | def test_browse_directory |
|
67 | def test_browse_directory | |
68 | assert_equal 0, @repository.changesets.count |
|
68 | assert_equal 0, @repository.changesets.count | |
69 | @repository.fetch_changesets |
|
69 | @repository.fetch_changesets | |
70 | @project.reload |
|
70 | @project.reload | |
71 | assert_equal NUM_REV, @repository.changesets.count |
|
71 | assert_equal NUM_REV, @repository.changesets.count | |
72 | get :show, :id => PRJ_ID, :path => ['images'] |
|
72 | get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param] | |
73 | assert_response :success |
|
73 | assert_response :success | |
74 | assert_template 'show' |
|
74 | assert_template 'show' | |
75 | assert_not_nil assigns(:entries) |
|
75 | assert_not_nil assigns(:entries) | |
76 | assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name) |
|
76 | assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name) | |
77 | entry = assigns(:entries).detect {|e| e.name == 'edit.png'} |
|
77 | entry = assigns(:entries).detect {|e| e.name == 'edit.png'} | |
78 | assert_not_nil entry |
|
78 | assert_not_nil entry | |
79 | assert_equal 'file', entry.kind |
|
79 | assert_equal 'file', entry.kind | |
80 | assert_equal 'images/edit.png', entry.path |
|
80 | assert_equal 'images/edit.png', entry.path | |
81 | end |
|
81 | end | |
82 |
|
82 | |||
83 | def test_browse_at_given_revision |
|
83 | def test_browse_at_given_revision | |
84 | assert_equal 0, @repository.changesets.count |
|
84 | assert_equal 0, @repository.changesets.count | |
85 | @repository.fetch_changesets |
|
85 | @repository.fetch_changesets | |
86 | @project.reload |
|
86 | @project.reload | |
87 | assert_equal NUM_REV, @repository.changesets.count |
|
87 | assert_equal NUM_REV, @repository.changesets.count | |
88 |
get :show, :id => PRJ_ID, :path => ['images'], |
|
88 | get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param], | |
|
89 | :rev => 1 | |||
89 | assert_response :success |
|
90 | assert_response :success | |
90 | assert_template 'show' |
|
91 | assert_template 'show' | |
91 | assert_not_nil assigns(:entries) |
|
92 | assert_not_nil assigns(:entries) | |
92 | assert_equal ['delete.png'], assigns(:entries).collect(&:name) |
|
93 | assert_equal ['delete.png'], assigns(:entries).collect(&:name) | |
93 | end |
|
94 | end | |
94 |
|
95 | |||
95 | def test_changes |
|
96 | def test_changes | |
96 | assert_equal 0, @repository.changesets.count |
|
97 | assert_equal 0, @repository.changesets.count | |
97 | @repository.fetch_changesets |
|
98 | @repository.fetch_changesets | |
98 | @project.reload |
|
99 | @project.reload | |
99 | assert_equal NUM_REV, @repository.changesets.count |
|
100 | assert_equal NUM_REV, @repository.changesets.count | |
100 |
get :changes, :id => PRJ_ID, |
|
101 | get :changes, :id => PRJ_ID, | |
|
102 | :path => repository_path_hash(['images', 'edit.png'])[:param] | |||
101 | assert_response :success |
|
103 | assert_response :success | |
102 | assert_template 'changes' |
|
104 | assert_template 'changes' | |
103 | assert_tag :tag => 'h2', :content => 'edit.png' |
|
105 | assert_tag :tag => 'h2', :content => 'edit.png' | |
104 | end |
|
106 | end | |
105 |
|
107 | |||
106 | def test_diff |
|
108 | def test_diff | |
107 | assert_equal 0, @repository.changesets.count |
|
109 | assert_equal 0, @repository.changesets.count | |
108 | @repository.fetch_changesets |
|
110 | @repository.fetch_changesets | |
109 | @project.reload |
|
111 | @project.reload | |
110 | assert_equal NUM_REV, @repository.changesets.count |
|
112 | assert_equal NUM_REV, @repository.changesets.count | |
111 | # Full diff of changeset 5 |
|
113 | # Full diff of changeset 5 | |
112 | ['inline', 'sbs'].each do |dt| |
|
114 | ['inline', 'sbs'].each do |dt| | |
113 | get :diff, :id => PRJ_ID, :rev => 5, :type => dt |
|
115 | get :diff, :id => PRJ_ID, :rev => 5, :type => dt | |
114 | assert_response :success |
|
116 | assert_response :success | |
115 | assert_template 'diff' |
|
117 | assert_template 'diff' | |
116 | # Line 22 removed |
|
118 | # Line 22 removed | |
117 | assert_tag :tag => 'th', |
|
119 | assert_tag :tag => 'th', | |
118 | :content => '22', |
|
120 | :content => '22', | |
119 | :sibling => { :tag => 'td', |
|
121 | :sibling => { :tag => 'td', | |
120 | :attributes => { :class => /diff_out/ }, |
|
122 | :attributes => { :class => /diff_out/ }, | |
121 | :content => /def remove/ } |
|
123 | :content => /def remove/ } | |
122 | end |
|
124 | end | |
123 | end |
|
125 | end | |
124 |
|
126 | |||
125 | def test_destroy_valid_repository |
|
127 | def test_destroy_valid_repository | |
126 | @request.session[:user_id] = 1 # admin |
|
128 | @request.session[:user_id] = 1 # admin | |
127 | assert_equal 0, @repository.changesets.count |
|
129 | assert_equal 0, @repository.changesets.count | |
128 | @repository.fetch_changesets |
|
130 | @repository.fetch_changesets | |
129 | @project.reload |
|
131 | @project.reload | |
130 | assert_equal NUM_REV, @repository.changesets.count |
|
132 | assert_equal NUM_REV, @repository.changesets.count | |
131 |
|
133 | |||
132 | assert_difference 'Repository.count', -1 do |
|
134 | assert_difference 'Repository.count', -1 do | |
133 | delete :destroy, :id => @repository.id |
|
135 | delete :destroy, :id => @repository.id | |
134 | end |
|
136 | end | |
135 | assert_response 302 |
|
137 | assert_response 302 | |
136 | @project.reload |
|
138 | @project.reload | |
137 | assert_nil @project.repository |
|
139 | assert_nil @project.repository | |
138 | end |
|
140 | end | |
139 |
|
141 | |||
140 | def test_destroy_invalid_repository |
|
142 | def test_destroy_invalid_repository | |
141 | @request.session[:user_id] = 1 # admin |
|
143 | @request.session[:user_id] = 1 # admin | |
142 | @project.repository.destroy |
|
144 | @project.repository.destroy | |
143 | @repository = Repository::Darcs.create!( |
|
145 | @repository = Repository::Darcs.create!( | |
144 | :project => @project, |
|
146 | :project => @project, | |
145 | :url => "/invalid", |
|
147 | :url => "/invalid", | |
146 | :log_encoding => 'UTF-8' |
|
148 | :log_encoding => 'UTF-8' | |
147 | ) |
|
149 | ) | |
148 | @repository.fetch_changesets |
|
150 | @repository.fetch_changesets | |
149 | @project.reload |
|
151 | @project.reload | |
150 | assert_equal 0, @repository.changesets.count |
|
152 | assert_equal 0, @repository.changesets.count | |
151 |
|
153 | |||
152 | assert_difference 'Repository.count', -1 do |
|
154 | assert_difference 'Repository.count', -1 do | |
153 | delete :destroy, :id => @repository.id |
|
155 | delete :destroy, :id => @repository.id | |
154 | end |
|
156 | end | |
155 | assert_response 302 |
|
157 | assert_response 302 | |
156 | @project.reload |
|
158 | @project.reload | |
157 | assert_nil @project.repository |
|
159 | assert_nil @project.repository | |
158 | end |
|
160 | end | |
159 | else |
|
161 | else | |
160 | puts "Darcs test repository NOT FOUND. Skipping functional tests !!!" |
|
162 | puts "Darcs test repository NOT FOUND. Skipping functional tests !!!" | |
161 | def test_fake; assert true end |
|
163 | def test_fake; assert true end | |
162 | end |
|
164 | end | |
163 | end |
|
165 | end |
General Comments 0
You need to be logged in to leave comments.
Login now