Revision 1297:0a574315af3e .svn/pristine/e0

View differences:

.svn/pristine/e0/e01726c21cab0c578f139014219d94cf009327c0.svn-base
1
# encoding: utf-8
2
#
3
# Redmine - project management software
4
# Copyright (C) 2006-2012  Jean-Philippe Lang
5
#
6
# This program is free software; you can redistribute it and/or
7
# modify it under the terms of the GNU General Public License
8
# as published by the Free Software Foundation; either version 2
9
# of the License, or (at your option) any later version.
10
#
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
# GNU General Public License for more details.
15
#
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
18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19

  
20
require File.expand_path('../../test_helper', __FILE__)
21

  
22
class WikiTest < ActiveSupport::TestCase
23
  fixtures :projects, :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions
24

  
25
  def test_create
26
    wiki = Wiki.new(:project => Project.find(2))
27
    assert !wiki.save
28
    assert_equal 1, wiki.errors.count
29

  
30
    wiki.start_page = "Start page"
31
    assert wiki.save
32
  end
33

  
34
  def test_update
35
    @wiki = Wiki.find(1)
36
    @wiki.start_page = "Another start page"
37
    assert @wiki.save
38
    @wiki.reload
39
    assert_equal "Another start page", @wiki.start_page
40
  end
41

  
42
  def test_find_page_should_not_be_case_sensitive
43
    wiki = Wiki.find(1)
44
    page = WikiPage.find(2)
45

  
46
    assert_equal page, wiki.find_page('Another_page')
47
    assert_equal page, wiki.find_page('Another page')
48
    assert_equal page, wiki.find_page('ANOTHER page')
49
  end
50

  
51
  def test_find_page_with_cyrillic_characters
52
    wiki = Wiki.find(1)
53
    page = WikiPage.find(10)
54
    assert_equal page, wiki.find_page('Этика_менеджмента')
55
  end
56

  
57
  def test_find_page_with_backslashes
58
    wiki = Wiki.find(1)
59
    page = WikiPage.create!(:wiki => wiki, :title => '2009\\02\\09')
60
    assert_equal page, wiki.find_page('2009\\02\\09')
61
  end
62

  
63
  def test_find_page_without_redirect
64
    wiki = Wiki.find(1)
65
    page = wiki.find_page('Another_page')
66
    assert_not_nil page
67
    assert_equal 'Another_page', page.title
68
    assert_equal false, wiki.page_found_with_redirect?
69
  end
70

  
71
  def test_find_page_with_redirect
72
    wiki = Wiki.find(1)
73
    WikiRedirect.create!(:wiki => wiki, :title => 'Old_title', :redirects_to => 'Another_page')
74
    page = wiki.find_page('Old_title')
75
    assert_not_nil page
76
    assert_equal 'Another_page', page.title
77
    assert_equal true, wiki.page_found_with_redirect?
78
  end
79

  
80
  def test_titleize
81
    ja_test = "\xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88"
82
    ja_test.force_encoding('UTF-8') if ja_test.respond_to?(:force_encoding)
83
    assert_equal 'Page_title_with_CAPITALES', Wiki.titleize('page title with CAPITALES')
84
    assert_equal ja_test, Wiki.titleize(ja_test)
85
  end
86

  
87
  context "#sidebar" do
88
    setup do
89
      @wiki = Wiki.find(1)
90
    end
91

  
92
    should "return nil if undefined" do
93
      assert_nil @wiki.sidebar
94
    end
95

  
96
    should "return a WikiPage if defined" do
97
      page = @wiki.pages.new(:title => 'Sidebar')
98
      page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar')
99
      page.save!
100

  
101
      assert_kind_of WikiPage, @wiki.sidebar
102
      assert_equal 'Sidebar', @wiki.sidebar.title
103
    end
104
  end
105
end
.svn/pristine/e0/e06570dead65e856ab4e7a692d4d40feaa2a817f.svn-base
1
# Redmine - project management software
2
# Copyright (C) 2006-2012  Jean-Philippe Lang
3
#
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
#
9
# 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
#
14
# 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
require File.expand_path('../../../../../../test_helper', __FILE__)
19

  
20
class FilesystemAdapterTest < ActiveSupport::TestCase
21
  REPOSITORY_PATH = Rails.root.join('tmp/test/filesystem_repository').to_s
