To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / test / unit / repository_test.rb @ 442:753f1380d6bc

History | View | Annotate | Download (8.21 KB)

1 441:cbce1fd3b1b7 Chris
# Redmine - project management software
2
# Copyright (C) 2006-2011  Jean-Philippe Lang
3 0:513646585e45 Chris
#
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU General Public License
6
# as published by the Free Software Foundation; either version 2
7
# of the License, or (at your option) any later version.
8 441:cbce1fd3b1b7 Chris
#
9 0:513646585e45 Chris
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13 441:cbce1fd3b1b7 Chris
#
14 0:513646585e45 Chris
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17
18 119:8661b858af72 Chris
require File.expand_path('../../test_helper', __FILE__)
19 0:513646585e45 Chris
20
class RepositoryTest < ActiveSupport::TestCase
21
  fixtures :projects,
22
           :trackers,
23
           :projects_trackers,
24 119:8661b858af72 Chris
           :enabled_modules,
25 0:513646585e45 Chris
           :repositories,
26
           :issues,
27
           :issue_statuses,
28 119:8661b858af72 Chris
           :issue_categories,
29 0:513646585e45 Chris
           :changesets,
30
           :changes,
31
           :users,
32 119:8661b858af72 Chris
           :members,
33
           :member_roles,
34
           :roles,
35 0:513646585e45 Chris
           :enumerations
36 441:cbce1fd3b1b7 Chris
37 0:513646585e45 Chris
  def setup
38
    @repository = Project.find(1).repository
39
  end
40 441:cbce1fd3b1b7 Chris
41 0:513646585e45 Chris
  def test_create
42
    repository = Repository::Subversion.new(:project => Project.find(3))
43
    assert !repository.save
44 441:cbce1fd3b1b7 Chris
45 0:513646585e45 Chris
    repository.url = "svn://localhost"
46
    assert repository.save
47
    repository.reload
48 441:cbce1fd3b1b7 Chris
49 0:513646585e45 Chris
    project = Project.find(3)
50
    assert_equal repository, project.repository
51
  end
52 441:cbce1fd3b1b7 Chris
53 0:513646585e45 Chris
  def test_destroy
54
    changesets = Changeset.count(:all, :conditions => "repository_id = 10")
55 441:cbce1fd3b1b7 Chris
    changes = Change.count(:all, :conditions => "repository_id = 10",
56
                           :include => :changeset)
57 0:513646585e45 Chris
    assert_difference 'Changeset.count', -changesets do
58
      assert_difference 'Change.count', -changes do
59
        Repository.find(10).destroy
60
      end
61
    end
62
  end
63 441:cbce1fd3b1b7 Chris
64 0:513646585e45 Chris
  def test_should_not_create_with_disabled_scm
65
    # disable Subversion
66 128:07fa8a8b56a8 Chris
    with_settings :enabled_scm => ['Darcs', 'Git'] do
67 441:cbce1fd3b1b7 Chris
      repository = Repository::Subversion.new(
68
                      :project => Project.find(3), :url => "svn://localhost")
69 128:07fa8a8b56a8 Chris
      assert !repository.save
70 441:cbce1fd3b1b7 Chris
      assert_equal I18n.translate('activerecord.errors.messages.invalid'),
71
                                  repository.errors.on(:type)
72 128:07fa8a8b56a8 Chris
    end
73 0:513646585e45 Chris
  end
74 441:cbce1fd3b1b7 Chris
75 0:513646585e45 Chris
  def test_scan_changesets_for_issue_ids
76
    Setting.default_language = 'en'
77 37:94944d00e43c chris
    Setting.notified_events = ['issue_added','issue_updated']
78 441:cbce1fd3b1b7 Chris
79 0:513646585e45 Chris
    # choosing a status to apply to fix issues
80 441:cbce1fd3b1b7 Chris
    Setting.commit_fix_status_id = IssueStatus.find(
81
                                     :first,
82
                                     :conditions => ["is_closed = ?", true]).id
