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 / .svn / pristine / 18 / 18aaa55b2d77150962ade434e4a8c39b73c97814.svn-base @ 1298:4f746d8966dd

History | View | Annotate | Download (5.96 KB)

1 1295:622f24f53b42 Chris
# Redmine - project management software
2
# Copyright (C) 2006-2013  Jean-Philippe Lang
3
#
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
#
9
# 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
#
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
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17
18
require File.expand_path('../../test_helper', __FILE__)
19
20
class RepositoriesFilesystemControllerTest < ActionController::TestCase
21
  tests RepositoriesController
22
23
  fixtures :projects, :users, :roles, :members, :member_roles,
24
           :repositories, :enabled_modules
25
26
  REPOSITORY_PATH = Rails.root.join('tmp/test/filesystem_repository').to_s
27
  PRJ_ID = 3
28
29
  def setup
30
    @ruby19_non_utf8_pass =
31
        (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
32
    User.current = nil
33
    Setting.enabled_scm << 'Filesystem' unless Setting.enabled_scm.include?('Filesystem')
34
    @project = Project.find(PRJ_ID)
35
    @repository = Repository::Filesystem.create(
36
                      :project       => @project,
37
                      :url           => REPOSITORY_PATH,
38
                      :path_encoding => ''
39
                      )
40
    assert @repository
41
  end
42
43
  if File.directory?(REPOSITORY_PATH)
44
    def test_get_new
45
      @request.session[:user_id] = 1
46
      @project.repository.destroy
47
      get :new, :project_id => 'subproject1', :repository_scm => 'Filesystem'
48
      assert_response :success
49
      assert_template 'new'
50
      assert_kind_of Repository::Filesystem, assigns(:repository)
51
      assert assigns(:repository).new_record?
52
    end
53
54
    def test_browse_root
55
      @repository.fetch_changesets
56
      @repository.reload
57
      get :show, :id => PRJ_ID
58
      assert_response :success
59
      assert_template 'show'
60
      assert_not_nil assigns(:entries)
61
      assert assigns(:entries).size > 0
62
      assert_not_nil assigns(:changesets)
63
      assert assigns(:changesets).size == 0
64
65
      assert_no_tag 'input', :attributes => {:name => 'rev'}
66
      assert_no_tag 'a', :content => 'Statistics'
67
      assert_no_tag 'a', :content => 'Atom'
68
    end
69
70
    def test_show_no_extension
71
      get :entry, :id => PRJ_ID, :path => repository_path_hash(['test'])[:param]
72
      assert_response :success
73
      assert_template 'entry'
74
      assert_tag :tag => 'th',
75
                 :content => '1',
76
                 :attributes => { :class => 'line-num' },
77
                 :sibling => { :tag => 'td', :content => /TEST CAT/ }
78
    end
79
80
    def test_entry_download_no_extension
81
      get :raw, :id => PRJ_ID, :path => repository_path_hash(['test'])[:param]
82
      assert_response :success
83
      assert_equal 'application/octet-stream', @response.content_type
84
    end
85
86
    def test_show_non_ascii_contents
87
      with_settings :repositories_encodings => 'UTF-8,EUC-JP' do
88
        get :entry, :id => PRJ_ID,
89
            :path => repository_path_hash(['japanese', 'euc-jp.txt'])[:param]
90
        assert_response :success
91
        assert_template 'entry'
92
        assert_tag :tag => 'th',
93
                   :content => '2',
94
                   :attributes => { :class => 'line-num' },
95
                   :sibling => { :tag => 'td', :content => /japanese/ }
96
        if @ruby19_non_utf8_pass
97
          puts "TODO: show repository file contents test fails in Ruby 1.9 " +
98
               "and Encoding.default_external is not UTF-8. " +
99
               "Current value is '#{Encoding.default_external.to_s}'"
100
        else
101
          str_japanese = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e"
102
          str_japanese.force_encoding('UTF-8') if str_japanese.respond_to?(:force_encoding)
103
          assert_tag :tag => 'th',
104
                     :content => '3',
105
                     :attributes => { :class => 'line-num' },
106
                     :sibling => { :tag => 'td', :content => /#{str_japanese}/ }
107
        end
108
      end
109
    end
110
111
    def test_show_utf16
112
      enc = (RUBY_VERSION == "1.9.2" ? 'UTF-16LE' : 'UTF-16')
113
      with_settings :repositories_encodings => enc do
114
        get :entry, :id => PRJ_ID,
115
            :path => repository_path_hash(['japanese', 'utf-16.txt'])[:param]
116
        assert_response :success
117
        assert_tag :tag => 'th',
118
                   :content => '2',
119
                   :attributes => { :class => 'line-num' },
120
                   :sibling => { :tag => 'td', :content => /japanese/ }
121
      end
122
    end
123
124
    def test_show_text_file_should_send_if_too_big
125
      with_settings :file_max_size_displayed => 1 do
126
        get :entry, :id => PRJ_ID,
127
            :path => repository_path_hash(['japanese', 'big-file.txt'])[:param]
128
        assert_response :success
129
        assert_equal 'text/plain', @response.content_type
130
      end
131
    end
132
133
    def test_destroy_valid_repository
134
      @request.session[:user_id] = 1 # admin
135
136
      assert_difference 'Repository.count', -1 do
137
        delete :destroy, :id => @repository.id
138
      end
139
      assert_response 302
140
      @project.reload
141
      assert_nil @project.repository
142
    end
143
144
    def test_destroy_invalid_repository
145
      @request.session[:user_id] = 1 # admin
146
      @project.repository.destroy
147
      @repository = Repository::Filesystem.create!(
148
                      :project       => @project,
149
                      :url           => "/invalid",
150
                      :path_encoding => ''
151
                      )
152
153
      assert_difference 'Repository.count', -1 do
154
        delete :destroy, :id => @repository.id
155
      end
156
      assert_response 302
157
      @project.reload
158
      assert_nil @project.repository
159
    end
160
  else
161
    puts "Filesystem test repository NOT FOUND. Skipping functional tests !!!"
162
    def test_fake; assert true end
163
  end
164
end