22

  
23
  if File.directory?(REPOSITORY_PATH)
24
    def setup
25
      @adapter = Redmine::Scm::Adapters::FilesystemAdapter.new(REPOSITORY_PATH)
26
    end
27

  
28
    def test_entries
29
      assert_equal 3, @adapter.entries.size
30
      assert_equal ["dir", "japanese", "test"], @adapter.entries.collect(&:name)
31
      assert_equal ["dir", "japanese", "test"], @adapter.entries(nil).collect(&:name)
32
      assert_equal ["dir", "japanese", "test"], @adapter.entries("/").collect(&:name)
33
      ["dir", "/dir", "/dir/", "dir/"].each do |path|
34
        assert_equal ["subdir", "dirfile"], @adapter.entries(path).collect(&:name)
35
      end
36
      # If y try to use "..", the path is ignored
37
      ["/../","dir/../", "..", "../", "/..", "dir/.."].each do |path|
38
        assert_equal ["dir", "japanese", "test"], @adapter.entries(path).collect(&:name),
39
             ".. must be ignored in path argument"
40
      end
41
    end
42

  
43
    def test_cat
44
      assert_equal "TEST CAT\n", @adapter.cat("test")
45
      assert_equal "TEST CAT\n", @adapter.cat("/test")
46
      # Revision number is ignored
47
      assert_equal "TEST CAT\n", @adapter.cat("/test", 1)
48
    end
49

  
50
    def test_path_encoding_default_utf8
51
      adpt1 = Redmine::Scm::Adapters::FilesystemAdapter.new(
52
                                  REPOSITORY_PATH
53
                                )
54
      assert_equal "UTF-8", adpt1.path_encoding
55
      adpt2 = Redmine::Scm::Adapters::FilesystemAdapter.new(
56
                                  REPOSITORY_PATH,
57
                                  nil,
58
                                  nil,
59
                                  nil,
60
                                  ""
61
                                )
62
      assert_equal "UTF-8", adpt2.path_encoding
63
    end
64
  else
65
    puts "Filesystem test repository NOT FOUND. Skipping unit tests !!! See doc/RUNNING_TESTS."
66
    def test_fake; assert true end
67
  end
68
end
.svn/pristine/e0/e093b9d78570bf6232d33bfa16bb621c9df74060.svn-base
1
<h2><%=l(:label_news_new)%></h2>
2

  
3
<%= labelled_form_for @news, :url => project_news_index_path(@project),
4
                                           :html => { :id => 'news-form', :multipart => true } do |f| %>
5
  <%= render :partial => 'news/form', :locals => { :f => f } %>
6
  <%= submit_tag l(:button_create) %>
7
  <%= preview_link preview_news_path(:project_id => @project), 'news-form' %>
8
<% end %>
9
<div id="preview" class="wiki"></div>
.svn/pristine/e0/e0bfac3426b697cd8e4386853697da2b7b05ee97.svn-base
1
# Redmine - project management software
2
# Copyright (C) 2006-2012  Jean-Philippe Lang
3
#
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
#
9
# 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
#
14
# 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
desc <<-END_DESC
19
Send reminders about issues due in the next days.
20

  
21
Available options:
22
  * days     => number of days to remind about (defaults to 7)
23
  * tracker  => id of tracker (defaults to all trackers)
24
  * project  => id or identifier of project (defaults to all projects)
25
  * users    => comma separated list of user/group ids who should be reminded
26

  
27
Example:
28
  rake redmine:send_reminders days=7 users="1,23, 56" RAILS_ENV="production"
29
END_DESC
30

  
31
namespace :redmine do
32
  task :send_reminders => :environment do
33
    options = {}
34
    options[:days] = ENV['days'].to_i if ENV['days']
35
    options[:project] = ENV['project'] if ENV['project']
36
    options[:tracker] = ENV['tracker'].to_i if ENV['tracker']
37
    options[:users] = (ENV['users'] || '').split(',').each(&:strip!)