83 0:513646585e45 Chris
    Setting.commit_fix_done_ratio = "90"
84
    Setting.commit_ref_keywords = 'refs , references, IssueID'
85
    Setting.commit_fix_keywords = 'fixes , closes'
86
    Setting.default_language = 'en'
87
    ActionMailer::Base.deliveries.clear
88 441:cbce1fd3b1b7 Chris
89 0:513646585e45 Chris
    # make sure issue 1 is not already closed
90
    fixed_issue = Issue.find(1)
91
    assert !fixed_issue.status.is_closed?
92
    old_status = fixed_issue.status
93 441:cbce1fd3b1b7 Chris
94 0:513646585e45 Chris
    Repository.scan_changesets_for_issue_ids
95
    assert_equal [101, 102], Issue.find(3).changeset_ids
96 441:cbce1fd3b1b7 Chris
97 0:513646585e45 Chris
    # fixed issues
98
    fixed_issue.reload
99
    assert fixed_issue.status.is_closed?
100
    assert_equal 90, fixed_issue.done_ratio
101
    assert_equal [101], fixed_issue.changeset_ids
102 441:cbce1fd3b1b7 Chris
103 0:513646585e45 Chris
    # issue change
104
    journal = fixed_issue.journals.find(:first, :order => 'created_on desc')
105
    assert_equal User.find_by_login('dlopper'), journal.user
106
    assert_equal 'Applied in changeset r2.', journal.notes
107 441:cbce1fd3b1b7 Chris
108 0:513646585e45 Chris
    # 2 email notifications
109
    assert_equal 2, ActionMailer::Base.deliveries.size
110
    mail = ActionMailer::Base.deliveries.first
111
    assert_kind_of TMail::Mail, mail
112 441:cbce1fd3b1b7 Chris
    assert mail.subject.starts_with?(
113
        "[#{fixed_issue.project.name} - #{fixed_issue.tracker.name} ##{fixed_issue.id}]")
114
    assert mail.body.include?(
115
        "Status changed from #{old_status} to #{fixed_issue.status}")
116
117 0:513646585e45 Chris
    # ignoring commits referencing an issue of another project
118
    assert_equal [], Issue.find(4).changesets
119
  end
120 441:cbce1fd3b1b7 Chris
121 0:513646585e45 Chris
  def test_for_changeset_comments_strip
122 441:cbce1fd3b1b7 Chris
    repository = Repository::Mercurial.create(
123
                    :project => Project.find( 4 ),
124
                    :url => '/foo/bar/baz' )
125 0:513646585e45 Chris
    comment = <<-COMMENT
126
    This is a loooooooooooooooooooooooooooong comment
127

128

129
    COMMENT
130
    changeset = Changeset.new(
131 441:cbce1fd3b1b7 Chris
      :comments => comment, :commit_date => Time.now,
132
      :revision => 0, :scmid => 'f39b7922fb3c',
133
      :committer => 'foo <foo@example.com>',
134
      :committed_on => Time.now, :repository => repository )
135 0:513646585e45 Chris
    assert( changeset.save )
136
    assert_not_equal( comment, changeset.comments )
137 441:cbce1fd3b1b7 Chris
    assert_equal( 'This is a loooooooooooooooooooooooooooong comment',
138
                  changeset.comments )
139 0:513646585e45 Chris
  end
140 245:051f544170fe Chris
141 0:513646585e45 Chris
  def test_for_urls_strip
142 245:051f544170fe Chris
    repository = Repository::Cvs.create(
143
        :project => Project.find(4),
144
        :url => ' :pserver:login:password@host:/path/to/the/repository',
145
        :root_url => 'foo  ',
146
        :log_encoding => 'UTF-8')
147 0:513646585e45 Chris
    assert repository.save
148
    repository.reload
149 441:cbce1fd3b1b7 Chris
    assert_equal ':pserver:login:password@host:/path/to/the/repository',
