To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / test / functional / repositories_cvs_controller_test.rb @ 442:753f1380d6bc

History | View | Annotate | Download (7.82 KB)

1 441:cbce1fd3b1b7 Chris
# Redmine - project management software
2
# Copyright (C) 2006-2011  Jean-Philippe Lang
3 0:513646585e45 Chris
#
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU General Public License
6
# as published by the Free Software Foundation; either version 2
7
# of the License, or (at your option) any later version.
8 441:cbce1fd3b1b7 Chris
#
9 0:513646585e45 Chris
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13 441:cbce1fd3b1b7 Chris
#
14 0:513646585e45 Chris
# You should have received a copy of the GNU General Public License
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.
17
18 119:8661b858af72 Chris
require File.expand_path('../../test_helper', __FILE__)
19 0:513646585e45 Chris
require 'repositories_controller'
20
21
# Re-raise errors caught by the controller.
22
class RepositoriesController; def rescue_action(e) raise e end; end
23
24
class RepositoriesCvsControllerTest < ActionController::TestCase
25 119:8661b858af72 Chris
  fixtures :projects, :users, :roles, :members, :member_roles, :repositories, :enabled_modules
26 0:513646585e45 Chris
27
  # No '..' in the repository path
28
  REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/cvs_repository'
29
  REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
30
  # CVS module
31
  MODULE_NAME = 'test'
32 210:0579821a129a Chris
  PRJ_ID = 3
33
34 0:513646585e45 Chris
  def setup
35
    @controller = RepositoriesController.new
36
    @request    = ActionController::TestRequest.new
37
    @response   = ActionController::TestResponse.new
38
    Setting.default_language = 'en'
39
    User.current = nil
40
41 210:0579821a129a Chris
    @project = Project.find(PRJ_ID)
42 441:cbce1fd3b1b7 Chris
    @repository  = Repository::Cvs.create(:project      => Project.find(PRJ_ID),
43
                                          :root_url     => REPOSITORY_PATH,
44
                                          :url          => MODULE_NAME,
45 245:051f544170fe Chris
                                          :log_encoding => 'UTF-8')
46 210:0579821a129a Chris
    assert @repository
47 0:513646585e45 Chris
  end
48 441:cbce1fd3b1b7 Chris
49 0:513646585e45 Chris
  if File.directory?(REPOSITORY_PATH)
50
    def test_browse_root
51 210:0579821a129a Chris
      @repository.fetch_changesets
52
      @repository.reload
53
      get :show, :id => PRJ_ID
54 0:513646585e45 Chris
      assert_response :success
55
      assert_template 'show'
56
      assert_not_nil assigns(:entries)
57
      assert_equal 3, assigns(:entries).size
58 441:cbce1fd3b1b7 Chris
59 0:513646585e45 Chris
      entry = assigns(:entries).detect {|e| e.name == 'images'}
60
      assert_equal 'dir', entry.kind
61
62
      entry = assigns(:entries).detect {|e| e.name == 'README'}
63
      assert_equal 'file', entry.kind
64 441:cbce1fd3b1b7 Chris
65
      assert_not_nil assigns(:changesets)
66
      assigns(:changesets).size > 0
67 0:513646585e45 Chris
    end
68 441:cbce1fd3b1b7 Chris
69 0:513646585e45 Chris
    def test_browse_directory
70 210:0579821a129a Chris
      @repository.fetch_changesets
71
      @repository.reload
72
      get :show, :id => PRJ_ID, :path => ['images']
73 0:513646585e45 Chris
      assert_response :success
74
      assert_template 'show'
75
      assert_not_nil assigns(:entries)
76
      assert_equal ['add.png', 'delete.png', 'edit.png'], assigns(:entries).collect(&:name)
77
      entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
78
      assert_not_nil entry
79
      assert_equal 'file', entry.kind
80
      assert_equal 'images/edit.png', entry.path
81
    end
82 441:cbce1fd3b1b7 Chris
83 0:513646585e45 Chris
    def test_browse_at_given_revision
84 210:0579821a129a Chris
      @repository.fetch_changesets
85
      @repository.reload
86
      get :show, :id => PRJ_ID, :path => ['images'], :rev => 1
87 0:513646585e45 Chris
      assert_response :success
88
      assert_template 'show'
89
      assert_not_nil assigns(:entries)
90
      assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
91
    end
92 441:cbce1fd3b1b7 Chris
93 0:513646585e45 Chris
    def test_entry
94 210:0579821a129a Chris
      @repository.fetch_changesets
95
      @repository.reload
96
      get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
97 0:513646585e45 Chris
      assert_response :success
98
      assert_template 'entry'
99 441:cbce1fd3b1b7 Chris
      assert_no_tag :tag => 'td',
100
                    :attributes => { :class => /line-code/},
101
                    :content => /before_filter/
102 0:513646585e45 Chris
    end
103 441:cbce1fd3b1b7 Chris
104 0:513646585e45 Chris
    def test_entry_at_given_revision
