@@ -55,6 +55,17 class Repository::Mercurial < Repository | |||||
55 | entries |
|
55 | entries | |
56 | end |
|
56 | end | |
57 |
|
57 | |||
|
58 | # Finds and returns a revision with a number or the beginning of a hash | |||
|
59 | def find_changeset_by_name(name) | |||
|
60 | if /[^\d]/ =~ name or name.to_s.size > 8 | |||
|
61 | e = changesets.find(:first, :conditions => ['scmid = ?', name.to_s]) | |||
|
62 | else | |||
|
63 | e = changesets.find(:first, :conditions => ['revision = ?', name.to_s]) | |||
|
64 | end | |||
|
65 | return e if e | |||
|
66 | changesets.find(:first, :conditions => ['scmid LIKE ?', "#{name}%"]) # last ditch | |||
|
67 | end | |||
|
68 | ||||
58 | # Returns the latest changesets for +path+; sorted by revision number |
|
69 | # Returns the latest changesets for +path+; sorted by revision number | |
59 | def latest_changesets(path, rev, limit=10) |
|
70 | def latest_changesets(path, rev, limit=10) | |
60 | if path.blank? |
|
71 | if path.blank? |
@@ -47,6 +47,17 begin | |||||
47 | assert_nil @adapter.cat("sources/welcome_controller.rb") |
|
47 | assert_nil @adapter.cat("sources/welcome_controller.rb") | |
48 | end |
|
48 | end | |
49 |
|
49 | |||
|
50 | def test_access_by_nodeid | |||
|
51 | path = 'sources/welcome_controller.rb' | |||
|
52 | assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400bb8672109') | |||
|
53 | end | |||
|
54 | ||||
|
55 | def test_access_by_fuzzy_nodeid | |||
|
56 | path = 'sources/welcome_controller.rb' | |||
|
57 | # falls back to nodeid | |||
|
58 | assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400') | |||
|
59 | end | |||
|
60 | ||||
50 | private |
|
61 | private | |
51 |
|
62 | |||
52 | def test_hgversion_for(hgversion, version) |
|
63 | def test_hgversion_for(hgversion, version) |
@@ -35,7 +35,8 class RepositoryMercurialTest < ActiveSupport::TestCase | |||||
35 |
|
35 | |||
36 | assert_equal 17, @repository.changesets.count |
|
36 | assert_equal 17, @repository.changesets.count | |
37 | assert_equal 25, @repository.changes.count |
|
37 | assert_equal 25, @repository.changes.count | |
38 |
assert_equal "Initial import.\nThe repository contains 3 files.", |
|
38 | assert_equal "Initial import.\nThe repository contains 3 files.", | |
|
39 | @repository.changesets.find_by_revision('0').comments | |||
39 | end |
|
40 | end | |
40 |
|
41 | |||
41 | def test_fetch_changesets_incremental |
|
42 | def test_fetch_changesets_incremental | |
@@ -51,7 +52,9 class RepositoryMercurialTest < ActiveSupport::TestCase | |||||
51 |
|
52 | |||
52 | def test_entries |
|
53 | def test_entries | |
53 | assert_equal 2, @repository.entries("sources", 2).size |
|
54 | assert_equal 2, @repository.entries("sources", 2).size | |
|
55 | assert_equal 2, @repository.entries("sources", '400bb8672109').size | |||
54 | assert_equal 1, @repository.entries("sources", 3).size |
|
56 | assert_equal 1, @repository.entries("sources", 3).size | |
|
57 | assert_equal 1, @repository.entries("sources", 'b3a615152df8').size | |||
55 | end |
|
58 | end | |
56 |
|
59 | |||
57 | def test_locate_on_outdated_repository |
|
60 | def test_locate_on_outdated_repository | |
@@ -122,6 +125,20 class RepositoryMercurialTest < ActiveSupport::TestCase | |||||
122 | assert_equal '/README (1)[2]&,%.-3_4', c2[0].path |
|
125 | assert_equal '/README (1)[2]&,%.-3_4', c2[0].path | |
123 | assert_equal '/README', c2[0].from_path |
|
126 | assert_equal '/README', c2[0].from_path | |
124 | end |
|
127 | end | |
|
128 | ||||
|
129 | def test_find_changeset_by_name | |||
|
130 | @repository.fetch_changesets | |||
|
131 | @repository.reload | |||
|
132 | %w|2 400bb8672109 400|.each do |r| | |||
|
133 | assert_equal @repository.find_changeset_by_name(r).revision, '2' | |||
|
134 | end | |||
|
135 | end | |||
|
136 | ||||
|
137 | def test_find_changeset_by_invalid_name | |||
|
138 | @repository.fetch_changesets | |||
|
139 | @repository.reload | |||
|
140 | assert_nil @repository.find_changeset_by_name('100000') | |||
|
141 | end | |||
125 | else |
|
142 | else | |
126 | puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!" |
|
143 | puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!" | |
127 | def test_fake; assert true end |
|
144 | def test_fake; assert true end |
General Comments 0
You need to be logged in to leave comments.
Login now