@@ -19,4 +19,8 class Change < ActiveRecord::Base | |||||
19 | belongs_to :changeset |
|
19 | belongs_to :changeset | |
20 |
|
20 | |||
21 | validates_presence_of :changeset_id, :action, :path |
|
21 | validates_presence_of :changeset_id, :action, :path | |
|
22 | ||||
|
23 | def relative_path | |||
|
24 | changeset.repository.relative_path(path) | |||
|
25 | end | |||
22 | end |
|
26 | end |
@@ -64,6 +64,11 class Repository < ActiveRecord::Base | |||||
64 | :order => "committed_on DESC, #{Changeset.table_name}.id DESC").collect(&:changeset) |
|
64 | :order => "committed_on DESC, #{Changeset.table_name}.id DESC").collect(&:changeset) | |
65 | end |
|
65 | end | |
66 |
|
66 | |||
|
67 | # Returns a path relative to the url of the repository | |||
|
68 | def relative_path(path) | |||
|
69 | path | |||
|
70 | end | |||
|
71 | ||||
67 | def latest_changeset |
|
72 | def latest_changeset | |
68 | @latest_changeset ||= changesets.find(:first) |
|
73 | @latest_changeset ||= changesets.find(:first) | |
69 | end |
|
74 | end |
@@ -35,6 +35,11 class Repository::Subversion < Repository | |||||
35 | revisions ? changesets.find_all_by_revision(revisions.collect(&:identifier), :order => "committed_on DESC") : [] |
|
35 | revisions ? changesets.find_all_by_revision(revisions.collect(&:identifier), :order => "committed_on DESC") : [] | |
36 | end |
|
36 | end | |
37 |
|
37 | |||
|
38 | # Returns a path relative to the url of the repository | |||
|
39 | def relative_path(path) | |||
|
40 | path.gsub(Regexp.new("^\/?#{Regexp.escape(relative_url)}"), '') | |||
|
41 | end | |||
|
42 | ||||
38 | def fetch_changesets |
|
43 | def fetch_changesets | |
39 | scm_info = scm.info |
|
44 | scm_info = scm.info | |
40 | if scm_info |
|
45 | if scm_info | |
@@ -71,4 +76,14 class Repository::Subversion < Repository | |||||
71 | end |
|
76 | end | |
72 | end |
|
77 | end | |
73 | end |
|
78 | end | |
|
79 | ||||
|
80 | private | |||
|
81 | ||||
|
82 | # Returns the relative url of the repository | |||
|
83 | # Eg: root_url = file:///var/svn/foo | |||
|
84 | # url = file:///var/svn/foo/bar | |||
|
85 | # => returns /bar | |||
|
86 | def relative_url | |||
|
87 | @relative_url ||= url.gsub(Regexp.new("^#{Regexp.escape(root_url)}"), '') | |||
|
88 | end | |||
74 | end |
|
89 | end |
@@ -49,7 +49,7 | |||||
49 | <td><div class="square action_<%= change.action %>"></div> <%= change.path %> <%= "(#{change.revision})" unless change.revision.blank? %></td> |
|
49 | <td><div class="square action_<%= change.action %>"></div> <%= change.path %> <%= "(#{change.revision})" unless change.revision.blank? %></td> | |
50 | <td align="right"> |
|
50 | <td align="right"> | |
51 | <% if change.action == "M" %> |
|
51 | <% if change.action == "M" %> | |
52 | <%= link_to l(:label_view_diff), :action => 'diff', :id => @project, :path => without_leading_slash(change.path), :rev => @changeset.revision %> |
|
52 | <%= link_to l(:label_view_diff), :action => 'diff', :id => @project, :path => without_leading_slash(change.relative_path), :rev => @changeset.revision %> | |
53 | <% end %> |
|
53 | <% end %> | |
54 | </td> |
|
54 | </td> | |
55 | </tr> |
|
55 | </tr> |
@@ -13,4 +13,11 changes_002: | |||||
13 | path: /test/some/path/elsewhere/in/the/repo |
|
13 | path: /test/some/path/elsewhere/in/the/repo | |
14 | from_path: |
|
14 | from_path: | |
15 | from_revision: |
|
15 | from_revision: | |
|
16 | changes_003: | |||
|
17 | id: 3 | |||
|
18 | changeset_id: 101 | |||
|
19 | action: M | |||
|
20 | path: /test/some/path/in/the/repo | |||
|
21 | from_path: | |||
|
22 | from_revision: | |||
16 | No newline at end of file |
|
23 |
@@ -97,6 +97,32 class RepositoriesSubversionControllerTest < Test::Unit::TestCase | |||||
97 | assert_equal 'folder', assigns(:entry).name |
|
97 | assert_equal 'folder', assigns(:entry).name | |
98 | end |
|
98 | end | |
99 |
|
99 | |||
|
100 | def test_revision | |||
|
101 | get :revision, :id => 1, :rev => 2 | |||
|
102 | assert_response :success | |||
|
103 | assert_template 'revision' | |||
|
104 | assert_tag :tag => 'tr', | |||
|
105 | :child => { :tag => 'td', :content => %r{/test/some/path/in/the/repo} }, | |||
|
106 | :child => { :tag => 'td', | |||
|
107 | :child => { :tag => 'a', :attributes => { :href => '/repositories/diff/ecookbook/test/some/path/in/the/repo?rev=2' } } | |||
|
108 | } | |||
|
109 | end | |||
|
110 | ||||
|
111 | def test_revision_with_repository_pointing_to_a_subdirectory | |||
|
112 | r = Project.find(1).repository | |||
|
113 | # Changes repository url to a subdirectory | |||
|
114 | r.update_attribute :url, (r.url + '/test/some') | |||
|
115 | ||||
|
116 | get :revision, :id => 1, :rev => 2 | |||
|
117 | assert_response :success | |||
|
118 | assert_template 'revision' | |||
|
119 | assert_tag :tag => 'tr', | |||
|
120 | :child => { :tag => 'td', :content => %r{/test/some/path/in/the/repo} }, | |||
|
121 | :child => { :tag => 'td', | |||
|
122 | :child => { :tag => 'a', :attributes => { :href => '/repositories/diff/ecookbook/path/in/the/repo?rev=2' } } | |||
|
123 | } | |||
|
124 | end | |||
|
125 | ||||
100 | def test_diff |
|
126 | def test_diff | |
101 | get :diff, :id => 1, :rev => 3 |
|
127 | get :diff, :id => 1, :rev => 3 | |
102 | assert_response :success |
|
128 | assert_response :success |
General Comments 0
You need to be logged in to leave comments.
Login now