annotate test/functional/repositories_controller_test.rb @ 1327:287f201c2802 redmine-2.2-integration

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