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 / 69 / 69aea32e67c1e43bf9542a209fc02cf6c1b5854c.svn-base @ 1297:0a574315af3e

History | View | Annotate | Download (6.61 KB)

1
# Redmine - project management software
2
# Copyright (C) 2006-2011  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
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 RepositoriesBazaarControllerTest < ActionController::TestCase
25
  fixtures :projects, :users, :roles, :members, :member_roles,
26
           :repositories, :enabled_modules
27

    
28
  REPOSITORY_PATH = Rails.root.join('tmp/test/bazaar_repository/trunk').to_s
29
  PRJ_ID = 3
30

    
31
  def setup
32
    @controller = RepositoriesController.new
33
    @request    = ActionController::TestRequest.new
34
    @response   = ActionController::TestResponse.new
35
    User.current = nil
36
    @project = Project.find(PRJ_ID)
37
    @repository = Repository::Bazaar.create(
38
                    :project      => @project,
39
                    :url          => REPOSITORY_PATH,
40
                    :log_encoding => 'UTF-8')
41
    assert @repository
42
  end
43

    
44
  if File.directory?(REPOSITORY_PATH)
45
    def test_browse_root
46
      get :show, :id => PRJ_ID
47
      assert_response :success
48
      assert_template 'show'
49
      assert_not_nil assigns(:entries)
50
      assert_equal 2, assigns(:entries).size
51
      assert assigns(:entries).detect {|e| e.name == 'directory' && e.kind == 'dir'}
52
      assert assigns(:entries).detect {|e| e.name == 'doc-mkdir.txt' && e.kind == 'file'}
53
    end
54

    
55
    def test_browse_directory
56
      get :show, :id => PRJ_ID, :path => ['directory']
57
      assert_response :success
58
      assert_template 'show'
59
      assert_not_nil assigns(:entries)
60
      assert_equal ['doc-ls.txt', 'document.txt', 'edit.png'], assigns(:entries).collect(&:name)
61
      entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
62
      assert_not_nil entry
63
      assert_equal 'file', entry.kind
64
      assert_equal 'directory/edit.png', entry.path
65
    end
66

    
67
    def test_browse_at_given_revision
68
      get :show, :id => PRJ_ID, :path => [], :rev => 3
69
      assert_response :success
70
      assert_template 'show'
71
      assert_not_nil assigns(:entries)
72
      assert_equal ['directory', 'doc-deleted.txt', 'doc-ls.txt', 'doc-mkdir.txt'],
73
                   assigns(:entries).collect(&:name)
74
    end
75

    
76
    def test_changes
77
      get :changes, :id => PRJ_ID, :path => ['doc-mkdir.txt']
78
      assert_response :success
79
      assert_template 'changes'
80
      assert_tag :tag => 'h2', :content => 'doc-mkdir.txt'
81
    end
82

    
83
    def test_entry_show
84
      get :entry, :id => PRJ_ID, :path => ['directory', 'doc-ls.txt']
85
      assert_response :success
86
      assert_template 'entry'
87
      # Line 19
88
      assert_tag :tag => 'th',
89
                 :content => /29/,
90
                 :attributes => { :class => /line-num/ },
91
                 :sibling => { :tag => 'td', :content => /Show help message/ }
92
    end
93

    
94
    def test_entry_download
95
      get :entry, :id => PRJ_ID, :path => ['directory', 'doc-ls.txt'], :format => 'raw'
96
      assert_response :success
97
      # File content
98
      assert @response.body.include?('Show help message')
99
    end
100

    
101
    def test_directory_entry
102
      get :entry, :id => PRJ_ID, :path => ['directory']
103
      assert_response :success
104
      assert_template 'show'
105
      assert_not_nil assigns(:entry)
106
      assert_equal 'directory', assigns(:entry).name
107
    end
108

    
109
    def test_diff
110
      # Full diff of changeset 3
111
      ['inline', 'sbs'].each do |dt|
112
        get :diff, :id => PRJ_ID, :rev => 3, :type => dt
113
        assert_response :success
114
        assert_template 'diff'
115
        # Line 11 removed
116
        assert_tag :tag => 'th',
117
                   :content => '11',
118
                   :sibling => { :tag => 'td',
119
                                 :attributes => { :class => /diff_out/ },
120
                                 :content => /Display more information/ }
121
      end
122
    end
123

    
124
    def test_annotate
125
      get :annotate, :id => PRJ_ID, :path => ['doc-mkdir.txt']
126
      assert_response :success
127
      assert_template 'annotate'
128
      assert_tag :tag => 'th', :content => '2',
129
                 :sibling => {
130
                    :tag => 'td',
131
                    :child => {
132
                       :tag => 'a',
133
                       :content => '3'
134
                       }
135
                    }
136
      assert_tag :tag => 'th', :content => '2',
137
                 :sibling => { :tag => 'td', :content => /jsmith/ }
138
      assert_tag :tag => 'th', :content => '2',
139
                 :sibling => {
140
                    :tag => 'td',
141
                    :child => {
142
                       :tag => 'a',
143
                       :content => '3'
144
                       }
145
                    }
146
      assert_tag :tag => 'th', :content => '2',
147
                 :sibling => { :tag => 'td', :content => /Main purpose/ }
148
    end
149

    
150
    def test_destroy_valid_repository
151
      @request.session[:user_id] = 1 # admin
152
      assert_equal 0, @repository.changesets.count
153
      @repository.fetch_changesets
154
      @project.reload
155
      assert @repository.changesets.count > 0
156

    
157
      get :destroy, :id => PRJ_ID
158
      assert_response 302
159
      @project.reload
160
      assert_nil @project.repository
161
    end
162

    
163
    def test_destroy_invalid_repository
164
      @request.session[:user_id] = 1 # admin
165
      assert_equal 0, @repository.changesets.count
166
      @repository.fetch_changesets
167
      @project.reload
168
      assert @repository.changesets.count > 0
169

    
170
      get :destroy, :id => PRJ_ID
171
      assert_response 302
172
      @project.reload
173
      assert_nil @project.repository
174

    
175
      @repository = Repository::Bazaar.create(
176
                    :project      => @project,
177
                    :url          => "/invalid",
178
                    :log_encoding => 'UTF-8')
179
      assert @repository
180
      @repository.fetch_changesets
181
      @repository.reload
182
      assert_equal 0, @repository.changesets.count
183

    
184
      get :destroy, :id => PRJ_ID
185
      assert_response 302
186
      @project.reload
187
      assert_nil @project.repository
188
    end
189
  else
190
    puts "Bazaar test repository NOT FOUND. Skipping functional tests !!!"
191
    def test_fake; assert true end
192
  end
193
end