38

  
39
    Mailer.with_synched_deliveries do
40
      Mailer.reminders(options)
41
    end
42
  end
43
end
.svn/pristine/e0/e0e435737c34d733170967e072de8e1e632a4bfa.svn-base
1
# Redmine - project management software
2
# Copyright (C) 2006-2012  Jean-Philippe Lang
3
#
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
#
9
# 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
#
14
# 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
require File.expand_path('../../test_helper', __FILE__)
19

  
20
class RepositoryGitTest < ActiveSupport::TestCase
21
  fixtures :projects, :repositories, :enabled_modules, :users, :roles
22

  
23
  include Redmine::I18n
24

  
25
  REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s
26
  REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
27

  
28
  NUM_REV = 28
29
  NUM_HEAD = 6
30

  
31
  FELIX_HEX  = "Felix Sch\xC3\xA4fer"
32
  CHAR_1_HEX = "\xc3\x9c"
33

  
34
  ## Git, Mercurial and CVS path encodings are binary.
35
  ## Subversion supports URL encoding for path.
36
  ## Redmine Mercurial adapter and extension use URL encoding.
37
  ## Git accepts only binary path in command line parameter.
38
  ## So, there is no way to use binary command line parameter in JRuby.
39
  JRUBY_SKIP     = (RUBY_PLATFORM == 'java')
40
  JRUBY_SKIP_STR = "TODO: This test fails in JRuby"
41

  
42
  def setup
43
    @project = Project.find(3)
44
    @repository = Repository::Git.create(
45
                        :project       => @project,
46
                        :url           => REPOSITORY_PATH,
47
                        :path_encoding => 'ISO-8859-1'
48
                        )
49
    assert @repository
50
    @char_1        = CHAR_1_HEX.dup
51
    if @char_1.respond_to?(:force_encoding)
52
      @char_1.force_encoding('UTF-8')
53
    end
54
  end
55

  
56
  def test_blank_path_to_repository_error_message
57
    set_language_if_valid 'en'
58
    repo = Repository::Git.new(
59
                          :project      => @project,
60
                          :identifier   => 'test'
61
                        )
62
    assert !repo.save
63
    assert_include "Path to repository can't be blank",
64
                   repo.errors.full_messages
65
  end
66

  
67
  def test_blank_path_to_repository_error_message_fr
68
    set_language_if_valid 'fr'
69
    str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)"
70
    str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
71
    repo = Repository::Git.new(
72
                          :project      => @project,
73
                          :url          => "",
74
                          :identifier   => 'test',
75
                          :path_encoding => ''
76
                        )
77
    assert !repo.save
78
    assert_include str, repo.errors.full_messages
79
  end
80

  
81
  if File.directory?(REPOSITORY_PATH)
82
    ## Ruby uses ANSI api to fork a process on Windows.
83
    ## Japanese Shift_JIS and Traditional Chinese Big5 have 0x5c(backslash) problem
84
    ## and these are incompatible with ASCII.
85
    ## Git for Windows (msysGit) changed internal API from ANSI to Unicode in 1.7.10
86
    ## http://code.google.com/p/msysgit/issues/detail?id=80
87
    ## So, Latin-1 path tests fail on Japanese Windows
88
    WINDOWS_PASS = (Redmine::Platform.mswin? &&
89
                         Redmine::Scm::Adapters::GitAdapter.client_version_above?([1, 7, 10]))
90
    WINDOWS_SKIP_STR = "TODO: This test fails in Git for Windows above 1.7.10"
91

  
92
    def test_scm_available
93
      klass = Repository::Git
94
      assert_equal "Git", klass.scm_name
95
      assert klass.scm_adapter_class
96
      assert_not_equal "", klass.scm_command
97
      assert_equal true, klass.scm_available
98
    end
99

  
100
    def test_entries
101
      entries = @repository.entries
102
      assert_kind_of Redmine::Scm::Adapters::Entries, entries
103
    end
104

  
105
    def test_fetch_changesets_from_scratch
106
      assert_nil @repository.extra_info
107

  
108
      assert_equal 0, @repository.changesets.count
109
      @repository.fetch_changesets
110
      @project.reload