105
      # changesets must be loaded
106 210:0579821a129a Chris
      @repository.fetch_changesets
107
      @repository.reload
108
      get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'], :rev => 2
109 0:513646585e45 Chris
      assert_response :success
110
      assert_template 'entry'
111
      # this line was removed in r3
112 441:cbce1fd3b1b7 Chris
      assert_tag :tag => 'td',
113
                 :attributes => { :class => /line-code/},
114
                 :content => /before_filter/
115 0:513646585e45 Chris
    end
116 441:cbce1fd3b1b7 Chris
117 0:513646585e45 Chris
    def test_entry_not_found
118 210:0579821a129a Chris
      @repository.fetch_changesets
119
      @repository.reload
120
      get :entry, :id => PRJ_ID, :path => ['sources', 'zzz.c']
121 441:cbce1fd3b1b7 Chris
      assert_tag :tag => 'p',
122
                 :attributes => { :id => /errorExplanation/ },
123
                 :content => /The entry or revision was not found in the repository/
124 0:513646585e45 Chris
    end
125 441:cbce1fd3b1b7 Chris
126 0:513646585e45 Chris
    def test_entry_download
127 210:0579821a129a Chris
      @repository.fetch_changesets
128
      @repository.reload
129
      get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'], :format => 'raw'
130 0:513646585e45 Chris
      assert_response :success
131
    end
132
133
    def test_directory_entry
134 210:0579821a129a Chris
      @repository.fetch_changesets
135
      @repository.reload
136
      get :entry, :id => PRJ_ID, :path => ['sources']
137 0:513646585e45 Chris
      assert_response :success
138
      assert_template 'show'
139
      assert_not_nil assigns(:entry)
140
      assert_equal 'sources', assigns(:entry).name
141
    end
142 441:cbce1fd3b1b7 Chris
143 0:513646585e45 Chris
    def test_diff
144 210:0579821a129a Chris
      @repository.fetch_changesets
145
      @repository.reload
146
      get :diff, :id => PRJ_ID, :rev => 3, :type => 'inline'
147 0:513646585e45 Chris
      assert_response :success
148
      assert_template 'diff'
149
      assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_out' },
150 441:cbce1fd3b1b7 Chris
                               :content => /before_filter :require_login/
151 0:513646585e45 Chris
      assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_in' },
152 441:cbce1fd3b1b7 Chris
                               :content => /with one change/
153 0:513646585e45 Chris
    end
154 441:cbce1fd3b1b7 Chris
155 245:051f544170fe Chris
    def test_diff_new_files
156
      @repository.fetch_changesets
157
      @repository.reload
158
      get :diff, :id => PRJ_ID, :rev => 1, :type => 'inline'
159
      assert_response :success
160
      assert_template 'diff'
161
      assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_in' },
162
                               :content => /watched.remove_watcher/
163
      assert_tag :tag => 'th', :attributes => { :class => 'filename' },
164
                               :content => /test\/README/
165
      assert_tag :tag => 'th', :attributes => { :class => 'filename' },
166
                               :content => /test\/images\/delete.png        /
167
      assert_tag :tag => 'th', :attributes => { :class => 'filename' },
168
                               :content => /test\/images\/edit.png/
169
      assert_tag :tag => 'th', :attributes => { :class => 'filename' },
170 441:cbce1fd3b1b7 Chris
                               :content => /test\/sources\/watchers_controller.rb/
171 245:051f544170fe Chris
    end
172 0:513646585e45 Chris
173
    def test_annotate
174 210:0579821a129a Chris
      @repository.fetch_changesets
175
      @repository.reload
176
      get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
177 0:513646585e45 Chris
      assert_response :success
178
      assert_template 'annotate'
179
      # 1.1 line
180 441:cbce1fd3b1b7 Chris
      assert_tag :tag => 'th',
181
                 :attributes => { :class => 'line-num' },
182
                 :content => '18',
183
                 :sibling => {
184
                   :tag => 'td',
185
                   :attributes => { :class => 'revision' },
186
                   :content => /1.1/,
187
                   :sibling => {
188
                      :tag => 'td',
189
                      :attributes => { :class => 'author' },
190
                      :content => /LANG/
191
                        }
192
                   }
193 0:513646585e45 Chris
      # 1.2 line
194 441:cbce1fd3b1b7 Chris
      assert_tag :tag => 'th',
195
                 :attributes => { :class => 'line-num' },
196
                 :content => '32',
197
                 :sibling => {
198
                     :tag => 'td',
199
                     :attributes => { :class => 'revision' },
200
                     :content => /1.2/,
201
                     :sibling => {
202
                        :tag => 'td',
203
                        :attributes => { :class => 'author' },
204
                        :content => /LANG/
205
                        }
206
                   }
207 0:513646585e45 Chris
    end
208
  else
209
    puts "CVS test repository NOT FOUND. Skipping functional tests !!!"
210
    def test_fake; assert true end
211
  end
212
end