comparison test/unit/repository_test.rb @ 1115:433d4f72a19b redmine-2.2

Update to Redmine SVN revision 11137 on 2.2-stable branch
author Chris Cannam
date Mon, 07 Jan 2013 12:01:42 +0000
parents cbb26bc654de
children 622f24f53b42 261b3d9a4903
comparison
equal deleted inserted replaced
929:5f33065ddc4b 1115:433d4f72a19b
1 # Redmine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang 2 # Copyright (C) 2006-2012 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.
32 :members, 32 :members,
33 :member_roles, 33 :member_roles,
34 :roles, 34 :roles,
35 :enumerations 35 :enumerations
36 36
37 include Redmine::I18n
38
37 def setup 39 def setup
38 @repository = Project.find(1).repository 40 @repository = Project.find(1).repository
41 end
42
43 def test_blank_log_encoding_error_message
44 set_language_if_valid 'en'
45 repo = Repository::Bazaar.new(
46 :project => Project.find(3),
47 :url => "/test",
48 :log_encoding => ''
49 )
50 assert !repo.save
51 assert_include "Commit messages encoding can't be blank",
52 repo.errors.full_messages
53 end
54
55 def test_blank_log_encoding_error_message_fr
56 set_language_if_valid 'fr'
57 str = "Encodage des messages de commit doit \xc3\xaatre renseign\xc3\xa9(e)"
58 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
59 repo = Repository::Bazaar.new(
60 :project => Project.find(3),
61 :url => "/test"
62 )
63 assert !repo.save
64 assert_include str, repo.errors.full_messages
39 end 65 end
40 66
41 def test_create 67 def test_create
42 repository = Repository::Subversion.new(:project => Project.find(3)) 68 repository = Repository::Subversion.new(:project => Project.find(3))
43 assert !repository.save 69 assert !repository.save
48 74
49 project = Project.find(3) 75 project = Project.find(3)
50 assert_equal repository, project.repository 76 assert_equal repository, project.repository
51 end 77 end
52 78
79 def test_first_repository_should_be_set_as_default
80 repository1 = Repository::Subversion.new(
81 :project => Project.find(3),
82 :identifier => 'svn1',
83 :url => 'file:///svn1'
84 )
85 assert repository1.save
86 assert repository1.is_default?
87
88 repository2 = Repository::Subversion.new(
89 :project => Project.find(3),
90 :identifier => 'svn2',
91 :url => 'file:///svn2'
92 )
93 assert repository2.save
94 assert !repository2.is_default?
95
96 assert_equal repository1, Project.find(3).repository
97 assert_equal [repository1, repository2], Project.find(3).repositories.sort
98 end
99
100 def test_identifier_should_accept_letters_digits_dashes_and_underscores
101 r = Repository::Subversion.new(
102 :project_id => 3,
103 :identifier => 'svn-123_45',
104 :url => 'file:///svn'
105 )
106 assert r.save
107 end
108
109 def test_identifier_should_not_be_frozen_for_a_new_repository
110 assert_equal false, Repository.new.identifier_frozen?
111 end
112
113 def test_identifier_should_not_be_frozen_for_a_saved_repository_with_blank_identifier
114 Repository.update_all(["identifier = ''"], "id = 10")
115
116 assert_equal false, Repository.find(10).identifier_frozen?
117 end
118
119 def test_identifier_should_be_frozen_for_a_saved_repository_with_valid_identifier
120 Repository.update_all(["identifier = 'abc123'"], "id = 10")
121
122 assert_equal true, Repository.find(10).identifier_frozen?
123 end
124
125 def test_identifier_should_not_accept_change_if_frozen
126 r = Repository.new(:identifier => 'foo')
127 r.stubs(:identifier_frozen?).returns(true)
128
129 r.identifier = 'bar'
130 assert_equal 'foo', r.identifier
131 end
132
133 def test_identifier_should_accept_change_if_not_frozen
134 r = Repository.new(:identifier => 'foo')
135 r.stubs(:identifier_frozen?).returns(false)
136
137 r.identifier = 'bar'
138 assert_equal 'bar', r.identifier
139 end
140
53 def test_destroy 141 def test_destroy
54 changesets = Changeset.count(:all, :conditions => "repository_id = 10") 142 repository = Repository.find(10)
55 changes = Change.count(:all, :conditions => "repository_id = 10", 143 changesets = repository.changesets.count
56 :include => :changeset) 144 changes = repository.filechanges.count
145
57 assert_difference 'Changeset.count', -changesets do 146 assert_difference 'Changeset.count', -changesets do
58 assert_difference 'Change.count', -changes do 147 assert_difference 'Change.count', -changes do
59 Repository.find(10).destroy 148 Repository.find(10).destroy
60 end 149 end
150 end
151 end
152
153 def test_destroy_should_delete_parents_associations
154 changeset = Changeset.find(102)
155 changeset.parents = Changeset.find_all_by_id([100, 101])
156
157 assert_difference 'Changeset.connection.select_all("select * from changeset_parents").size', -2 do
158 Repository.find(10).destroy
159 end
160 end
161
162 def test_destroy_should_delete_issues_associations
163 changeset = Changeset.find(102)
164 changeset.issues = Issue.find_all_by_id([1, 2])
165
166 assert_difference 'Changeset.connection.select_all("select * from changesets_issues").size', -2 do
167 Repository.find(10).destroy
61 end 168 end
62 end 169 end
63 170
64 def test_should_not_create_with_disabled_scm 171 def test_should_not_create_with_disabled_scm
65 # disable Subversion 172 # disable Subversion
66 with_settings :enabled_scm => ['Darcs', 'Git'] do 173 with_settings :enabled_scm => ['Darcs', 'Git'] do
67 repository = Repository::Subversion.new( 174 repository = Repository::Subversion.new(
68 :project => Project.find(3), :url => "svn://localhost") 175 :project => Project.find(3), :url => "svn://localhost")
69 assert !repository.save 176 assert !repository.save
70 assert_equal I18n.translate('activerecord.errors.messages.invalid'), 177 assert_include I18n.translate('activerecord.errors.messages.invalid'),
71 repository.errors.on(:type) 178 repository.errors[:type]
72 end 179 end
73 end 180 end
74 181
75 def test_scan_changesets_for_issue_ids 182 def test_scan_changesets_for_issue_ids
76 Setting.default_language = 'en' 183 Setting.default_language = 'en'
77 Setting.notified_events = ['issue_added','issue_updated']
78 184
79 # choosing a status to apply to fix issues 185 # choosing a status to apply to fix issues
80 Setting.commit_fix_status_id = IssueStatus.find( 186 Setting.commit_fix_status_id = IssueStatus.find(
81 :first, 187 :first,
82 :conditions => ["is_closed = ?", true]).id 188 :conditions => ["is_closed = ?", true]).id
89 # make sure issue 1 is not already closed 195 # make sure issue 1 is not already closed
90 fixed_issue = Issue.find(1) 196 fixed_issue = Issue.find(1)
91 assert !fixed_issue.status.is_closed? 197 assert !fixed_issue.status.is_closed?
92 old_status = fixed_issue.status 198 old_status = fixed_issue.status
93 199
94 Repository.scan_changesets_for_issue_ids 200 with_settings :notified_events => %w(issue_added issue_updated) do
201 Repository.scan_changesets_for_issue_ids
202 end
95 assert_equal [101, 102], Issue.find(3).changeset_ids 203 assert_equal [101, 102], Issue.find(3).changeset_ids
96 204
97 # fixed issues 205 # fixed issues
98 fixed_issue.reload 206 fixed_issue.reload
99 assert fixed_issue.status.is_closed? 207 assert fixed_issue.status.is_closed?
106 assert_equal 'Applied in changeset r2.', journal.notes 214 assert_equal 'Applied in changeset r2.', journal.notes
107 215
108 # 2 email notifications 216 # 2 email notifications
109 assert_equal 2, ActionMailer::Base.deliveries.size 217 assert_equal 2, ActionMailer::Base.deliveries.size
110 mail = ActionMailer::Base.deliveries.first 218 mail = ActionMailer::Base.deliveries.first
111 assert_kind_of TMail::Mail, mail 219 assert_not_nil mail
112 assert mail.subject.starts_with?( 220 assert mail.subject.starts_with?(
113 "[#{fixed_issue.project.name} - #{fixed_issue.tracker.name} ##{fixed_issue.id}]") 221 "[#{fixed_issue.project.name} - #{fixed_issue.tracker.name} ##{fixed_issue.id}]")
114 assert mail.body.include?( 222 assert_mail_body_match(
115 "Status changed from #{old_status} to #{fixed_issue.status}") 223 "Status changed from #{old_status} to #{fixed_issue.status}", mail)
116 224
117 # ignoring commits referencing an issue of another project 225 # ignoring commits referencing an issue of another project
118 assert_equal [], Issue.find(4).changesets 226 assert_equal [], Issue.find(4).changesets
119 end 227 end
120 228
251 repo.extra_info["test_1"] 359 repo.extra_info["test_1"]
252 assert_nil repo.extra_info["test_2"]["test_21"] 360 assert_nil repo.extra_info["test_2"]["test_21"]
253 assert_equal "test_value_23", 361 assert_equal "test_value_23",
254 repo.extra_info["test_2"]["test_23"] 362 repo.extra_info["test_2"]["test_23"]
255 end 363 end
364
365 def test_sort_should_not_raise_an_error_with_nil_identifiers
366 r1 = Repository.new
367 r2 = Repository.new
368
369 assert_nothing_raised do
370 [r1, r2].sort
371 end
372 end
256 end 373 end