111

  
112
      assert_equal NUM_REV, @repository.changesets.count
113
      assert_equal 39, @repository.filechanges.count
114

  
115
      commit = @repository.changesets.find_by_revision("7234cb2750b63f47bff735edc50a1c0a433c2518")
116
      assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", commit.scmid
117
      assert_equal "Initial import.\nThe repository contains 3 files.", commit.comments
118
      assert_equal "jsmith <jsmith@foo.bar>", commit.committer
119
      assert_equal User.find_by_login('jsmith'), commit.user
120
      # TODO: add a commit with commit time <> author time to the test repository
121
      assert_equal "2007-12-14 09:22:52".to_time, commit.committed_on
122
      assert_equal "2007-12-14".to_date, commit.commit_date
123
      assert_equal 3, commit.filechanges.count
124
      change = commit.filechanges.sort_by(&:path).first
125
      assert_equal "README", change.path
126
      assert_equal nil, change.from_path
127
      assert_equal "A", change.action
128

  
129
      assert_equal NUM_HEAD, @repository.extra_info["heads"].size
130
    end
131

  
132
    def test_fetch_changesets_incremental
133
      assert_equal 0, @repository.changesets.count
134
      @repository.fetch_changesets
135
      @project.reload
136
      assert_equal NUM_REV, @repository.changesets.count
137
      extra_info_heads = @repository.extra_info["heads"].dup
138
      assert_equal NUM_HEAD, extra_info_heads.size
139
      extra_info_heads.delete_if { |x| x == "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c" }
140
      assert_equal 4, extra_info_heads.size
141

  
142
      del_revs = [
143
          "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
144
          "ed5bb786bbda2dee66a2d50faf51429dbc043a7b",
145
          "4f26664364207fa8b1af9f8722647ab2d4ac5d43",
146
          "deff712f05a90d96edbd70facc47d944be5897e3",
147
          "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf",
148
          "7e61ac704deecde634b51e59daa8110435dcb3da",
149
         ]
150
      @repository.changesets.each do |rev|
151
        rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s }
152
      end
153
      @project.reload
154
      cs1 = @repository.changesets
155
      assert_equal NUM_REV - 6, cs1.count
156
      extra_info_heads << "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8"
157
      h = {}
158
      h["heads"] = extra_info_heads
159
      @repository.merge_extra_info(h)
160
      @repository.save
161
      @project.reload
162
      assert @repository.extra_info["heads"].index("4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8")
163
      @repository.fetch_changesets
164
      @project.reload
165
      assert_equal NUM_REV, @repository.changesets.count
166
      assert_equal NUM_HEAD, @repository.extra_info["heads"].size
167
      assert @repository.extra_info["heads"].index("83ca5fd546063a3c7dc2e568ba3355661a9e2b2c")
168
    end
169

  
170
    def test_fetch_changesets_history_editing
171
      assert_equal 0, @repository.changesets.count
172
      @repository.fetch_changesets
173
      @project.reload
174
      assert_equal NUM_REV, @repository.changesets.count
175
      extra_info_heads = @repository.extra_info["heads"].dup
176
      assert_equal NUM_HEAD, extra_info_heads.size
177
      extra_info_heads.delete_if { |x| x == "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c" }
178
      assert_equal 4, extra_info_heads.size
179

  
180
      del_revs = [
181
          "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
182
          "ed5bb786bbda2dee66a2d50faf51429dbc043a7b",
183
          "4f26664364207fa8b1af9f8722647ab2d4ac5d43",
184
          "deff712f05a90d96edbd70facc47d944be5897e3",
185
          "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf",
186
          "7e61ac704deecde634b51e59daa8110435dcb3da",
187
         ]
188
      @repository.changesets.each do |rev|
189
        rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s }
190
      end
191
      @project.reload
192
      assert_equal NUM_REV - 6, @repository.changesets.count
193

  
194
      c = Changeset.new(:repository   => @repository,
195
                        :committed_on => Time.now,
196
                        :revision     => "abcd1234efgh",
197
                        :scmid        => "abcd1234efgh",
198
                        :comments     => 'test')
199
      assert c.save
200
      @project.reload
