annotate .svn/pristine/5b/5b4d21bca26fd3fe16dbb733fe9dd17bcabdb041.svn-base @ 1298:4f746d8966dd redmine_2.3_integration

Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author Chris Cannam
date Fri, 14 Jun 2013 09:28:30 +0100
parents 622f24f53b42
children
rev   line source
Chris@1295 1 # Redmine - project management software
Chris@1295 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
Chris@1295 3 #
Chris@1295 4 # This program is free software; you can redistribute it and/or
Chris@1295 5 # modify it under the terms of the GNU General Public License
Chris@1295 6 # as published by the Free Software Foundation; either version 2
Chris@1295 7 # of the License, or (at your option) any later version.
Chris@1295 8 #
Chris@1295 9 # This program is distributed in the hope that it will be useful,
Chris@1295 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1295 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1295 12 # GNU General Public License for more details.
Chris@1295 13 #
Chris@1295 14 # You should have received a copy of the GNU General Public License
Chris@1295 15 # along with this program; if not, write to the Free Software
Chris@1295 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1295 17
Chris@1295 18 require File.expand_path('../../test_helper', __FILE__)
Chris@1295 19 require 'repositories_controller'
Chris@1295 20
Chris@1295 21 # Re-raise errors caught by the controller.
Chris@1295 22 class RepositoriesController; def rescue_action(e) raise e end; end
Chris@1295 23
Chris@1295 24 class RepositoriesControllerTest < ActionController::TestCase
Chris@1295 25 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules,
Chris@1295 26 :repositories, :issues, :issue_statuses, :changesets, :changes,
Chris@1295 27 :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers
Chris@1295 28
Chris@1295 29 def setup
Chris@1295 30 @controller = RepositoriesController.new
Chris@1295 31 @request = ActionController::TestRequest.new
Chris@1295 32 @response = ActionController::TestResponse.new
Chris@1295 33 User.current = nil
Chris@1295 34 end
Chris@1295 35
Chris@1295 36 def test_new
Chris@1295 37 @request.session[:user_id] = 1
Chris@1295 38 get :new, :project_id => 'subproject1'
Chris@1295 39 assert_response :success
Chris@1295 40 assert_template 'new'
Chris@1295 41 assert_kind_of Repository::Subversion, assigns(:repository)
Chris@1295 42 assert assigns(:repository).new_record?
Chris@1295 43 assert_tag 'input', :attributes => {:name => 'repository[url]', :disabled => nil}
Chris@1295 44 end
Chris@1295 45
Chris@1295 46 def test_new_should_propose_enabled_scm_only
Chris@1295 47 @request.session[:user_id] = 1
Chris@1295 48 with_settings :enabled_scm => ['Mercurial', 'Git'] do
Chris@1295 49 get :new, :project_id => 'subproject1'
Chris@1295 50 end
Chris@1295 51 assert_response :success
Chris@1295 52 assert_template 'new'
Chris@1295 53 assert_kind_of Repository::Mercurial, assigns(:repository)
Chris@1295 54 assert_tag 'select', :attributes => {:name => 'repository_scm'},
Chris@1295 55 :children => {:count => 3}
Chris@1295 56 assert_tag 'select', :attributes => {:name => 'repository_scm'},
Chris@1295 57 :child => {:tag => 'option', :attributes => {:value => 'Mercurial', :selected => 'selected'}}
Chris@1295 58 assert_tag 'select', :attributes => {:name => 'repository_scm'},
Chris@1295 59 :child => {:tag => 'option', :attributes => {:value => 'Git', :selected => nil}}
Chris@1295 60 end
Chris@1295 61
Chris@1295 62 def test_create
Chris@1295 63 @request.session[:user_id] = 1
Chris@1295 64 assert_difference 'Repository.count' do
Chris@1295 65 post :create, :project_id => 'subproject1',
Chris@1295 66 :repository_scm => 'Subversion',
Chris@1295 67 :repository => {:url => 'file:///test', :is_default => '1', :identifier => ''}
Chris@1295 68 end
Chris@1295 69 assert_response 302
Chris@1295 70 repository = Repository.first(:order => 'id DESC')
Chris@1295 71 assert_kind_of Repository::Subversion, repository
Chris@1295 72 assert_equal 'file:///test', repository.url
Chris@1295 73 end
Chris@1295 74
Chris@1295 75 def test_create_with_failure
Chris@1295 76 @request.session[:user_id] = 1
Chris@1295 77 assert_no_difference 'Repository.count' do
Chris@1295 78 post :create, :project_id => 'subproject1',
Chris@1295 79 :repository_scm => 'Subversion',
Chris@1295 80 :repository => {:url => 'invalid'}
Chris@1295 81 end
Chris@1295 82 assert_response :success
Chris@1295 83 assert_template 'new'
Chris@1295 84 assert_kind_of Repository::Subversion, assigns(:repository)
Chris@1295 85 assert assigns(:repository).new_record?
Chris@1295 86 end
Chris@1295 87
Chris@1295 88 def test_edit
Chris@1295 89 @request.session[:user_id] = 1
Chris@1295 90 get :edit, :id => 11
Chris@1295 91 assert_response :success
Chris@1295 92 assert_template 'edit'
Chris@1295 93 assert_equal Repository.find(11), assigns(:repository)
Chris@1295 94 assert_tag 'input', :attributes => {:name => 'repository[url]', :value => 'svn://localhost/test', :disabled => 'disabled'}
Chris@1295 95 end
Chris@1295 96
Chris@1295 97 def test_update
Chris@1295 98 @request.session[:user_id] = 1
Chris@1295 99 put :update, :id => 11, :repository => {:password => 'test_update'}
Chris@1295 100 assert_response 302
Chris@1295 101 assert_equal 'test_update', Repository.find(11).password
Chris@1295 102 end
Chris@1295 103
Chris@1295 104 def test_update_with_failure
Chris@1295 105 @request.session[:user_id] = 1
Chris@1295 106 put :update, :id => 11, :repository => {:password => 'x'*260}
Chris@1295 107 assert_response :success
Chris@1295 108 assert_template 'edit'
Chris@1295 109 assert_equal Repository.find(11), assigns(:repository)
Chris@1295 110 end
Chris@1295 111
Chris@1295 112 def test_destroy
Chris@1295 113 @request.session[:user_id] = 1
Chris@1295 114 assert_difference 'Repository.count', -1 do
Chris@1295 115 delete :destroy, :id => 11
Chris@1295 116 end
Chris@1295 117 assert_response 302
Chris@1295 118 assert_nil Repository.find_by_id(11)
Chris@1295 119 end
Chris@1295 120
Chris@1295 121 def test_revisions
Chris@1295 122 get :revisions, :id => 1
Chris@1295 123 assert_response :success
Chris@1295 124 assert_template 'revisions'
Chris@1295 125 assert_equal Repository.find(10), assigns(:repository)
Chris@1295 126 assert_not_nil assigns(:changesets)
Chris@1295 127 end
Chris@1295 128
Chris@1295 129 def test_revisions_for_other_repository
Chris@1295 130 repository = Repository::Subversion.create!(:project_id => 1, :identifier => 'foo', :url => 'file:///foo')
Chris@1295 131
Chris@1295 132 get :revisions, :id => 1, :repository_id => 'foo'
Chris@1295 133 assert_response :success
Chris@1295 134 assert_template 'revisions'
Chris@1295 135 assert_equal repository, assigns(:repository)
Chris@1295 136 assert_not_nil assigns(:changesets)
Chris@1295 137 end
Chris@1295 138
Chris@1295 139 def test_revisions_for_invalid_repository
Chris@1295 140 get :revisions, :id => 1, :repository_id => 'foo'
Chris@1295 141 assert_response 404
Chris@1295 142 end
Chris@1295 143
Chris@1295 144 def test_revision
Chris@1295 145 get :revision, :id => 1, :rev => 1
Chris@1295 146 assert_response :success
Chris@1295 147 assert_not_nil assigns(:changeset)
Chris@1295 148 assert_equal "1", assigns(:changeset).revision
Chris@1295 149 end
Chris@1295 150
Chris@1295 151 def test_revision_should_not_change_the_project_menu_link
Chris@1295 152 get :revision, :id => 1, :rev => 1
Chris@1295 153 assert_response :success
Chris@1295 154
Chris@1295 155 assert_tag 'a', :attributes => {:href => '/projects/ecookbook/repository', :class => /repository/},
Chris@1295 156 :ancestor => {:attributes => {:id => 'main-menu'}}
Chris@1295 157 end
Chris@1295 158
Chris@1295 159 def test_revision_with_before_nil_and_afer_normal
Chris@1295 160 get :revision, {:id => 1, :rev => 1}
Chris@1295 161 assert_response :success
Chris@1295 162 assert_template 'revision'
Chris@1295 163 assert_no_tag :tag => "div", :attributes => { :class => "contextual" },
Chris@1295 164 :child => { :tag => "a", :attributes => { :href => '/projects/ecookbook/repository/revisions/0'}
Chris@1295 165 }
Chris@1295 166 assert_tag :tag => "div", :attributes => { :class => "contextual" },
Chris@1295 167 :child => { :tag => "a", :attributes => { :href => '/projects/ecookbook/repository/revisions/2'}
Chris@1295 168 }
Chris@1295 169 end
Chris@1295 170
Chris@1295 171 def test_add_related_issue
Chris@1295 172 @request.session[:user_id] = 2
Chris@1295 173 assert_difference 'Changeset.find(103).issues.size' do
Chris@1295 174 xhr :post, :add_related_issue, :id => 1, :rev => 4, :issue_id => 2, :format => 'js'
Chris@1295 175 assert_response :success
Chris@1295 176 assert_template 'add_related_issue'
Chris@1295 177 assert_equal 'text/javascript', response.content_type
Chris@1295 178 end
Chris@1295 179 assert_equal [2], Changeset.find(103).issue_ids
Chris@1295 180 assert_include 'related-issues', response.body
Chris@1295 181 assert_include 'Feature request #2', response.body
Chris@1295 182 end
Chris@1295 183
Chris@1295 184 def test_add_related_issue_with_invalid_issue_id
Chris@1295 185 @request.session[:user_id] = 2
Chris@1295 186 assert_no_difference 'Changeset.find(103).issues.size' do
Chris@1295 187 xhr :post, :add_related_issue, :id => 1, :rev => 4, :issue_id => 9999, :format => 'js'
Chris@1295 188 assert_response :success
Chris@1295 189 assert_template 'add_related_issue'
Chris@1295 190 assert_equal 'text/javascript', response.content_type
Chris@1295 191 end
Chris@1295 192 assert_include 'alert("Issue is invalid")', response.body
Chris@1295 193 end
Chris@1295 194
Chris@1295 195 def test_remove_related_issue
Chris@1295 196 Changeset.find(103).issues << Issue.find(1)
Chris@1295 197 Changeset.find(103).issues << Issue.find(2)
Chris@1295 198
Chris@1295 199 @request.session[:user_id] = 2
Chris@1295 200 assert_difference 'Changeset.find(103).issues.size', -1 do
Chris@1295 201 xhr :delete, :remove_related_issue, :id => 1, :rev => 4, :issue_id => 2, :format => 'js'
Chris@1295 202 assert_response :success
Chris@1295 203 assert_template 'remove_related_issue'
Chris@1295 204 assert_equal 'text/javascript', response.content_type
Chris@1295 205 end
Chris@1295 206 assert_equal [1], Changeset.find(103).issue_ids
Chris@1295 207 assert_include 'related-issue-2', response.body
Chris@1295 208 end
Chris@1295 209
Chris@1295 210 def test_graph_commits_per_month
Chris@1295 211 # Make sure there's some data to display
Chris@1295 212 latest = Project.find(1).repository.changesets.maximum(:commit_date)
Chris@1295 213 assert_not_nil latest
Chris@1295 214 Date.stubs(:today).returns(latest.to_date + 10)
Chris@1295 215
Chris@1295 216 get :graph, :id => 1, :graph => 'commits_per_month'
Chris@1295 217 assert_response :success
Chris@1295 218 assert_equal 'image/svg+xml', @response.content_type
Chris@1295 219 end
Chris@1295 220
Chris@1295 221 def test_graph_commits_per_author
Chris@1295 222 get :graph, :id => 1, :graph => 'commits_per_author'
Chris@1295 223 assert_response :success
Chris@1295 224 assert_equal 'image/svg+xml', @response.content_type
Chris@1295 225 end
Chris@1295 226
Chris@1295 227 def test_get_committers
Chris@1295 228 @request.session[:user_id] = 2
Chris@1295 229 # add a commit with an unknown user
Chris@1295 230 Changeset.create!(
Chris@1295 231 :repository => Project.find(1).repository,
Chris@1295 232 :committer => 'foo',
Chris@1295 233 :committed_on => Time.now,
Chris@1295 234 :revision => 100,
Chris@1295 235 :comments => 'Committed by foo.'
Chris@1295 236 )
Chris@1295 237
Chris@1295 238 get :committers, :id => 10
Chris@1295 239 assert_response :success
Chris@1295 240 assert_template 'committers'
Chris@1295 241
Chris@1295 242 assert_tag :td, :content => 'dlopper',
Chris@1295 243 :sibling => { :tag => 'td',
Chris@1295 244 :child => { :tag => 'select', :attributes => { :name => %r{^committers\[\d+\]\[\]$} },
Chris@1295 245 :child => { :tag => 'option', :content => 'Dave Lopper',
Chris@1295 246 :attributes => { :value => '3', :selected => 'selected' }}}}
Chris@1295 247 assert_tag :td, :content => 'foo',
Chris@1295 248 :sibling => { :tag => 'td',
Chris@1295 249 :child => { :tag => 'select', :attributes => { :name => %r{^committers\[\d+\]\[\]$} }}}
Chris@1295 250 assert_no_tag :td, :content => 'foo',
Chris@1295 251 :sibling => { :tag => 'td',
Chris@1295 252 :descendant => { :tag => 'option', :attributes => { :selected => 'selected' }}}
Chris@1295 253 end
Chris@1295 254
Chris@1295 255 def test_post_committers
Chris@1295 256 @request.session[:user_id] = 2
Chris@1295 257 # add a commit with an unknown user
Chris@1295 258 c = Changeset.create!(
Chris@1295 259 :repository => Project.find(1).repository,
Chris@1295 260 :committer => 'foo',
Chris@1295 261 :committed_on => Time.now,
Chris@1295 262 :revision => 100,
Chris@1295 263 :comments => 'Committed by foo.'
Chris@1295 264 )
Chris@1295 265 assert_no_difference "Changeset.count(:conditions => 'user_id = 3')" do
Chris@1295 266 post :committers, :id => 10, :committers => { '0' => ['foo', '2'], '1' => ['dlopper', '3']}
Chris@1295 267 assert_response 302
Chris@1295 268 assert_equal User.find(2), c.reload.user
Chris@1295 269 end
Chris@1295 270 end
Chris@1295 271 end