@@ -0,0 +1,129 | |||||
|
1 | # redMine - project management software | |||
|
2 | # Copyright (C) 2006-2008 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.dirname(__FILE__) + '/../test_helper' | |||
|
19 | require 'repositories_controller' | |||
|
20 | ||||
|
21 | # Re-raise errors caught by the controller. | |||
|
22 | class RepositoriesController; def rescue_action(e) raise e end; end | |||
|
23 | ||||
|
24 | class RepositoriesBazaarControllerTest < Test::Unit::TestCase | |||
|
25 | fixtures :projects, :users, :roles, :members, :repositories, :enabled_modules | |||
|
26 | ||||
|
27 | # No '..' in the repository path | |||
|
28 | REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/bazaar_repository' | |||
|
29 | ||||
|
30 | def setup | |||
|
31 | @controller = RepositoriesController.new | |||
|
32 | @request = ActionController::TestRequest.new | |||
|
33 | @response = ActionController::TestResponse.new | |||
|
34 | User.current = nil | |||
|
35 | Repository::Bazaar.create(:project => Project.find(3), :url => REPOSITORY_PATH) | |||
|
36 | end | |||
|
37 | ||||
|
38 | if File.directory?(REPOSITORY_PATH) | |||
|
39 | def test_show | |||
|
40 | get :show, :id => 3 | |||
|
41 | assert_response :success | |||
|
42 | assert_template 'show' | |||
|
43 | assert_not_nil assigns(:entries) | |||
|
44 | assert_not_nil assigns(:changesets) | |||
|
45 | end | |||
|
46 | ||||
|
47 | def test_browse_root | |||
|
48 | get :browse, :id => 3 | |||
|
49 | assert_response :success | |||
|
50 | assert_template 'browse' | |||
|
51 | assert_not_nil assigns(:entries) | |||
|
52 | assert_equal 2, assigns(:entries).size | |||
|
53 | assert assigns(:entries).detect {|e| e.name == 'directory' && e.kind == 'dir'} | |||
|
54 | assert assigns(:entries).detect {|e| e.name == 'doc-mkdir.txt' && e.kind == 'file'} | |||
|
55 | end | |||
|
56 | ||||
|
57 | def test_browse_directory | |||
|
58 | get :browse, :id => 3, :path => ['directory'] | |||
|
59 | assert_response :success | |||
|
60 | assert_template 'browse' | |||
|
61 | assert_not_nil assigns(:entries) | |||
|
62 | assert_equal ['doc-ls.txt', 'document.txt', 'edit.png'], assigns(:entries).collect(&:name) | |||
|
63 | entry = assigns(:entries).detect {|e| e.name == 'edit.png'} | |||
|
64 | assert_not_nil entry | |||
|
65 | assert_equal 'file', entry.kind | |||
|
66 | assert_equal 'directory/edit.png', entry.path | |||
|
67 | end | |||
|
68 | ||||
|
69 | def test_browse_at_given_revision | |||
|
70 | get :browse, :id => 3, :path => [], :rev => 3 | |||
|
71 | assert_response :success | |||
|
72 | assert_template 'browse' | |||
|
73 | assert_not_nil assigns(:entries) | |||
|
74 | assert_equal ['directory', 'doc-deleted.txt', 'doc-ls.txt', 'doc-mkdir.txt'], assigns(:entries).collect(&:name) | |||
|
75 | end | |||
|
76 | ||||
|
77 | def test_changes | |||
|
78 | get :changes, :id => 3, :path => ['doc-mkdir.txt'] | |||
|
79 | assert_response :success | |||
|
80 | assert_template 'changes' | |||
|
81 | assert_tag :tag => 'h2', :content => 'doc-mkdir.txt' | |||
|
82 | end | |||
|
83 | ||||
|
84 | def test_entry_show | |||
|
85 | get :entry, :id => 3, :path => ['directory', 'doc-ls.txt'] | |||
|
86 | assert_response :success | |||
|
87 | assert_template 'entry' | |||
|
88 | # Line 19 | |||
|
89 | assert_tag :tag => 'th', | |||
|
90 | :content => /29/, | |||
|
91 | :attributes => { :class => /line-num/ }, | |||
|
92 | :sibling => { :tag => 'td', :content => /Show help message/ } | |||
|
93 | end | |||
|
94 | ||||
|
95 | def test_entry_download | |||
|
96 | get :entry, :id => 3, :path => ['directory', 'doc-ls.txt'], :format => 'raw' | |||
|
97 | assert_response :success | |||
|
98 | # File content | |||
|
99 | assert @response.body.include?('Show help message') | |||
|
100 | end | |||
|
101 | ||||
|
102 | def test_diff | |||
|
103 | # Full diff of changeset 3 | |||
|
104 | get :diff, :id => 3, :rev => 3 | |||
|
105 | assert_response :success | |||
|
106 | assert_template 'diff' | |||
|
107 | # Line 22 removed | |||
|
108 | assert_tag :tag => 'th', | |||
|
109 | :content => /2/, | |||
|
110 | :sibling => { :tag => 'td', | |||
|
111 | :attributes => { :class => /diff_in/ }, | |||
|
112 | :content => /Main purpose/ } | |||
|
113 | end | |||
|
114 | ||||
|
115 | def test_annotate | |||
|
116 | get :annotate, :id => 3, :path => ['doc-mkdir.txt'] | |||
|
117 | assert_response :success | |||
|
118 | assert_template 'annotate' | |||
|
119 | # Line 2, revision 3 | |||
|
120 | assert_tag :tag => 'th', :content => /2/, | |||
|
121 | :sibling => { :tag => 'td', :child => { :tag => 'a', :content => /3/ } }, | |||
|
122 | :sibling => { :tag => 'td', :content => /jsmith/ }, | |||
|
123 | :sibling => { :tag => 'td', :content => /Main purpose/ } | |||
|
124 | end | |||
|
125 | else | |||
|
126 | puts "Bazaar test repository NOT FOUND. Skipping functional tests !!!" | |||
|
127 | def test_fake; assert true end | |||
|
128 | end | |||
|
129 | end |
@@ -51,8 +51,8 class RepositoriesController < ApplicationController | |||||
51 | def show |
|
51 | def show | |
52 | # check if new revisions have been committed in the repository |
|
52 | # check if new revisions have been committed in the repository | |
53 | @repository.fetch_changesets if Setting.autofetch_changesets? |
|
53 | @repository.fetch_changesets if Setting.autofetch_changesets? | |
54 | # get entries for the browse frame |
|
54 | # root entries | |
55 | @entries = @repository.entries('') |
|
55 | @entries = @repository.entries('', @rev) | |
56 | # latest changesets |
|
56 | # latest changesets | |
57 | @changesets = @repository.changesets.find(:all, :limit => 10, :order => "committed_on DESC") |
|
57 | @changesets = @repository.changesets.find(:all, :limit => 10, :order => "committed_on DESC") | |
58 | show_error_not_found unless @entries || @changesets.any? |
|
58 | show_error_not_found unless @entries || @changesets.any? |
@@ -35,7 +35,8 class Repository::Cvs < Repository | |||||
35 | end |
|
35 | end | |
36 |
|
36 | |||
37 | def entries(path=nil, identifier=nil) |
|
37 | def entries(path=nil, identifier=nil) | |
38 | entries=scm.entries(path, identifier) |
|
38 | rev = identifier.nil? ? nil : changesets.find_by_revision(identifier) | |
|
39 | entries = scm.entries(path, rev.nil? ? nil : rev.committed_on) | |||
39 | if entries |
|
40 | if entries | |
40 | entries.each() do |entry| |
|
41 | entries.each() do |entry| | |
41 | unless entry.lastrev.nil? || entry.lastrev.identifier |
|
42 | unless entry.lastrev.nil? || entry.lastrev.identifier |
@@ -29,7 +29,8 class Repository::Darcs < Repository | |||||
29 | end |
|
29 | end | |
30 |
|
30 | |||
31 | def entries(path=nil, identifier=nil) |
|
31 | def entries(path=nil, identifier=nil) | |
32 | entries=scm.entries(path, identifier) |
|
32 | patch = identifier.nil? ? nil : changesets.find_by_revision(identifier) | |
|
33 | entries = scm.entries(path, patch.nil? ? nil : patch.scmid) | |||
33 | if entries |
|
34 | if entries | |
34 | entries.each do |entry| |
|
35 | entries.each do |entry| | |
35 | # Search the DB for the entry's last change |
|
36 | # Search the DB for the entry's last change |
@@ -72,7 +72,9 module Redmine | |||||
72 | logger.debug "<cvs> entries '#{path}' with identifier '#{identifier}'" |
|
72 | logger.debug "<cvs> entries '#{path}' with identifier '#{identifier}'" | |
73 | path_with_project="#{url}#{with_leading_slash(path)}" |
|
73 | path_with_project="#{url}#{with_leading_slash(path)}" | |
74 | entries = Entries.new |
|
74 | entries = Entries.new | |
75 |
cmd = "#{CVS_BIN} -d #{root_url} rls -ed |
|
75 | cmd = "#{CVS_BIN} -d #{root_url} rls -ed" | |
|
76 | cmd << " -D \"#{time_to_cvstime(identifier)}\"" if identifier | |||
|
77 | cmd << " #{path_with_project}" | |||
76 | shellout(cmd) do |io| |
|
78 | shellout(cmd) do |io| | |
77 | io.each_line(){|line| |
|
79 | io.each_line(){|line| | |
78 | fields=line.chop.split('/',-1) |
|
80 | fields=line.chop.split('/',-1) |
@@ -53,7 +53,9 module Redmine | |||||
53 | path_prefix = (path.blank? ? '' : "#{path}/") |
|
53 | path_prefix = (path.blank? ? '' : "#{path}/") | |
54 | path = '.' if path.blank? |
|
54 | path = '.' if path.blank? | |
55 | entries = Entries.new |
|
55 | entries = Entries.new | |
56 |
cmd = "#{DARCS_BIN} annotate --repodir #{@url} --xml-output |
|
56 | cmd = "#{DARCS_BIN} annotate --repodir #{@url} --xml-output" | |
|
57 | cmd << " --match \"hash #{identifier}\"" if identifier | |||
|
58 | cmd << " #{path}" | |||
57 | shellout(cmd) do |io| |
|
59 | shellout(cmd) do |io| | |
58 | begin |
|
60 | begin | |
59 | doc = REXML::Document.new(io) |
|
61 | doc = REXML::Document.new(io) |
@@ -79,7 +79,7 module Redmine | |||||
79 | rev = Revision.new({:identifier => changeset[:commit], |
|
79 | rev = Revision.new({:identifier => changeset[:commit], | |
80 | :scmid => changeset[:commit], |
|
80 | :scmid => changeset[:commit], | |
81 | :author => changeset[:author], |
|
81 | :author => changeset[:author], | |
82 | :time => Time.parse(changeset[:date]), |
|
82 | :time => (changeset[:date] ? Time.parse(changeset[:date]) : nil), | |
83 | :message => changeset[:description], |
|
83 | :message => changeset[:description], | |
84 | :paths => files |
|
84 | :paths => files | |
85 | }) |
|
85 | }) |
@@ -65,13 +65,24 class RepositoriesCvsControllerTest < Test::Unit::TestCase | |||||
65 | end |
|
65 | end | |
66 |
|
66 | |||
67 | def test_browse_directory |
|
67 | def test_browse_directory | |
68 |
get :browse, :id => 1, :path => [' |
|
68 | get :browse, :id => 1, :path => ['images'] | |
69 | assert_response :success |
|
69 | assert_response :success | |
70 | assert_template 'browse' |
|
70 | assert_template 'browse' | |
71 | assert_not_nil assigns(:entries) |
|
71 | assert_not_nil assigns(:entries) | |
72 | entry = assigns(:entries).detect {|e| e.name == 'watchers_controller.rb'} |
|
72 | assert_equal ['add.png', 'delete.png', 'edit.png'], assigns(:entries).collect(&:name) | |
|
73 | entry = assigns(:entries).detect {|e| e.name == 'edit.png'} | |||
|
74 | assert_not_nil entry | |||
73 | assert_equal 'file', entry.kind |
|
75 | assert_equal 'file', entry.kind | |
74 |
assert_equal ' |
|
76 | assert_equal 'images/edit.png', entry.path | |
|
77 | end | |||
|
78 | ||||
|
79 | def test_browse_at_given_revision | |||
|
80 | Project.find(1).repository.fetch_changesets | |||
|
81 | get :browse, :id => 1, :path => ['images'], :rev => 1 | |||
|
82 | assert_response :success | |||
|
83 | assert_template 'browse' | |||
|
84 | assert_not_nil assigns(:entries) | |||
|
85 | assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name) | |||
75 | end |
|
86 | end | |
76 |
|
87 | |||
77 | def test_entry |
|
88 | def test_entry |
@@ -60,13 +60,22 class RepositoriesDarcsControllerTest < Test::Unit::TestCase | |||||
60 | assert_response :success |
|
60 | assert_response :success | |
61 | assert_template 'browse' |
|
61 | assert_template 'browse' | |
62 | assert_not_nil assigns(:entries) |
|
62 | assert_not_nil assigns(:entries) | |
63 |
assert_equal |
|
63 | assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name) | |
64 | entry = assigns(:entries).detect {|e| e.name == 'edit.png'} |
|
64 | entry = assigns(:entries).detect {|e| e.name == 'edit.png'} | |
65 | assert_not_nil entry |
|
65 | assert_not_nil entry | |
66 | assert_equal 'file', entry.kind |
|
66 | assert_equal 'file', entry.kind | |
67 | assert_equal 'images/edit.png', entry.path |
|
67 | assert_equal 'images/edit.png', entry.path | |
68 | end |
|
68 | end | |
69 |
|
69 | |||
|
70 | def test_browse_at_given_revision | |||
|
71 | Project.find(3).repository.fetch_changesets | |||
|
72 | get :browse, :id => 3, :path => ['images'], :rev => 1 | |||
|
73 | assert_response :success | |||
|
74 | assert_template 'browse' | |||
|
75 | assert_not_nil assigns(:entries) | |||
|
76 | assert_equal ['delete.png'], assigns(:entries).collect(&:name) | |||
|
77 | end | |||
|
78 | ||||
70 | def test_changes |
|
79 | def test_changes | |
71 | get :changes, :id => 3, :path => ['images', 'edit.png'] |
|
80 | get :changes, :id => 3, :path => ['images', 'edit.png'] | |
72 | assert_response :success |
|
81 | assert_response :success |
@@ -1,5 +1,5 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 |
# Copyright (C) 2006-200 |
|
2 | # Copyright (C) 2006-2008 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
@@ -61,13 +61,21 class RepositoriesGitControllerTest < Test::Unit::TestCase | |||||
61 | assert_response :success |
|
61 | assert_response :success | |
62 | assert_template 'browse' |
|
62 | assert_template 'browse' | |
63 | assert_not_nil assigns(:entries) |
|
63 | assert_not_nil assigns(:entries) | |
64 |
assert_equal |
|
64 | assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name) | |
65 | entry = assigns(:entries).detect {|e| e.name == 'edit.png'} |
|
65 | entry = assigns(:entries).detect {|e| e.name == 'edit.png'} | |
66 | assert_not_nil entry |
|
66 | assert_not_nil entry | |
67 | assert_equal 'file', entry.kind |
|
67 | assert_equal 'file', entry.kind | |
68 | assert_equal 'images/edit.png', entry.path |
|
68 | assert_equal 'images/edit.png', entry.path | |
69 | end |
|
69 | end | |
70 |
|
70 | |||
|
71 | def test_browse_at_given_revision | |||
|
72 | get :browse, :id => 3, :path => ['images'], :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518' | |||
|
73 | assert_response :success | |||
|
74 | assert_template 'browse' | |||
|
75 | assert_not_nil assigns(:entries) | |||
|
76 | assert_equal ['delete.png'], assigns(:entries).collect(&:name) | |||
|
77 | end | |||
|
78 | ||||
71 | def test_changes |
|
79 | def test_changes | |
72 | get :changes, :id => 3, :path => ['images', 'edit.png'] |
|
80 | get :changes, :id => 3, :path => ['images', 'edit.png'] | |
73 | assert_response :success |
|
81 | assert_response :success |
@@ -1,5 +1,5 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 |
# Copyright (C) 2006-200 |
|
2 | # Copyright (C) 2006-2008 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
@@ -60,13 +60,21 class RepositoriesMercurialControllerTest < Test::Unit::TestCase | |||||
60 | assert_response :success |
|
60 | assert_response :success | |
61 | assert_template 'browse' |
|
61 | assert_template 'browse' | |
62 | assert_not_nil assigns(:entries) |
|
62 | assert_not_nil assigns(:entries) | |
63 |
assert_equal |
|
63 | assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name) | |
64 | entry = assigns(:entries).detect {|e| e.name == 'edit.png'} |
|
64 | entry = assigns(:entries).detect {|e| e.name == 'edit.png'} | |
65 | assert_not_nil entry |
|
65 | assert_not_nil entry | |
66 | assert_equal 'file', entry.kind |
|
66 | assert_equal 'file', entry.kind | |
67 | assert_equal 'images/edit.png', entry.path |
|
67 | assert_equal 'images/edit.png', entry.path | |
68 | end |
|
68 | end | |
69 |
|
69 | |||
|
70 | def test_browse_at_given_revision | |||
|
71 | get :browse, :id => 3, :path => ['images'], :rev => 0 | |||
|
72 | assert_response :success | |||
|
73 | assert_template 'browse' | |||
|
74 | assert_not_nil assigns(:entries) | |||
|
75 | assert_equal ['delete.png'], assigns(:entries).collect(&:name) | |||
|
76 | end | |||
|
77 | ||||
70 | def test_changes |
|
78 | def test_changes | |
71 | get :changes, :id => 3, :path => ['images', 'edit.png'] |
|
79 | get :changes, :id => 3, :path => ['images', 'edit.png'] | |
72 | assert_response :success |
|
80 | assert_response :success |
@@ -1,5 +1,5 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 |
# Copyright (C) 2006-200 |
|
2 | # Copyright (C) 2006-2008 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
@@ -58,11 +58,20 class RepositoriesSubversionControllerTest < Test::Unit::TestCase | |||||
58 | assert_response :success |
|
58 | assert_response :success | |
59 | assert_template 'browse' |
|
59 | assert_template 'browse' | |
60 | assert_not_nil assigns(:entries) |
|
60 | assert_not_nil assigns(:entries) | |
|
61 | assert_equal ['folder', '.project', 'helloworld.c', 'textfile.txt'], assigns(:entries).collect(&:name) | |||
61 | entry = assigns(:entries).detect {|e| e.name == 'helloworld.c'} |
|
62 | entry = assigns(:entries).detect {|e| e.name == 'helloworld.c'} | |
62 | assert_equal 'file', entry.kind |
|
63 | assert_equal 'file', entry.kind | |
63 | assert_equal 'subversion_test/helloworld.c', entry.path |
|
64 | assert_equal 'subversion_test/helloworld.c', entry.path | |
64 | end |
|
65 | end | |
65 |
|
66 | |||
|
67 | def test_browse_at_given_revision | |||
|
68 | get :browse, :id => 1, :path => ['subversion_test'], :rev => 4 | |||
|
69 | assert_response :success | |||
|
70 | assert_template 'browse' | |||
|
71 | assert_not_nil assigns(:entries) | |||
|
72 | assert_equal ['folder', '.project', 'helloworld.c', 'helloworld.rb', 'textfile.txt'], assigns(:entries).collect(&:name) | |||
|
73 | end | |||
|
74 | ||||
66 | def test_entry |
|
75 | def test_entry | |
67 | get :entry, :id => 1, :path => ['subversion_test', 'helloworld.c'] |
|
76 | get :entry, :id => 1, :path => ['subversion_test', 'helloworld.c'] | |
68 | assert_response :success |
|
77 | assert_response :success |
General Comments 0
You need to be logged in to leave comments.
Login now