@@ -139,6 +139,7 class RepositoriesController < ApplicationController | |||||
139 | end |
|
139 | end | |
140 |
|
140 | |||
141 | def revision |
|
141 | def revision | |
|
142 | raise ChangesetNotFound if @rev.nil? || @rev.empty? | |||
142 | @changeset = @repository.find_changeset_by_name(@rev) |
|
143 | @changeset = @repository.find_changeset_by_name(@rev) | |
143 | raise ChangesetNotFound unless @changeset |
|
144 | raise ChangesetNotFound unless @changeset | |
144 |
|
145 |
@@ -94,6 +94,7 class Repository < ActiveRecord::Base | |||||
94 |
|
94 | |||
95 | # Finds and returns a revision with a number or the beginning of a hash |
|
95 | # Finds and returns a revision with a number or the beginning of a hash | |
96 | def find_changeset_by_name(name) |
|
96 | def find_changeset_by_name(name) | |
|
97 | return nil if name.nil? || name.empty? | |||
97 | changesets.find(:first, :conditions => (name.match(/^\d*$/) ? ["revision = ?", name.to_s] : ["revision LIKE ?", name + '%'])) |
|
98 | changesets.find(:first, :conditions => (name.match(/^\d*$/) ? ["revision = ?", name.to_s] : ["revision LIKE ?", name + '%'])) | |
98 | end |
|
99 | end | |
99 |
|
100 |
@@ -176,6 +176,26 class RepositoriesGitControllerTest < ActionController::TestCase | |||||
176 | assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ }, |
|
176 | assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ }, | |
177 | :content => /can not be annotated/ |
|
177 | :content => /can not be annotated/ | |
178 | end |
|
178 | end | |
|
179 | ||||
|
180 | def test_revision | |||
|
181 | @repository.fetch_changesets | |||
|
182 | @repository.reload | |||
|
183 | ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r| | |||
|
184 | get :revision, :id => 3, :rev => r | |||
|
185 | assert_response :success | |||
|
186 | assert_template 'revision' | |||
|
187 | end | |||
|
188 | end | |||
|
189 | ||||
|
190 | def test_empty_revision | |||
|
191 | @repository.fetch_changesets | |||
|
192 | @repository.reload | |||
|
193 | ['', ' ', nil].each do |r| | |||
|
194 | get :revision, :id => 1, :rev => r | |||
|
195 | assert_response 500 | |||
|
196 | assert_error_tag :content => /was not found/ | |||
|
197 | end | |||
|
198 | end | |||
179 | else |
|
199 | else | |
180 | puts "Git test repository NOT FOUND. Skipping functional tests !!!" |
|
200 | puts "Git test repository NOT FOUND. Skipping functional tests !!!" | |
181 | def test_fake; assert true end |
|
201 | def test_fake; assert true end |
@@ -171,7 +171,15 class RepositoriesSubversionControllerTest < ActionController::TestCase | |||||
171 | assert_response 500 |
|
171 | assert_response 500 | |
172 | assert_error_tag :content => /was not found/ |
|
172 | assert_error_tag :content => /was not found/ | |
173 | end |
|
173 | end | |
174 |
|
174 | |||
|
175 | def test_empty_revision | |||
|
176 | ['', ' ', nil].each do |r| | |||
|
177 | get :revision, :id => 1, :rev => r | |||
|
178 | assert_response 500 | |||
|
179 | assert_error_tag :content => /was not found/ | |||
|
180 | end | |||
|
181 | end | |||
|
182 | ||||
175 | def test_revision_with_repository_pointing_to_a_subdirectory |
|
183 | def test_revision_with_repository_pointing_to_a_subdirectory | |
176 | r = Project.find(1).repository |
|
184 | r = Project.find(1).repository | |
177 | # Changes repository url to a subdirectory |
|
185 | # Changes repository url to a subdirectory |
@@ -63,6 +63,23 class RepositoryGitTest < ActiveSupport::TestCase | |||||
63 | assert_equal 15, @repository.changesets.count |
|
63 | assert_equal 15, @repository.changesets.count | |
64 | end |
|
64 | end | |
65 |
|
65 | |||
|
66 | def test_find_changeset_by_name | |||
|
67 | @repository.fetch_changesets | |||
|
68 | @repository.reload | |||
|
69 | ['7234cb2750b63f47bff735edc50a1c0a433c2518', '7234cb2750b'].each do |r| | |||
|
70 | assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', | |||
|
71 | @repository.find_changeset_by_name(r).revision | |||
|
72 | end | |||
|
73 | end | |||
|
74 | ||||
|
75 | def test_find_changeset_by_empty_name | |||
|
76 | @repository.fetch_changesets | |||
|
77 | @repository.reload | |||
|
78 | ['', ' ', nil].each do |r| | |||
|
79 | assert_nil @repository.find_changeset_by_name(r) | |||
|
80 | end | |||
|
81 | end | |||
|
82 | ||||
66 | def test_identifier |
|
83 | def test_identifier | |
67 | @repository.fetch_changesets |
|
84 | @repository.fetch_changesets | |
68 | @repository.reload |
|
85 | @repository.reload |
@@ -96,6 +96,14 class RepositorySubversionTest < ActiveSupport::TestCase | |||||
96 | assert_equal c.revision, c.identifier |
|
96 | assert_equal c.revision, c.identifier | |
97 | end |
|
97 | end | |
98 |
|
98 | |||
|
99 | def test_find_changeset_by_empty_name | |||
|
100 | @repository.fetch_changesets | |||
|
101 | @repository.reload | |||
|
102 | ['', ' ', nil].each do |r| | |||
|
103 | assert_nil @repository.find_changeset_by_name(r) | |||
|
104 | end | |||
|
105 | end | |||
|
106 | ||||
99 | def test_identifier_nine_digit |
|
107 | def test_identifier_nine_digit | |
100 | c = Changeset.new(:repository => @repository, :committed_on => Time.now, |
|
108 | c = Changeset.new(:repository => @repository, :committed_on => Time.now, | |
101 | :revision => '123456789', :comments => 'test') |
|
109 | :revision => '123456789', :comments => 'test') |
General Comments 0
You need to be logged in to leave comments.
Login now