comparison test/unit/changeset_test.rb @ 909:cbb26bc654de redmine-1.3

Update to Redmine 1.3-stable branch (Redmine SVN rev 8964)
author Chris Cannam
date Fri, 24 Feb 2012 19:09:32 +0000
parents cbce1fd3b1b7
children 5f33065ddc4b
comparison
equal deleted inserted replaced
908:c6c2cbd0afee 909:cbb26bc654de
1 # encoding: utf-8 1 # encoding: utf-8
2 # 2 #
3 # Redmine - project management software 3 # Redmine - project management software
4 # Copyright (C) 2006-2010 Jean-Philippe Lang 4 # Copyright (C) 2006-2011 Jean-Philippe Lang
5 # 5 #
6 # This program is free software; you can redistribute it and/or 6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License 7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2 8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version. 9 # of the License, or (at your option) any later version.
10 # 10 #
11 # This program is distributed in the hope that it will be useful, 11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details. 14 # GNU General Public License for more details.
15 # 15 #
16 # You should have received a copy of the GNU General Public License 16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software 17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 19
20 require File.expand_path('../../test_helper', __FILE__) 20 require File.expand_path('../../test_helper', __FILE__)
21 21
22 class ChangesetTest < ActiveSupport::TestCase 22 class ChangesetTest < ActiveSupport::TestCase
23 fixtures :projects, :repositories, 23 fixtures :projects, :repositories,
24 :issues, :issue_statuses, :issue_categories, 24 :issues, :issue_statuses, :issue_categories,
25 :changesets, :changes, 25 :changesets, :changes,
26 :enumerations, 26 :enumerations,
27 :custom_fields, :custom_values, 27 :custom_fields, :custom_values,
28 :users, :members, :member_roles, :trackers, 28 :users, :members, :member_roles, :trackers,
29 :enabled_modules, :roles 29 :enabled_modules, :roles
30 30
39 Setting.commit_ref_keywords = '*' 39 Setting.commit_ref_keywords = '*'
40 Setting.commit_fix_keywords = 'fixes , closes' 40 Setting.commit_fix_keywords = 'fixes , closes'
41 41
42 c = Changeset.new(:repository => Project.find(1).repository, 42 c = Changeset.new(:repository => Project.find(1).repository,
43 :committed_on => Time.now, 43 :committed_on => Time.now,
44 :comments => 'New commit (#2). Fixes #1') 44 :comments => 'New commit (#2). Fixes #1',
45 c.scan_comment_for_issue_ids 45 :revision => '12345')
46 46 assert c.save
47 assert_equal [1, 2], c.issue_ids.sort 47 assert_equal [1, 2], c.issue_ids.sort
48 fixed = Issue.find(1) 48 fixed = Issue.find(1)
49 assert fixed.closed? 49 assert fixed.closed?
50 assert_equal 90, fixed.done_ratio 50 assert_equal 90, fixed.done_ratio
51 assert_equal 1, ActionMailer::Base.deliveries.size 51 assert_equal 1, ActionMailer::Base.deliveries.size
52 end 52 end
53 53
54 def test_ref_keywords 54 def test_ref_keywords
55 Setting.commit_ref_keywords = 'refs' 55 Setting.commit_ref_keywords = 'refs'
56 Setting.commit_fix_keywords = '' 56 Setting.commit_fix_keywords = ''
57 57 c = Changeset.new(:repository => Project.find(1).repository,
58 c = Changeset.new(:repository => Project.find(1).repository, 58 :committed_on => Time.now,
59 :committed_on => Time.now, 59 :comments => 'Ignores #2. Refs #1',
60 :comments => 'Ignores #2. Refs #1') 60 :revision => '12345')
61 c.scan_comment_for_issue_ids 61 assert c.save
62
63 assert_equal [1], c.issue_ids.sort 62 assert_equal [1], c.issue_ids.sort
64 end 63 end
65 64
66 def test_ref_keywords_any_only 65 def test_ref_keywords_any_only
67 Setting.commit_ref_keywords = '*' 66 Setting.commit_ref_keywords = '*'
68 Setting.commit_fix_keywords = '' 67 Setting.commit_fix_keywords = ''
69 68 c = Changeset.new(:repository => Project.find(1).repository,
70 c = Changeset.new(:repository => Project.find(1).repository, 69 :committed_on => Time.now,
71 :committed_on => Time.now, 70 :comments => 'Ignores #2. Refs #1',
72 :comments => 'Ignores #2. Refs #1') 71 :revision => '12345')
73 c.scan_comment_for_issue_ids 72 assert c.save
74
75 assert_equal [1, 2], c.issue_ids.sort 73 assert_equal [1, 2], c.issue_ids.sort
76 end 74 end
77 75
78 def test_ref_keywords_any_with_timelog 76 def test_ref_keywords_any_with_timelog
79 Setting.commit_ref_keywords = '*' 77 Setting.commit_ref_keywords = '*'
121 Setting.commit_fix_status_id = IssueStatus.find( 119 Setting.commit_fix_status_id = IssueStatus.find(
122 :first, :conditions => ["is_closed = ?", true]).id 120 :first, :conditions => ["is_closed = ?", true]).id
123 Setting.commit_ref_keywords = '*' 121 Setting.commit_ref_keywords = '*'
124 Setting.commit_fix_keywords = 'fixes , closes' 122 Setting.commit_fix_keywords = 'fixes , closes'
125 Setting.commit_logtime_enabled = '1' 123 Setting.commit_logtime_enabled = '1'
126 124
127 c = Changeset.new(:repository => Project.find(1).repository, 125 c = Changeset.new(:repository => Project.find(1).repository,
128 :committed_on => Time.now, 126 :committed_on => Time.now,
129 :comments => 'This is a comment. Fixes #1 @4.5, #2 @1', 127 :comments => 'This is a comment. Fixes #1 @4.5, #2 @1',
130 :user => User.find(2)) 128 :user => User.find(2))
131 assert_difference 'TimeEntry.count', 2 do 129 assert_difference 'TimeEntry.count', 2 do
140 assert_equal [1, 2], times.collect(&:issue_id).sort 138 assert_equal [1, 2], times.collect(&:issue_id).sort
141 end 139 end
142 140
143 def test_ref_keywords_any_line_start 141 def test_ref_keywords_any_line_start
144 Setting.commit_ref_keywords = '*' 142 Setting.commit_ref_keywords = '*'
145 143 c = Changeset.new(:repository => Project.find(1).repository,
146 c = Changeset.new(:repository => Project.find(1).repository, 144 :committed_on => Time.now,
147 :committed_on => Time.now, 145 :comments => '#1 is the reason of this commit',
148 :comments => '#1 is the reason of this commit') 146 :revision => '12345')
149 c.scan_comment_for_issue_ids 147 assert c.save
150
151 assert_equal [1], c.issue_ids.sort 148 assert_equal [1], c.issue_ids.sort
152 end 149 end
153 150
154 def test_ref_keywords_allow_brackets_around_a_issue_number 151 def test_ref_keywords_allow_brackets_around_a_issue_number
155 Setting.commit_ref_keywords = '*' 152 Setting.commit_ref_keywords = '*'
156 153 c = Changeset.new(:repository => Project.find(1).repository,
157 c = Changeset.new(:repository => Project.find(1).repository, 154 :committed_on => Time.now,
158 :committed_on => Time.now, 155 :comments => '[#1] Worked on this issue',
159 :comments => '[#1] Worked on this issue') 156 :revision => '12345')
160 c.scan_comment_for_issue_ids 157 assert c.save
161
162 assert_equal [1], c.issue_ids.sort 158 assert_equal [1], c.issue_ids.sort
163 end 159 end
164 160
165 def test_ref_keywords_allow_brackets_around_multiple_issue_numbers 161 def test_ref_keywords_allow_brackets_around_multiple_issue_numbers
166 Setting.commit_ref_keywords = '*' 162 Setting.commit_ref_keywords = '*'
167 163 c = Changeset.new(:repository => Project.find(1).repository,
168 c = Changeset.new(:repository => Project.find(1).repository, 164 :committed_on => Time.now,
169 :committed_on => Time.now, 165 :comments => '[#1 #2, #3] Worked on these',
170 :comments => '[#1 #2, #3] Worked on these') 166 :revision => '12345')
171 c.scan_comment_for_issue_ids 167 assert c.save
172
173 assert_equal [1,2,3], c.issue_ids.sort 168 assert_equal [1,2,3], c.issue_ids.sort
174 end 169 end
175 170
176 def test_commit_referencing_a_subproject_issue 171 def test_commit_referencing_a_subproject_issue
177 c = Changeset.new(:repository => Project.find(1).repository, 172 c = Changeset.new(:repository => Project.find(1).repository,
178 :committed_on => Time.now, 173 :committed_on => Time.now,
179 :comments => 'refs #5, a subproject issue') 174 :comments => 'refs #5, a subproject issue',
180 c.scan_comment_for_issue_ids 175 :revision => '12345')
181 176 assert c.save
182 assert_equal [5], c.issue_ids.sort 177 assert_equal [5], c.issue_ids.sort
183 assert c.issues.first.project != c.project 178 assert c.issues.first.project != c.project
184 end 179 end
185 180
186 def test_commit_referencing_a_parent_project_issue 181 def test_commit_referencing_a_parent_project_issue
187 # repository of child project 182 # repository of child project
188 r = Repository::Subversion.create!( 183 r = Repository::Subversion.create!(
189 :project => Project.find(3), 184 :project => Project.find(3),
190 :url => 'svn://localhost/test') 185 :url => 'svn://localhost/test')
191 186 c = Changeset.new(:repository => r,
192 c = Changeset.new(:repository => r, 187 :committed_on => Time.now,
193 :committed_on => Time.now, 188 :comments => 'refs #2, an issue of a parent project',
194 :comments => 'refs #2, an issue of a parent project') 189 :revision => '12345')
195 c.scan_comment_for_issue_ids 190 assert c.save
196
197 assert_equal [2], c.issue_ids.sort 191 assert_equal [2], c.issue_ids.sort
198 assert c.issues.first.project != c.project 192 assert c.issues.first.project != c.project
199 end 193 end
200 194
201 def test_text_tag_revision 195 def test_text_tag_revision