annotate .svn/pristine/7d/7d3ac76c84dee77bab1ef37f05ae263ad699e2b8.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-2013 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
Chris@1295 20 class RepositoriesControllerTest < ActionController::TestCase
Chris@1295 21 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules,
Chris@1295 22 :repositories, :issues, :issue_statuses, :changesets, :changes,
Chris@1295 23 :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers
Chris@1295 24
Chris@1295 25 def setup
Chris@1295 26 User.current = nil
Chris@1295 27 end
Chris@1295 28
Chris@1295 29 def test_new
Chris@1295 30 @request.session[:user_id] = 1
Chris@1295 31 get :new, :project_id => 'subproject1'
Chris@1295 32 assert_response :success
Chris@1295 33 assert_template 'new'
Chris@1295 34 assert_kind_of Repository::Subversion, assigns(:repository)
Chris@1295 35 assert assigns(:repository).new_record?
Chris@1295 36 assert_tag 'input', :attributes => {:name => 'repository[url]', :disabled => nil}
Chris@1295 37 end
Chris@1295 38
Chris@1295 39 def test_new_should_propose_enabled_scm_only
Chris@1295 40 @request.session[:user_id] = 1
Chris@1295 41 with_settings :enabled_scm => ['Mercurial', 'Git'] do
Chris@1295 42 get :new, :project_id => 'subproject1'
Chris@1295 43 end
Chris@1295 44 assert_response :success
Chris@1295 45 assert_template 'new'
Chris@1295 46 assert_kind_of Repository::Mercurial, assigns(:repository)
Chris@1295 47 assert_tag 'select', :attributes => {:name => 'repository_scm'},
Chris@1295 48 :children => {:count => 3}
Chris@1295 49 assert_tag 'select', :attributes => {:name => 'repository_scm'},
Chris@1295 50 :child => {:tag => 'option', :attributes => {:value => 'Mercurial', :selected => 'selected'}}
Chris@1295 51 assert_tag 'select', :attributes => {:name => 'repository_scm'},
Chris@1295 52 :child => {:tag => 'option', :attributes => {:value => 'Git', :selected => nil}}
Chris@1295 53 end
Chris@1295 54
Chris@1295 55 def test_create
Chris@1295 56 @request.session[:user_id] = 1
Chris@1295 57 assert_difference 'Repository.count' do
Chris@1295 58 post :create, :project_id => 'subproject1',
Chris@1295 59 :repository_scm => 'Subversion',
Chris@1295 60 :repository => {:url => 'file:///test', :is_default => '1', :identifier => ''}
Chris@1295 61 end
Chris@1295 62 assert_response 302
Chris@1295 63 repository = Repository.first(:order => 'id DESC')
Chris@1295 64 assert_kind_of Repository::Subversion, repository
Chris@1295 65 assert_equal 'file:///test', repository.url
Chris@1295 66 end
Chris@1295 67
Chris@1295 68 def test_create_with_failure
Chris@1295 69 @request.session[:user_id] = 1
Chris@1295 70 assert_no_difference 'Repository.count' do
Chris@1295 71 post :create, :project_id => 'subproject1',
Chris@1295 72 :repository_scm => 'Subversion',
Chris@1295 73 :repository => {:url => 'invalid'}
Chris@1295 74 end
Chris@1295 75 assert_response :success
Chris@1295 76 assert_template 'new'
Chris@1295 77 assert_kind_of Repository::Subversion, assigns(:repository)
Chris@1295 78 assert assigns(:repository).new_record?
Chris@1295 79 end
Chris@1295 80
Chris@1295 81 def test_edit
Chris@1295 82 @request.session[:user_id] = 1
Chris@1295 83 get :edit, :id => 11
Chris@1295 84 assert_response :success
Chris@1295 85 assert_template 'edit'
Chris@1295 86 assert_equal Repository.find(11), assigns(:repository)
Chris@1295 87 assert_tag 'input', :attributes => {:name => 'repository[url]', :value => 'svn://localhost/test', :disabled => 'disabled'}
Chris@1295 88 end
Chris@1295 89
Chris@1295 90 def test_update
Chris@1295 91 @request.session[:user_id] = 1
Chris@1295 92 put :update, :id => 11, :repository => {:password => 'test_update'}
Chris@1295 93 assert_response 302
Chris@1295 94 assert_equal 'test_update', Repository.find(11).password
Chris@1295 95 end
Chris@1295 96
Chris@1295 97 def test_update_with_failure
Chris@1295 98 @request.session[:user_id] = 1
Chris@1295 99 put :update, :id => 11, :repository => {:password => 'x'*260}
Chris@1295 100 assert_response :success
Chris@1295 101 assert_template 'edit'
Chris@1295 102 assert_equal Repository.find(11), assigns(:repository)
Chris@1295 103 end
Chris@1295 104
Chris@1295 105 def test_destroy
Chris@1295 106 @request.session[:user_id] = 1
Chris@1295 107 assert_difference 'Repository.count', -1 do
Chris@1295 108 delete :destroy, :id => 11
Chris@1295 109 end
Chris@1295 110 assert_response 302
Chris@1295 111 assert_nil Repository.find_by_id(11)
Chris@1295 112 end
Chris@1295 113
Chris@1295 114 def test_revisions
Chris@1295 115 get :revisions, :id => 1
Chris@1295 116 assert_response :success
Chris@1295 117 assert_template 'revisions'
Chris@1295 118 assert_equal Repository.find(10), assigns(:repository)
Chris@1295 119 assert_not_nil assigns(:changesets)
Chris@1295 120 end
Chris@1295 121
Chris@1295 122 def test_revisions_for_other_repository
Chris@1295 123 repository = Repository::Subversion.create!(:project_id => 1, :identifier => 'foo', :url => 'file:///foo')
Chris@1295 124
Chris@1295 125 get :revisions, :id => 1, :repository_id => 'foo'
Chris@1295 126 assert_response :success
Chris@1295 127 assert_template 'revisions'
Chris@1295 128 assert_equal repository, assigns(:repository)
Chris@1295 129 assert_not_nil assigns(:changesets)
Chris@1295 130 end
Chris@1295 131
Chris@1295 132 def test_revisions_for_invalid_repository
Chris@1295 133 get :revisions, :id => 1, :repository_id => 'foo'
Chris@1295 134 assert_response 404
Chris@1295 135 end
Chris@1295 136
Chris@1295 137 def test_revision
Chris@1295 138 get :revision, :id => 1, :rev => 1
Chris@1295 139 assert_response :success
Chris@1295 140 assert_not_nil assigns(:changeset)
Chris@1295 141 assert_equal "1", assigns(:changeset).revision
Chris@1295 142 end
Chris@1295 143
Chris@1295 144 def test_revision_should_not_change_the_project_menu_link
Chris@1295 145 get :revision, :id => 1, :rev => 1
Chris@1295 146 assert_response :success
Chris@1295 147
Chris@1295 148 assert_tag 'a', :attributes => {:href => '/projects/ecookbook/repository', :class => /repository/},
Chris@1295 149 :ancestor => {:attributes => {:id => 'main-menu'}}
Chris@1295 150 end
Chris@1295 151
Chris@1295 152 def test_revision_with_before_nil_and_afer_normal
Chris@1295 153 get :revision, {:id => 1, :rev => 1}
Chris@1295 154 assert_response :success
Chris@1295 155 assert_template 'revision'
Chris@1295 156 assert_no_tag :tag => "div", :attributes => { :class => "contextual" },
Chris@1295 157 :child => { :tag => "a", :attributes => { :href => '/projects/ecookbook/repository/revisions/0'}
Chris@1295 158 }
Chris@1295 159 assert_tag :tag => "div", :attributes => { :class => "contextual" },
Chris@1295 160 :child => { :tag => "a", :attributes => { :href => '/projects/ecookbook/repository/revisions/2'}
Chris@1295 161 }
Chris@1295 162 end
Chris@1295 163
Chris@1295 164 def test_add_related_issue
Chris@1295 165 @request.session[:user_id] = 2
Chris@1295 166 assert_difference 'Changeset.find(103).issues.size' do
Chris@1295 167 xhr :post, :add_related_issue, :id => 1, :rev => 4, :issue_id => 2, :format => 'js'
Chris@1295 168 assert_response :success
Chris@1295 169 assert_template 'add_related_issue'
Chris@1295 170 assert_equal 'text/javascript', response.content_type
Chris@1295 171 end
Chris@1295 172 assert_equal [2], Changeset.find(103).issue_ids
Chris@1295 173 assert_include 'related-issues', response.body
Chris@1295 174 assert_include 'Feature request #2', response.body
Chris@1295 175 end
Chris@1295 176
Chris@1295 177 def test_add_related_issue_with_invalid_issue_id
Chris@1295 178 @request.session[:user_id] = 2
Chris@1295 179 assert_no_difference 'Changeset.find(103).issues.size' do
Chris@1295 180 xhr :post, :add_related_issue, :id => 1, :rev => 4, :issue_id => 9999, :format => 'js'
Chris@1295 181 assert_response :success
Chris@1295 182 assert_template 'add_related_issue'
Chris@1295 183 assert_equal 'text/javascript', response.content_type
Chris@1295 184 end
Chris@1295 185 assert_include 'alert("Issue is invalid")', response.body
Chris@1295 186 end
Chris@1295 187
Chris@1295 188 def test_remove_related_issue
Chris@1295 189 Changeset.find(103).issues << Issue.find(1)
Chris@1295 190 Changeset.find(103).issues << Issue.find(2)
Chris@1295 191
Chris@1295 192 @request.session[:user_id] = 2
Chris@1295 193 assert_difference 'Changeset.find(103).issues.size', -1 do
Chris@1295 194 xhr :delete, :remove_related_issue, :id => 1, :rev => 4, :issue_id => 2, :format => 'js'
Chris@1295 195 assert_response :success
Chris@1295 196 assert_template 'remove_related_issue'
Chris@1295 197 assert_equal 'text/javascript', response.content_type
Chris@1295 198 end
Chris@1295 199 assert_equal [1], Changeset.find(103).issue_ids
Chris@1295 200 assert_include 'related-issue-2', response.body
Chris@1295 201 end
Chris@1295 202
Chris@1295 203 def test_graph_commits_per_month
Chris@1295 204 # Make sure there's some data to display
Chris@1295 205 latest = Project.find(1).repository.changesets.maximum(:commit_date)
Chris@1295 206 assert_not_nil latest
Chris@1295 207 Date.stubs(:today).returns(latest.to_date + 10)
Chris@1295 208
Chris@1295 209 get :graph, :id => 1, :graph => 'commits_per_month'
Chris@1295 210 assert_response :success
Chris@1295 211 assert_equal 'image/svg+xml', @response.content_type
Chris@1295 212 end
Chris@1295 213
Chris@1295 214 def test_graph_commits_per_author
Chris@1295 215 get :graph, :id => 1, :graph => 'commits_per_author'
Chris@1295 216 assert_response :success
Chris@1295 217 assert_equal 'image/svg+xml', @response.content_type
Chris@1295 218 end
Chris@1295 219
Chris@1295 220 def test_get_committers
Chris@1295 221 @request.session[:user_id] = 2
Chris@1295 222 # add a commit with an unknown user
Chris@1295 223 Changeset.create!(
Chris@1295 224 :repository => Project.find(1).repository,
Chris@1295 225 :committer => 'foo',
Chris@1295 226 :committed_on => Time.now,
Chris@1295 227 :revision => 100,
Chris@1295 228 :comments => 'Committed by foo.'
Chris@1295 229 )
Chris@1295 230
Chris@1295 231 get :committers, :id => 10
Chris@1295 232 assert_response :success
Chris@1295 233 assert_template 'committers'
Chris@1295 234
Chris@1295 235 assert_tag :td, :content => 'dlopper',
Chris@1295 236 :sibling => { :tag => 'td',
Chris@1295 237 :child => { :tag => 'select', :attributes => { :name => %r{^committers\[\d+\]\[\]$} },
Chris@1295 238 :child => { :tag => 'option', :content => 'Dave Lopper',
Chris@1295 239 :attributes => { :value => '3', :selected => 'selected' }}}}
Chris@1295 240 assert_tag :td, :content => 'foo',
Chris@1295 241 :sibling => { :tag => 'td',
Chris@1295 242 :child => { :tag => 'select', :attributes => { :name => %r{^committers\[\d+\]\[\]$} }}}
Chris@1295 243 assert_no_tag :td, :content => 'foo',
Chris@1295 244 :sibling => { :tag => 'td',
Chris@1295 245 :descendant => { :tag => 'option', :attributes => { :selected => 'selected' }}}
Chris@1295 246 end
Chris@1295 247
Chris@1295 248 def test_post_committers
Chris@1295 249 @request.session[:user_id] = 2
Chris@1295 250 # add a commit with an unknown user
Chris@1295 251 c = Changeset.create!(
Chris@1295 252 :repository => Project.find(1).repository,
Chris@1295 253 :committer => 'foo',
Chris@1295 254 :committed_on => Time.now,
Chris@1295 255 :revision => 100,
Chris@1295 256 :comments => 'Committed by foo.'
Chris@1295 257 )
Chris@1295 258 assert_no_difference "Changeset.count(:conditions => 'user_id = 3')" do
Chris@1295 259 post :committers, :id => 10, :committers => { '0' => ['foo', '2'], '1' => ['dlopper', '3']}
Chris@1295 260 assert_response 302
Chris@1295 261 assert_equal User.find(2), c.reload.user
Chris@1295 262 end
Chris@1295 263 end
Chris@1295 264 end