150
                  repository.url
151 0:513646585e45 Chris
    assert_equal 'foo', repository.root_url
152
  end
153 245:051f544170fe Chris
154 0:513646585e45 Chris
  def test_manual_user_mapping
155
    assert_no_difference "Changeset.count(:conditions => 'user_id <> 2')" do
156 441:cbce1fd3b1b7 Chris
      c = Changeset.create!(
157
              :repository => @repository,
158
              :committer => 'foo',
159
              :committed_on => Time.now,
160
              :revision => 100,
161
              :comments => 'Committed by foo.'
162
            )
163 0:513646585e45 Chris
      assert_nil c.user
164
      @repository.committer_ids = {'foo' => '2'}
165
      assert_equal User.find(2), c.reload.user
166
      # committer is now mapped
167 441:cbce1fd3b1b7 Chris
      c = Changeset.create!(
168
              :repository => @repository,
169
              :committer => 'foo',
170
              :committed_on => Time.now,
171
              :revision => 101,
172
              :comments => 'Another commit by foo.'
173
            )
174 0:513646585e45 Chris
      assert_equal User.find(2), c.user
175
    end
176
  end
177 441:cbce1fd3b1b7 Chris
178 0:513646585e45 Chris
  def test_auto_user_mapping_by_username
179 441:cbce1fd3b1b7 Chris
    c = Changeset.create!(
180
          :repository   => @repository,
181
          :committer    => 'jsmith',
182
          :committed_on => Time.now,
183
          :revision     => 100,
184
          :comments     => 'Committed by john.'
185
        )
186 0:513646585e45 Chris
    assert_equal User.find(2), c.user
187
  end
188 441:cbce1fd3b1b7 Chris
189 0:513646585e45 Chris
  def test_auto_user_mapping_by_email
190 441:cbce1fd3b1b7 Chris
    c = Changeset.create!(
191
          :repository   => @repository,
192
          :committer    => 'john <jsmith@somenet.foo>',
193
          :committed_on => Time.now,
194
          :revision     => 100,
195
          :comments     => 'Committed by john.'
196
        )
197 0:513646585e45 Chris
    assert_equal User.find(2), c.user
198
  end
199 441:cbce1fd3b1b7 Chris
200
  def test_filesystem_avaialbe
201
    klass = Repository::Filesystem
202
    assert klass.scm_adapter_class
203
    assert_equal true, klass.scm_available
204
  end
205
206
  def test_merge_extra_info
207
    repo = Repository::Subversion.new(:project => Project.find(3))
208
    assert !repo.save
209
    repo.url = "svn://localhost"
210
    assert repo.save
211
    repo.reload
212
    project = Project.find(3)
213
    assert_equal repo, project.repository
214
    assert_nil repo.extra_info
215
    h1 = {"test_1" => {"test_11" => "test_value_11"}}
216
    repo.merge_extra_info(h1)
217
    assert_equal h1, repo.extra_info
218
    h2 = {"test_2" => {
219
                   "test_21" => "test_value_21",
220
                   "test_22" => "test_value_22",
221
                  }}
222
    repo.merge_extra_info(h2)
223
    assert_equal (h = {"test_11" => "test_value_11"}),
224
                 repo.extra_info["test_1"]
225
    assert_equal "test_value_21",
226
                 repo.extra_info["test_2"]["test_21"]
227
    h3 = {"test_2" => {
228
                   "test_23" => "test_value_23",
229
                   "test_24" => "test_value_24",
230
                  }}
231
    repo.merge_extra_info(h3)
232
    assert_equal (h = {"test_11" => "test_value_11"}),
233
                 repo.extra_info["test_1"]
234
    assert_nil repo.extra_info["test_2"]["test_21"]
235
    assert_equal "test_value_23",
236
                 repo.extra_info["test_2"]["test_23"]
237
  end
238 0:513646585e45 Chris
end