201
      assert_equal NUM_REV - 5, @repository.changesets.count
202

  
203
      extra_info_heads << "1234abcd5678"
204
      h = {}
205
      h["heads"] = extra_info_heads
206
      @repository.merge_extra_info(h)
207
      @repository.save
208
      @project.reload
209
      h1 = @repository.extra_info["heads"].dup
210
      assert h1.index("1234abcd5678")
211
      assert_equal 5, h1.size
212

  
213
      @repository.fetch_changesets
214
      @project.reload
215
      assert_equal NUM_REV - 5, @repository.changesets.count
216
      h2 = @repository.extra_info["heads"].dup
217
      assert_equal h1, h2
218
    end
219

  
220
    def test_keep_extra_report_last_commit_in_clear_changesets
221
      assert_nil @repository.extra_info
222
      h = {}
223
      h["extra_report_last_commit"] = "1"
224
      @repository.merge_extra_info(h)
225
      @repository.save
226
      @project.reload
227

  
228
      assert_equal 0, @repository.changesets.count
229
      @repository.fetch_changesets
230
      @project.reload
231

  
232
      assert_equal NUM_REV, @repository.changesets.count
233
      @repository.send(:clear_changesets)
234
      assert_equal 1, @repository.extra_info.size
235
      assert_equal "1", @repository.extra_info["extra_report_last_commit"]
236
    end
237

  
238
    def test_refetch_after_clear_changesets
239
      assert_nil @repository.extra_info
240
      assert_equal 0, @repository.changesets.count
241
      @repository.fetch_changesets
242
      @project.reload
243
      assert_equal NUM_REV, @repository.changesets.count
244

  
245
      @repository.send(:clear_changesets)
246
      @project.reload
247
      assert_equal 0, @repository.changesets.count
248

  
249
      @repository.fetch_changesets
250
      @project.reload
251
      assert_equal NUM_REV, @repository.changesets.count
252
    end
253

  
254
    def test_parents
255
      assert_equal 0, @repository.changesets.count
256
      @repository.fetch_changesets
257
      @project.reload
258
      assert_equal NUM_REV, @repository.changesets.count
259
      r1 = @repository.find_changeset_by_name("7234cb2750b63")
260
      assert_equal [], r1.parents
261
      r2 = @repository.find_changeset_by_name("899a15dba03a3")
262
      assert_equal 1, r2.parents.length
263
      assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518",
264
                   r2.parents[0].identifier
265
      r3 = @repository.find_changeset_by_name("32ae898b720c2")
266
      assert_equal 2, r3.parents.length
267
      r4 = [r3.parents[0].identifier, r3.parents[1].identifier].sort
268
      assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", r4[0]
269
      assert_equal "7e61ac704deecde634b51e59daa8110435dcb3da", r4[1]
270
    end
271

  
272
    def test_db_consistent_ordering_init
273
      assert_nil @repository.extra_info
274
      assert_equal 0, @repository.changesets.count
275
      @repository.fetch_changesets
276
      @project.reload
277
      assert_equal 1, @repository.extra_info["db_consistent"]["ordering"]
278
    end
279

  
280
    def test_db_consistent_ordering_before_1_2
281
      assert_nil @repository.extra_info
282
      assert_equal 0, @repository.changesets.count
283
      @repository.fetch_changesets
284
      @project.reload
285
      assert_equal NUM_REV, @repository.changesets.count
286
      assert_not_nil @repository.extra_info
287
      h = {}
288
      h["heads"] = []
289
      h["branches"] = {}
290
      h["db_consistent"] = {}
291
      @repository.merge_extra_info(h)
292
      @repository.save
293
      assert_equal NUM_REV, @repository.changesets.count
294
      @repository.fetch_changesets
295
      @project.reload
296
      assert_equal 0, @repository.extra_info["db_consistent"]["ordering"]
297

  
298
      extra_info_heads = @repository.extra_info["heads"].dup
299
      extra_info_heads.delete_if { |x| x == "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c" }
