To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / .svn / pristine / 07 / 07402976102eaabe37c42cc6aab7aeb00d221891.svn-base @ 912:5e80956cc792
History | View | Annotate | Download (5.74 KB)
| 1 | 909:cbb26bc654de | Chris | # 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 RepositoriesDarcsControllerTest < ActionController::TestCase |
||
| 25 | fixtures :projects, :users, :roles, :members, :member_roles, |
||
| 26 | :repositories, :enabled_modules |
||
| 27 | |||
| 28 | REPOSITORY_PATH = Rails.root.join('tmp/test/darcs_repository').to_s
|
||
| 29 | PRJ_ID = 3 |
||
| 30 | NUM_REV = 6 |
||
| 31 | |||
| 32 | def setup |
||
| 33 | @controller = RepositoriesController.new |
||
| 34 | @request = ActionController::TestRequest.new |
||
| 35 | @response = ActionController::TestResponse.new |
||
| 36 | User.current = nil |
||
| 37 | @project = Project.find(PRJ_ID) |
||
| 38 | @repository = Repository::Darcs.create( |
||
| 39 | :project => @project, |
||
| 40 | :url => REPOSITORY_PATH, |
||
| 41 | :log_encoding => 'UTF-8' |
||
| 42 | ) |
||
| 43 | assert @repository |
||
| 44 | end |
||
| 45 | |||
| 46 | if File.directory?(REPOSITORY_PATH) |
||
| 47 | def test_browse_root |
||
| 48 | assert_equal 0, @repository.changesets.count |
||
| 49 | @repository.fetch_changesets |
||
| 50 | @project.reload |
||
| 51 | assert_equal NUM_REV, @repository.changesets.count |
||
| 52 | get :show, :id => PRJ_ID |
||
| 53 | assert_response :success |
||
| 54 | assert_template 'show' |
||
| 55 | assert_not_nil assigns(:entries) |
||
| 56 | assert_equal 3, assigns(:entries).size |
||
| 57 | assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
|
||
| 58 | assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
|
||
| 59 | assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
|
||
| 60 | end |
||
| 61 | |||
| 62 | def test_browse_directory |
||
| 63 | assert_equal 0, @repository.changesets.count |
||
| 64 | @repository.fetch_changesets |
||
| 65 | @project.reload |
||
| 66 | assert_equal NUM_REV, @repository.changesets.count |
||
| 67 | get :show, :id => PRJ_ID, :path => ['images'] |
||
| 68 | assert_response :success |
||
| 69 | assert_template 'show' |
||
| 70 | assert_not_nil assigns(:entries) |
||
| 71 | assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name) |
||
| 72 | entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
|
||
| 73 | assert_not_nil entry |
||
| 74 | assert_equal 'file', entry.kind |
||
| 75 | assert_equal 'images/edit.png', entry.path |
||
| 76 | end |
||
| 77 | |||
| 78 | def test_browse_at_given_revision |
||
| 79 | assert_equal 0, @repository.changesets.count |
||
| 80 | @repository.fetch_changesets |
||
| 81 | @project.reload |
||
| 82 | assert_equal NUM_REV, @repository.changesets.count |
||
| 83 | get :show, :id => PRJ_ID, :path => ['images'], :rev => 1 |
||
| 84 | assert_response :success |
||
| 85 | assert_template 'show' |
||
| 86 | assert_not_nil assigns(:entries) |
||
| 87 | assert_equal ['delete.png'], assigns(:entries).collect(&:name) |
||
| 88 | end |
||
| 89 | |||
| 90 | def test_changes |
||
| 91 | assert_equal 0, @repository.changesets.count |
||
| 92 | @repository.fetch_changesets |
||
| 93 | @project.reload |
||
| 94 | assert_equal NUM_REV, @repository.changesets.count |
||
| 95 | get :changes, :id => PRJ_ID, :path => ['images', 'edit.png'] |
||
| 96 | assert_response :success |
||
| 97 | assert_template 'changes' |
||
| 98 | assert_tag :tag => 'h2', :content => 'edit.png' |
||
| 99 | end |
||
| 100 | |||
| 101 | def test_diff |
||
| 102 | assert_equal 0, @repository.changesets.count |
||
| 103 | @repository.fetch_changesets |
||
| 104 | @project.reload |
||
| 105 | assert_equal NUM_REV, @repository.changesets.count |
||
| 106 | # Full diff of changeset 5 |
||
| 107 | ['inline', 'sbs'].each do |dt| |
||
| 108 | get :diff, :id => PRJ_ID, :rev => 5, :type => dt |
||
| 109 | assert_response :success |
||
| 110 | assert_template 'diff' |
||
| 111 | # Line 22 removed |
||
| 112 | assert_tag :tag => 'th', |
||
| 113 | :content => '22', |
||
| 114 | :sibling => { :tag => 'td',
|
||
| 115 | :attributes => { :class => /diff_out/ },
|
||
| 116 | :content => /def remove/ } |
||
| 117 | end |
||
| 118 | end |
||
| 119 | |||
| 120 | def test_destroy_valid_repository |
||
| 121 | @request.session[:user_id] = 1 # admin |
||
| 122 | assert_equal 0, @repository.changesets.count |
||
| 123 | @repository.fetch_changesets |
||
| 124 | @project.reload |
||
| 125 | assert_equal NUM_REV, @repository.changesets.count |
||
| 126 | |||
| 127 | get :destroy, :id => PRJ_ID |
||
| 128 | assert_response 302 |
||
| 129 | @project.reload |
||
| 130 | assert_nil @project.repository |
||
| 131 | end |
||
| 132 | |||
| 133 | def test_destroy_invalid_repository |
||
| 134 | @request.session[:user_id] = 1 # admin |
||
| 135 | assert_equal 0, @repository.changesets.count |
||
| 136 | @repository.fetch_changesets |
||
| 137 | @project.reload |
||
| 138 | assert_equal NUM_REV, @repository.changesets.count |
||
| 139 | |||
| 140 | get :destroy, :id => PRJ_ID |
||
| 141 | assert_response 302 |
||
| 142 | @project.reload |
||
| 143 | assert_nil @project.repository |
||
| 144 | |||
| 145 | @repository = Repository::Darcs.create( |
||
| 146 | :project => @project, |
||
| 147 | :url => "/invalid", |
||
| 148 | :log_encoding => 'UTF-8' |
||
| 149 | ) |
||
| 150 | assert @repository |
||
| 151 | @repository.fetch_changesets |
||
| 152 | @project.reload |
||
| 153 | assert_equal 0, @repository.changesets.count |
||
| 154 | |||
| 155 | get :destroy, :id => PRJ_ID |
||
| 156 | assert_response 302 |
||
| 157 | @project.reload |
||
| 158 | assert_nil @project.repository |
||
| 159 | end |
||
| 160 | else |
||
| 161 | puts "Darcs test repository NOT FOUND. Skipping functional tests !!!" |
||
| 162 | def test_fake; assert true end |
||
| 163 | end |
||
| 164 | end |