annotate .svn/pristine/af/af9af6c7e5a0647f8676df5d9cd78d394797b260.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

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