300
      del_revs = [
301
          "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
302
          "ed5bb786bbda2dee66a2d50faf51429dbc043a7b",
303
          "4f26664364207fa8b1af9f8722647ab2d4ac5d43",
304
          "deff712f05a90d96edbd70facc47d944be5897e3",
305
          "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf",
306
          "7e61ac704deecde634b51e59daa8110435dcb3da",
307
         ]
308
      @repository.changesets.each do |rev|
309
        rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s }
310
      end
311
      @project.reload
312
      cs1 = @repository.changesets
313
      assert_equal NUM_REV - 6, cs1.count
314
      assert_equal 0, @repository.extra_info["db_consistent"]["ordering"]
315

  
316
      extra_info_heads << "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8"
317
      h = {}
318
      h["heads"] = extra_info_heads
319
      @repository.merge_extra_info(h)
320
      @repository.save
321
      @project.reload
322
      assert @repository.extra_info["heads"].index("4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8")
323
      @repository.fetch_changesets
324
      @project.reload
325
      assert_equal NUM_REV, @repository.changesets.count
326
      assert_equal NUM_HEAD, @repository.extra_info["heads"].size
327

  
328
      assert_equal 0, @repository.extra_info["db_consistent"]["ordering"]
329
    end
330

  
331
    def test_heads_from_branches_hash
332
      assert_nil @repository.extra_info
333
      assert_equal 0, @repository.changesets.count
334
      assert_equal [], @repository.heads_from_branches_hash
335
      h = {}
336
      h["branches"] = {}
337
      h["branches"]["test1"] = {}
338
      h["branches"]["test1"]["last_scmid"] = "1234abcd"
339
      h["branches"]["test2"] = {}
340
      h["branches"]["test2"]["last_scmid"] = "abcd1234"
341
      @repository.merge_extra_info(h)
342
      @repository.save
343
      @project.reload
344
      assert_equal ["1234abcd", "abcd1234"], @repository.heads_from_branches_hash.sort
345
    end
346

  
347
    def test_latest_changesets
348
      assert_equal 0, @repository.changesets.count
349
      @repository.fetch_changesets
350
      @project.reload
351
      assert_equal NUM_REV, @repository.changesets.count
352
      # with limit
353
      changesets = @repository.latest_changesets('', 'master', 2)
354
      assert_equal 2, changesets.size
355

  
356
      # with path
357
      changesets = @repository.latest_changesets('images', 'master')
358
      assert_equal [
359
              'deff712f05a90d96edbd70facc47d944be5897e3',
360
              '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
361
              '7234cb2750b63f47bff735edc50a1c0a433c2518',
362
          ], changesets.collect(&:revision)
363

  
364
      changesets = @repository.latest_changesets('README', nil)
365
      assert_equal [
366
              '32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf',
367
              '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8',
368
              '713f4944648826f558cf548222f813dabe7cbb04',
369
              '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
370
              '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
371
              '7234cb2750b63f47bff735edc50a1c0a433c2518',
372
          ], changesets.collect(&:revision)
373

  
374
      # with path, revision and limit
375
      changesets = @repository.latest_changesets('images', '899a15dba')
376
      assert_equal [
377
              '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
378
              '7234cb2750b63f47bff735edc50a1c0a433c2518',
379
          ], changesets.collect(&:revision)
380

  
381
      changesets = @repository.latest_changesets('images', '899a15dba', 1)
382
      assert_equal [
383
              '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
384
          ], changesets.collect(&:revision)
385

  
386
      changesets = @repository.latest_changesets('README', '899a15dba')
387
      assert_equal [
388
              '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
389
              '7234cb2750b63f47bff735edc50a1c0a433c2518',
390
          ], changesets.collect(&:revision)
391

  
392
      changesets = @repository.latest_changesets('README', '899a15dba', 1)
393
      assert_equal [
394
              '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
395
          ], changesets.collect(&:revision)
396

  
397
      # with path, tag and limit
398
      changesets = @repository.latest_changesets('images', 'tag01.annotated')
399
      assert_equal [
400
              '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
401
              '7234cb2750b63f47bff735edc50a1c0a433c2518',
402
          ], changesets.collect(&:revision)
403

  
404
      changesets = @repository.latest_changesets('images', 'tag01.annotated', 1)
405
      assert_equal [
406
              '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
407
          ], changesets.collect(&:revision)
