comparison test/unit/.svn/text-base/changeset_test.rb.svn-base @ 119:8661b858af72

* Update to Redmine trunk rev 4705
author Chris Cannam
date Thu, 13 Jan 2011 14:12:06 +0000
parents 513646585e45
children 051f544170fe
comparison
equal deleted inserted replaced
39:150ceac17a8d 119:8661b858af72
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.dirname(__FILE__) + '/../test_helper' 20 require File.expand_path('../../test_helper', __FILE__)
21 21
22 class ChangesetTest < ActiveSupport::TestCase 22 class ChangesetTest < ActiveSupport::TestCase
23 fixtures :projects, :repositories, :issues, :issue_statuses, :changesets, :changes, :issue_categories, :enumerations, :custom_fields, :custom_values, :users, :members, :member_roles, :trackers 23 fixtures :projects, :repositories, :issues, :issue_statuses, :changesets, :changes, :issue_categories, :enumerations, :custom_fields, :custom_values, :users, :members, :member_roles, :trackers
24 24
25 def setup 25 def setup
42 assert fixed.closed? 42 assert fixed.closed?
43 assert_equal 90, fixed.done_ratio 43 assert_equal 90, fixed.done_ratio
44 assert_equal 1, ActionMailer::Base.deliveries.size 44 assert_equal 1, ActionMailer::Base.deliveries.size
45 end 45 end
46 46
47 def test_ref_keywords
48 Setting.commit_ref_keywords = 'refs'
49 Setting.commit_fix_keywords = ''
50
51 c = Changeset.new(:repository => Project.find(1).repository,
52 :committed_on => Time.now,
53 :comments => 'Ignores #2. Refs #1')
54 c.scan_comment_for_issue_ids
55
56 assert_equal [1], c.issue_ids.sort
57 end
58
59 def test_ref_keywords_any_only
60 Setting.commit_ref_keywords = '*'
61 Setting.commit_fix_keywords = ''
62
63 c = Changeset.new(:repository => Project.find(1).repository,
64 :committed_on => Time.now,
65 :comments => 'Ignores #2. Refs #1')
66 c.scan_comment_for_issue_ids
67
68 assert_equal [1, 2], c.issue_ids.sort
69 end
70
71 def test_ref_keywords_any_with_timelog
72 Setting.commit_ref_keywords = '*'
73 Setting.commit_logtime_enabled = '1'
74
75 c = Changeset.new(:repository => Project.find(1).repository,
76 :committed_on => 24.hours.ago,
77 :comments => 'Worked on this issue #1 @2h',
78 :revision => '520',
79 :user => User.find(2))
80 assert_difference 'TimeEntry.count' do
81 c.scan_comment_for_issue_ids
82 end
83 assert_equal [1], c.issue_ids.sort
84
85 time = TimeEntry.first(:order => 'id desc')
86 assert_equal 1, time.issue_id
87 assert_equal 1, time.project_id
88 assert_equal 2, time.user_id
89 assert_equal 2.0, time.hours
90 assert_equal Date.yesterday, time.spent_on
91 assert time.activity.is_default?
92 assert time.comments.include?('r520'), "r520 was expected in time_entry comments: #{time.comments}"
93 end
94
95 def test_ref_keywords_closing_with_timelog
96 Setting.commit_fix_status_id = IssueStatus.find(:first, :conditions => ["is_closed = ?", true]).id
97 Setting.commit_ref_keywords = '*'
98 Setting.commit_fix_keywords = 'fixes , closes'
99 Setting.commit_logtime_enabled = '1'
100
101 c = Changeset.new(:repository => Project.find(1).repository,
102 :committed_on => Time.now,
103 :comments => 'This is a comment. Fixes #1 @2.5, #2 @1',
104 :user => User.find(2))
105 assert_difference 'TimeEntry.count', 2 do
106 c.scan_comment_for_issue_ids
107 end
108
109 assert_equal [1, 2], c.issue_ids.sort
110 assert Issue.find(1).closed?
111 assert Issue.find(2).closed?
112
113 times = TimeEntry.all(:order => 'id desc', :limit => 2)
114 assert_equal [1, 2], times.collect(&:issue_id).sort
115 end
116
47 def test_ref_keywords_any_line_start 117 def test_ref_keywords_any_line_start
48 Setting.commit_ref_keywords = '*' 118 Setting.commit_ref_keywords = '*'
49 119
50 c = Changeset.new(:repository => Project.find(1).repository, 120 c = Changeset.new(:repository => Project.find(1).repository,
51 :committed_on => Time.now, 121 :committed_on => Time.now,
96 :comments => 'refs #2, an issue of a parent project') 166 :comments => 'refs #2, an issue of a parent project')
97 c.scan_comment_for_issue_ids 167 c.scan_comment_for_issue_ids
98 168
99 assert_equal [2], c.issue_ids.sort 169 assert_equal [2], c.issue_ids.sort
100 assert c.issues.first.project != c.project 170 assert c.issues.first.project != c.project
171 end
172
173 def test_text_tag_revision
174 c = Changeset.new(:revision => '520')
175 assert_equal 'r520', c.text_tag
176 end
177
178 def test_text_tag_hash
179 c = Changeset.new(:scmid => '7234cb2750b63f47bff735edc50a1c0a433c2518', :revision => '7234cb2750b63f47bff735edc50a1c0a433c2518')
180 assert_equal 'commit:7234cb2750b63f47bff735edc50a1c0a433c2518', c.text_tag
181 end
182
183 def test_text_tag_hash_all_number
184 c = Changeset.new(:scmid => '0123456789', :revision => '0123456789')
185 assert_equal 'commit:0123456789', c.text_tag
101 end 186 end
102 187
103 def test_previous 188 def test_previous
104 changeset = Changeset.find_by_revision('3') 189 changeset = Changeset.find_by_revision('3')
105 assert_equal Changeset.find_by_revision('2'), changeset.previous 190 assert_equal Changeset.find_by_revision('2'), changeset.previous
131 def test_invalid_utf8_sequences_in_comments_should_be_stripped 216 def test_invalid_utf8_sequences_in_comments_should_be_stripped
132 c = Changeset.new 217 c = Changeset.new
133 c.comments = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt") 218 c.comments = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
134 assert_equal "Texte encod en ISO-8859-1.", c.comments 219 assert_equal "Texte encod en ISO-8859-1.", c.comments
135 end 220 end
221
222 def test_identifier
223 c = Changeset.find_by_revision('1')
224 assert_equal c.revision, c.identifier
225 end
136 end 226 end