Mercurial > hg > soundsoftware-site
comparison test/unit/repository_test.rb @ 1526:404aa68d4227
Merge from live branch
author | Chris Cannam |
---|---|
date | Thu, 11 Sep 2014 12:46:20 +0100 |
parents | dffacf8a6908 |
children |
comparison
equal
deleted
inserted
replaced
1493:a5f2bdf3b486 | 1526:404aa68d4227 |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2012 Jean-Philippe Lang | 2 # Copyright (C) 2006-2014 Jean-Philippe Lang |
3 # | 3 # |
4 # This program is free software; you can redistribute it and/or | 4 # This program is free software; you can redistribute it and/or |
5 # modify it under the terms of the GNU General Public License | 5 # modify it under the terms of the GNU General Public License |
6 # as published by the Free Software Foundation; either version 2 | 6 # as published by the Free Software Foundation; either version 2 |
7 # of the License, or (at your option) any later version. | 7 # of the License, or (at your option) any later version. |
95 | 95 |
96 assert_equal repository1, Project.find(3).repository | 96 assert_equal repository1, Project.find(3).repository |
97 assert_equal [repository1, repository2], Project.find(3).repositories.sort | 97 assert_equal [repository1, repository2], Project.find(3).repositories.sort |
98 end | 98 end |
99 | 99 |
100 def test_default_repository_should_be_one | |
101 assert_equal 0, Project.find(3).repositories.count | |
102 repository1 = Repository::Subversion.new( | |
103 :project => Project.find(3), | |
104 :identifier => 'svn1', | |
105 :url => 'file:///svn1' | |
106 ) | |
107 assert repository1.save | |
108 assert repository1.is_default? | |
109 | |
110 repository2 = Repository::Subversion.new( | |
111 :project => Project.find(3), | |
112 :identifier => 'svn2', | |
113 :url => 'file:///svn2', | |
114 :is_default => true | |
115 ) | |
116 assert repository2.save | |
117 assert repository2.is_default? | |
118 repository1.reload | |
119 assert !repository1.is_default? | |
120 | |
121 assert_equal repository2, Project.find(3).repository | |
122 assert_equal [repository2, repository1], Project.find(3).repositories.sort | |
123 end | |
124 | |
100 def test_identifier_should_accept_letters_digits_dashes_and_underscores | 125 def test_identifier_should_accept_letters_digits_dashes_and_underscores |
101 r = Repository::Subversion.new( | 126 r = Repository::Subversion.new( |
102 :project_id => 3, | 127 :project_id => 3, |
103 :identifier => 'svn-123_45', | 128 :identifier => 'svn-123_45', |
104 :url => 'file:///svn' | 129 :url => 'file:///svn' |
105 ) | 130 ) |
106 assert r.save | 131 assert r.save |
107 end | 132 end |
108 | 133 |
109 def test_identifier_should_not_be_frozen_for_a_new_repository | 134 def test_identifier_should_not_be_frozen_for_a_new_repository |
110 assert_equal false, Repository.new.identifier_frozen? | 135 assert_equal false, Repository.new.identifier_frozen? |
111 end | 136 end |
112 | 137 |
113 def test_identifier_should_not_be_frozen_for_a_saved_repository_with_blank_identifier | 138 def test_identifier_should_not_be_frozen_for_a_saved_repository_with_blank_identifier |
114 Repository.update_all(["identifier = ''"], "id = 10") | 139 Repository.where(:id => 10).update_all(["identifier = ''"]) |
115 | |
116 assert_equal false, Repository.find(10).identifier_frozen? | 140 assert_equal false, Repository.find(10).identifier_frozen? |
117 end | 141 end |
118 | 142 |
119 def test_identifier_should_be_frozen_for_a_saved_repository_with_valid_identifier | 143 def test_identifier_should_be_frozen_for_a_saved_repository_with_valid_identifier |
120 Repository.update_all(["identifier = 'abc123'"], "id = 10") | 144 Repository.where(:id => 10).update_all(["identifier = 'abc123'"]) |
121 | |
122 assert_equal true, Repository.find(10).identifier_frozen? | 145 assert_equal true, Repository.find(10).identifier_frozen? |
123 end | 146 end |
124 | 147 |
125 def test_identifier_should_not_accept_change_if_frozen | 148 def test_identifier_should_not_accept_change_if_frozen |
126 r = Repository.new(:identifier => 'foo') | 149 r = Repository.new(:identifier => 'foo') |
150 end | 173 end |
151 end | 174 end |
152 | 175 |
153 def test_destroy_should_delete_parents_associations | 176 def test_destroy_should_delete_parents_associations |
154 changeset = Changeset.find(102) | 177 changeset = Changeset.find(102) |
155 changeset.parents = Changeset.find_all_by_id([100, 101]) | 178 changeset.parents = Changeset.where(:id => [100, 101]).all |
156 | 179 assert_difference 'Changeset.connection.select_all("select * from changeset_parents").count', -2 do |
157 assert_difference 'Changeset.connection.select_all("select * from changeset_parents").size', -2 do | |
158 Repository.find(10).destroy | 180 Repository.find(10).destroy |
159 end | 181 end |
160 end | 182 end |
161 | 183 |
162 def test_destroy_should_delete_issues_associations | 184 def test_destroy_should_delete_issues_associations |
163 changeset = Changeset.find(102) | 185 changeset = Changeset.find(102) |
164 changeset.issues = Issue.find_all_by_id([1, 2]) | 186 changeset.issues = Issue.where(:id => [1, 2]).all |
165 | 187 assert_difference 'Changeset.connection.select_all("select * from changesets_issues").count', -2 do |
166 assert_difference 'Changeset.connection.select_all("select * from changesets_issues").size', -2 do | |
167 Repository.find(10).destroy | 188 Repository.find(10).destroy |
168 end | 189 end |
169 end | 190 end |
170 | 191 |
171 def test_should_not_create_with_disabled_scm | 192 def test_should_not_create_with_disabled_scm |
179 end | 200 end |
180 end | 201 end |
181 | 202 |
182 def test_scan_changesets_for_issue_ids | 203 def test_scan_changesets_for_issue_ids |
183 Setting.default_language = 'en' | 204 Setting.default_language = 'en' |
184 | |
185 # choosing a status to apply to fix issues | |
186 Setting.commit_fix_status_id = IssueStatus.find( | |
187 :first, | |
188 :conditions => ["is_closed = ?", true]).id | |
189 Setting.commit_fix_done_ratio = "90" | |
190 Setting.commit_ref_keywords = 'refs , references, IssueID' | 205 Setting.commit_ref_keywords = 'refs , references, IssueID' |
191 Setting.commit_fix_keywords = 'fixes , closes' | 206 Setting.commit_update_keywords = [ |
207 {'keywords' => 'fixes , closes', | |
208 'status_id' => IssueStatus.where(:is_closed => true).first.id, | |
209 'done_ratio' => '90'} | |
210 ] | |
192 Setting.default_language = 'en' | 211 Setting.default_language = 'en' |
193 ActionMailer::Base.deliveries.clear | 212 ActionMailer::Base.deliveries.clear |
194 | 213 |
195 # make sure issue 1 is not already closed | 214 # make sure issue 1 is not already closed |
196 fixed_issue = Issue.find(1) | 215 fixed_issue = Issue.find(1) |
207 assert fixed_issue.status.is_closed? | 226 assert fixed_issue.status.is_closed? |
208 assert_equal 90, fixed_issue.done_ratio | 227 assert_equal 90, fixed_issue.done_ratio |
209 assert_equal [101], fixed_issue.changeset_ids | 228 assert_equal [101], fixed_issue.changeset_ids |
210 | 229 |
211 # issue change | 230 # issue change |
212 journal = fixed_issue.journals.find(:first, :order => 'created_on desc') | 231 journal = fixed_issue.journals.reorder('created_on desc').first |
213 assert_equal User.find_by_login('dlopper'), journal.user | 232 assert_equal User.find_by_login('dlopper'), journal.user |
214 assert_equal 'Applied in changeset r2.', journal.notes | 233 assert_equal 'Applied in changeset r2.', journal.notes |
215 | 234 |
216 # 2 email notifications | 235 # 2 email notifications |
217 assert_equal 2, ActionMailer::Base.deliveries.size | 236 assert_equal 2, ActionMailer::Base.deliveries.size |
276 repository.reload | 295 repository.reload |
277 assert_equal 'c:\dummy', repository.url | 296 assert_equal 'c:\dummy', repository.url |
278 end | 297 end |
279 | 298 |
280 def test_manual_user_mapping | 299 def test_manual_user_mapping |
281 assert_no_difference "Changeset.count(:conditions => 'user_id <> 2')" do | 300 assert_no_difference "Changeset.where('user_id <> 2').count" do |
282 c = Changeset.create!( | 301 c = Changeset.create!( |
283 :repository => @repository, | 302 :repository => @repository, |
284 :committer => 'foo', | 303 :committer => 'foo', |
285 :committed_on => Time.now, | 304 :committed_on => Time.now, |
286 :revision => 100, | 305 :revision => 100, |
325 | 344 |
326 def test_filesystem_avaialbe | 345 def test_filesystem_avaialbe |
327 klass = Repository::Filesystem | 346 klass = Repository::Filesystem |
328 assert klass.scm_adapter_class | 347 assert klass.scm_adapter_class |
329 assert_equal true, klass.scm_available | 348 assert_equal true, klass.scm_available |
349 end | |
350 | |
351 def test_extra_info_should_not_return_non_hash_value | |
352 repo = Repository.new | |
353 repo.extra_info = "foo" | |
354 assert_nil repo.extra_info | |
330 end | 355 end |
331 | 356 |
332 def test_merge_extra_info | 357 def test_merge_extra_info |
333 repo = Repository::Subversion.new(:project => Project.find(3)) | 358 repo = Repository::Subversion.new(:project => Project.find(3)) |
334 assert !repo.save | 359 assert !repo.save |