408

  
409
      changesets = @repository.latest_changesets('README', 'tag01.annotated')
410
      assert_equal [
411
              '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
412
              '7234cb2750b63f47bff735edc50a1c0a433c2518',
413
          ], changesets.collect(&:revision)
414

  
415
      changesets = @repository.latest_changesets('README', 'tag01.annotated', 1)
416
      assert_equal [
417
              '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
418
          ], changesets.collect(&:revision)
419

  
420
      # with path, branch and limit
421
      changesets = @repository.latest_changesets('images', 'test_branch')
422
      assert_equal [
423
              '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
424
              '7234cb2750b63f47bff735edc50a1c0a433c2518',
425
          ], changesets.collect(&:revision)
426

  
427
      changesets = @repository.latest_changesets('images', 'test_branch', 1)
428
      assert_equal [
429
              '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
430
          ], changesets.collect(&:revision)
431

  
432
      changesets = @repository.latest_changesets('README', 'test_branch')
433
      assert_equal [
434
              '713f4944648826f558cf548222f813dabe7cbb04',
435
              '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
436
              '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
437
              '7234cb2750b63f47bff735edc50a1c0a433c2518',
438
          ], changesets.collect(&:revision)
439

  
440
      changesets = @repository.latest_changesets('README', 'test_branch', 2)
441
      assert_equal [
442
              '713f4944648826f558cf548222f813dabe7cbb04',
443
              '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
444
          ], changesets.collect(&:revision)
445

  
446
      if WINDOWS_PASS
447
        puts WINDOWS_SKIP_STR
448
      elsif JRUBY_SKIP
449
        puts JRUBY_SKIP_STR
450
      else
451
        # latin-1 encoding path
452
        changesets = @repository.latest_changesets(
453
                      "latin-1-dir/test-#{@char_1}-2.txt", '64f1f3e89')
454
        assert_equal [
455
              '64f1f3e89ad1cb57976ff0ad99a107012ba3481d',
456
              '4fc55c43bf3d3dc2efb66145365ddc17639ce81e',
457
          ], changesets.collect(&:revision)
458

  
459
        changesets = @repository.latest_changesets(
460
                    "latin-1-dir/test-#{@char_1}-2.txt", '64f1f3e89', 1)
461
        assert_equal [
462
              '64f1f3e89ad1cb57976ff0ad99a107012ba3481d',
463
          ], changesets.collect(&:revision)
464
      end
465
    end
466

  
467
    def test_latest_changesets_latin_1_dir
468
      if WINDOWS_PASS
469
        puts WINDOWS_SKIP_STR
470
      elsif JRUBY_SKIP
471
        puts JRUBY_SKIP_STR
472
      else
473
        assert_equal 0, @repository.changesets.count
474
        @repository.fetch_changesets
475
        @project.reload
476
        assert_equal NUM_REV, @repository.changesets.count
477
        changesets = @repository.latest_changesets(
478
                    "latin-1-dir/test-#{@char_1}-subdir", '1ca7f5ed')
479
        assert_equal [
480
              '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127',
481
          ], changesets.collect(&:revision)
482
      end
483
    end
484

  
485
    def test_find_changeset_by_name
486
      assert_equal 0, @repository.changesets.count
487
      @repository.fetch_changesets
488
      @project.reload
489
      assert_equal NUM_REV, @repository.changesets.count
490
      ['7234cb2750b63f47bff735edc50a1c0a433c2518', '7234cb2750b'].each do |r|
491
        assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518',
492
                     @repository.find_changeset_by_name(r).revision
493
      end
494
    end
495

  
496
    def test_find_changeset_by_empty_name
497
      assert_equal 0, @repository.changesets.count
498
      @repository.fetch_changesets
499
      @project.reload
500
      assert_equal NUM_REV, @repository.changesets.count
501
      ['', ' ', nil].each do |r|
502
        assert_nil @repository.find_changeset_by_name(r)
503
      end
504
    end
505

  
506
    def test_identifier
507
      assert_equal 0, @repository.changesets.count
508
      @repository.fetch_changesets
509
      @project.reload
510
      assert_equal NUM_REV, @repository.changesets.count
511
      c = @repository.changesets.find_by_revision(
512
                          '7234cb2750b63f47bff735edc50a1c0a433c2518')
513
      assert_equal c.scmid, c.identifier
514
    end
515

  
516
    def test_format_identifier
517
      assert_equal 0, @repository.changesets.count
518
      @repository.fetch_changesets
519
      @project.reload
520
      assert_equal NUM_REV, @repository.changesets.count
521
      c = @repository.changesets.find_by_revision(
522
                          '7234cb2750b63f47bff735edc50a1c0a433c2518')
523
      assert_equal '7234cb27', c.format_identifier
524
    end
525

  
526
    def test_activities
527
      c = Changeset.new(:repository => @repository,
528
                        :committed_on => Time.now,
529
                        :revision => 'abc7234cb2750b63f47bff735edc50a1c0a433c2',
530
                        :scmid    => 'abc7234cb2750b63f47bff735edc50a1c0a433c2',
531
                        :comments => 'test')
532
      assert c.event_title.include?('abc7234c:')
533
      assert_equal 'abc7234cb2750b63f47bff735edc50a1c0a433c2', c.event_url[:rev]
534
    end
535

  
536
    def test_log_utf8
537
      assert_equal 0, @repository.changesets.count
538
      @repository.fetch_changesets
539
      @project.reload
540
      assert_equal NUM_REV, @repository.changesets.count
541
      str_felix_hex  = FELIX_HEX.dup
542
      if str_felix_hex.respond_to?(:force_encoding)
543
          str_felix_hex.force_encoding('UTF-8')
544
      end
545
      c = @repository.changesets.find_by_revision(
546
                        'ed5bb786bbda2dee66a2d50faf51429dbc043a7b')
547
      assert_equal "#{str_felix_hex} <felix@fachschaften.org>", c.committer
548
    end
549

  
550
    def test_previous
551
      assert_equal 0, @repository.changesets.count
552
      @repository.fetch_changesets
553
      @project.reload
554
      assert_equal NUM_REV, @repository.changesets.count
555
      %w|1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127 1ca7f5ed|.each do |r1|
556
        changeset = @repository.find_changeset_by_name(r1)
557
        %w|64f1f3e89ad1cb57976ff0ad99a107012ba3481d 64f1f3e89ad1|.each do |r2|
558
          assert_equal @repository.find_changeset_by_name(r2), changeset.previous
559
        end
560
      end
561
    end
562

  
563
    def test_previous_nil
564
      assert_equal 0, @repository.changesets.count
565
      @repository.fetch_changesets
566
      @project.reload
567
      assert_equal NUM_REV, @repository.changesets.count
568
      %w|7234cb2750b63f47bff735edc50a1c0a433c2518 7234cb275|.each do |r1|
569
        changeset = @repository.find_changeset_by_name(r1)
570
        assert_nil changeset.previous
571
      end
572
    end
573

  
574
    def test_next
575
      assert_equal 0, @repository.changesets.count
576
      @repository.fetch_changesets
577
      @project.reload
578
      assert_equal NUM_REV, @repository.changesets.count
579
      %w|64f1f3e89ad1cb57976ff0ad99a107012ba3481d 64f1f3e89ad1|.each do |r2|
580
        changeset = @repository.find_changeset_by_name(r2)
581
        %w|1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127 1ca7f5ed|.each do |r1|
582
        assert_equal @repository.find_changeset_by_name(r1), changeset.next
583
        end
584
      end
585
    end
586

  
587
    def test_next_nil
588
      assert_equal 0, @repository.changesets.count
589
      @repository.fetch_changesets
590
      @project.reload
591
      assert_equal NUM_REV, @repository.changesets.count
592
      %w|2a682156a3b6e77a8bf9cd4590e8db757f3c6c78 2a682156a3b6e77a|.each do |r1|
593
        changeset = @repository.find_changeset_by_name(r1)
594
        assert_nil changeset.next
595
      end
596
    end
597
  else
598
    puts "Git test repository NOT FOUND. Skipping unit tests !!!"
599
    def test_fake; assert true end
600
  end
601
end

Also available in: Unified diff