##// END OF EJS Templates
Fixes platform determination under JRuby (#1804)....
Jean-Philippe Lang -
r1752:116091a1d2ea
parent child
Show More
@@ -0,0 +1,26
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 module Redmine
19 module Platform
20 class << self
21 def mswin?
22 (RUBY_PLATFORM =~ /(:?mswin|mingw)/) || (RUBY_PLATFORM == 'java' && (ENV['OS'] || ENV['os']) =~ /windows/i)
23 end
24 end
25 end
26 end
@@ -1,296 +1,296
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require 'cgi'
19 19
20 20 module Redmine
21 21 module Scm
22 22 module Adapters
23 23 class CommandFailed < StandardError #:nodoc:
24 24 end
25 25
26 26 class AbstractAdapter #:nodoc:
27 27 class << self
28 28 # Returns the version of the scm client
29 29 # Eg: [1, 5, 0] or [] if unknown
30 30 def client_version
31 31 []
32 32 end
33 33
34 34 # Returns the version string of the scm client
35 35 # Eg: '1.5.0' or 'Unknown version' if unknown
36 36 def client_version_string
37 37 v = client_version || 'Unknown version'
38 38 v.is_a?(Array) ? v.join('.') : v.to_s
39 39 end
40 40
41 41 # Returns true if the current client version is above
42 42 # or equals the given one
43 43 # If option is :unknown is set to true, it will return
44 44 # true if the client version is unknown
45 45 def client_version_above?(v, options={})
46 46 ((client_version <=> v) >= 0) || (client_version.empty? && options[:unknown])
47 47 end
48 48 end
49 49
50 50 def initialize(url, root_url=nil, login=nil, password=nil)
51 51 @url = url
52 52 @login = login if login && !login.empty?
53 53 @password = (password || "") if @login
54 54 @root_url = root_url.blank? ? retrieve_root_url : root_url
55 55 end
56 56
57 57 def adapter_name
58 58 'Abstract'
59 59 end
60 60
61 61 def supports_cat?
62 62 true
63 63 end
64 64
65 65 def supports_annotate?
66 66 respond_to?('annotate')
67 67 end
68 68
69 69 def root_url
70 70 @root_url
71 71 end
72 72
73 73 def url
74 74 @url
75 75 end
76 76
77 77 # get info about the svn repository
78 78 def info
79 79 return nil
80 80 end
81 81
82 82 # Returns the entry identified by path and revision identifier
83 83 # or nil if entry doesn't exist in the repository
84 84 def entry(path=nil, identifier=nil)
85 85 parts = path.to_s.split(%r{[\/\\]}).select {|n| !n.blank?}
86 86 search_path = parts[0..-2].join('/')
87 87 search_name = parts[-1]
88 88 if search_path.blank? && search_name.blank?
89 89 # Root entry
90 90 Entry.new(:path => '', :kind => 'dir')
91 91 else
92 92 # Search for the entry in the parent directory
93 93 es = entries(search_path, identifier)
94 94 es ? es.detect {|e| e.name == search_name} : nil
95 95 end
96 96 end
97 97
98 98 # Returns an Entries collection
99 99 # or nil if the given path doesn't exist in the repository
100 100 def entries(path=nil, identifier=nil)
101 101 return nil
102 102 end
103 103
104 104 def properties(path, identifier=nil)
105 105 return nil
106 106 end
107 107
108 108 def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={})
109 109 return nil
110 110 end
111 111
112 112 def diff(path, identifier_from, identifier_to=nil)
113 113 return nil
114 114 end
115 115
116 116 def cat(path, identifier=nil)
117 117 return nil
118 118 end
119 119
120 120 def with_leading_slash(path)
121 121 path ||= ''
122 122 (path[0,1]!="/") ? "/#{path}" : path
123 123 end
124 124
125 125 def with_trailling_slash(path)
126 126 path ||= ''
127 127 (path[-1,1] == "/") ? path : "#{path}/"
128 128 end
129 129
130 130 def without_leading_slash(path)
131 131 path ||= ''
132 132 path.gsub(%r{^/+}, '')
133 133 end
134 134
135 135 def without_trailling_slash(path)
136 136 path ||= ''
137 137 (path[-1,1] == "/") ? path[0..-2] : path
138 138 end
139 139
140 140 def shell_quote(str)
141 if RUBY_PLATFORM =~ /mswin/
141 if Redmine::Platform.mswin?
142 142 '"' + str.gsub(/"/, '\\"') + '"'
143 143 else
144 144 "'" + str.gsub(/'/, "'\"'\"'") + "'"
145 145 end
146 146 end
147 147
148 148 private
149 149 def retrieve_root_url
150 150 info = self.info
151 151 info ? info.root_url : nil
152 152 end
153 153
154 154 def target(path)
155 155 path ||= ''
156 156 base = path.match(/^\//) ? root_url : url
157 157 shell_quote("#{base}/#{path}".gsub(/[?<>\*]/, ''))
158 158 end
159 159
160 160 def logger
161 161 self.class.logger
162 162 end
163 163
164 164 def shellout(cmd, &block)
165 165 self.class.shellout(cmd, &block)
166 166 end
167 167
168 168 def self.logger
169 169 RAILS_DEFAULT_LOGGER
170 170 end
171 171
172 172 def self.shellout(cmd, &block)
173 173 logger.debug "Shelling out: #{cmd}" if logger && logger.debug?
174 174 begin
175 175 IO.popen(cmd, "r+") do |io|
176 176 io.close_write
177 177 block.call(io) if block_given?
178 178 end
179 179 rescue Errno::ENOENT => e
180 180 msg = strip_credential(e.message)
181 181 # The command failed, log it and re-raise
182 182 logger.error("SCM command failed: #{strip_credential(cmd)}\n with: #{msg}")
183 183 raise CommandFailed.new(msg)
184 184 end
185 185 end
186 186
187 187 # Hides username/password in a given command
188 188 def self.hide_credential(cmd)
189 q = (RUBY_PLATFORM =~ /mswin/ ? '"' : "'")
189 q = (Redmine::Platform.mswin? ? '"' : "'")
190 190 cmd.to_s.gsub(/(\-\-(password|username))\s+(#{q}[^#{q}]+#{q}|[^#{q}]\S+)/, '\\1 xxxx')
191 191 end
192 192
193 193 def strip_credential(cmd)
194 194 self.class.hide_credential(cmd)
195 195 end
196 196 end
197 197
198 198 class Entries < Array
199 199 def sort_by_name
200 200 sort {|x,y|
201 201 if x.kind == y.kind
202 202 x.name <=> y.name
203 203 else
204 204 x.kind <=> y.kind
205 205 end
206 206 }
207 207 end
208 208
209 209 def revisions
210 210 revisions ||= Revisions.new(collect{|entry| entry.lastrev}.compact)
211 211 end
212 212 end
213 213
214 214 class Info
215 215 attr_accessor :root_url, :lastrev
216 216 def initialize(attributes={})
217 217 self.root_url = attributes[:root_url] if attributes[:root_url]
218 218 self.lastrev = attributes[:lastrev]
219 219 end
220 220 end
221 221
222 222 class Entry
223 223 attr_accessor :name, :path, :kind, :size, :lastrev
224 224 def initialize(attributes={})
225 225 self.name = attributes[:name] if attributes[:name]
226 226 self.path = attributes[:path] if attributes[:path]
227 227 self.kind = attributes[:kind] if attributes[:kind]
228 228 self.size = attributes[:size].to_i if attributes[:size]
229 229 self.lastrev = attributes[:lastrev]
230 230 end
231 231
232 232 def is_file?
233 233 'file' == self.kind
234 234 end
235 235
236 236 def is_dir?
237 237 'dir' == self.kind
238 238 end
239 239
240 240 def is_text?
241 241 Redmine::MimeType.is_type?('text', name)
242 242 end
243 243 end
244 244
245 245 class Revisions < Array
246 246 def latest
247 247 sort {|x,y|
248 248 unless x.time.nil? or y.time.nil?
249 249 x.time <=> y.time
250 250 else
251 251 0
252 252 end
253 253 }.last
254 254 end
255 255 end
256 256
257 257 class Revision
258 258 attr_accessor :identifier, :scmid, :name, :author, :time, :message, :paths, :revision, :branch
259 259 def initialize(attributes={})
260 260 self.identifier = attributes[:identifier]
261 261 self.scmid = attributes[:scmid]
262 262 self.name = attributes[:name] || self.identifier
263 263 self.author = attributes[:author]
264 264 self.time = attributes[:time]
265 265 self.message = attributes[:message] || ""
266 266 self.paths = attributes[:paths]
267 267 self.revision = attributes[:revision]
268 268 self.branch = attributes[:branch]
269 269 end
270 270
271 271 end
272 272
273 273 class Annotate
274 274 attr_reader :lines, :revisions
275 275
276 276 def initialize
277 277 @lines = []
278 278 @revisions = []
279 279 end
280 280
281 281 def add_line(line, revision)
282 282 @lines << line
283 283 @revisions << revision
284 284 end
285 285
286 286 def content
287 287 content = lines.join("\n")
288 288 end
289 289
290 290 def empty?
291 291 lines.empty?
292 292 end
293 293 end
294 294 end
295 295 end
296 296 end
@@ -1,165 +1,165
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2008 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.dirname(__FILE__) + '/../test_helper'
19 19 require 'repositories_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class RepositoriesController; def rescue_action(e) raise e end; end
23 23
24 24 class RepositoriesCvsControllerTest < Test::Unit::TestCase
25 25
26 26 # No '..' in the repository path
27 27 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/cvs_repository'
28 REPOSITORY_PATH.gsub!(/\//, "\\") if RUBY_PLATFORM =~ /mswin/
28 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
29 29 # CVS module
30 30 MODULE_NAME = 'test'
31 31
32 32 def setup
33 33 @controller = RepositoriesController.new
34 34 @request = ActionController::TestRequest.new
35 35 @response = ActionController::TestResponse.new
36 36 Setting.default_language = 'en'
37 37 User.current = nil
38 38
39 39 @project = Project.find(1)
40 40 @project.repository = Repository::Cvs.create(:root_url => REPOSITORY_PATH,
41 41 :url => MODULE_NAME)
42 42 end
43 43
44 44 if File.directory?(REPOSITORY_PATH)
45 45 def test_show
46 46 get :show, :id => 1
47 47 assert_response :success
48 48 assert_template 'show'
49 49 assert_not_nil assigns(:entries)
50 50 assert_not_nil assigns(:changesets)
51 51 end
52 52
53 53 def test_browse_root
54 54 get :browse, :id => 1
55 55 assert_response :success
56 56 assert_template 'browse'
57 57 assert_not_nil assigns(:entries)
58 58 assert_equal 3, assigns(:entries).size
59 59
60 60 entry = assigns(:entries).detect {|e| e.name == 'images'}
61 61 assert_equal 'dir', entry.kind
62 62
63 63 entry = assigns(:entries).detect {|e| e.name == 'README'}
64 64 assert_equal 'file', entry.kind
65 65 end
66 66
67 67 def test_browse_directory
68 68 get :browse, :id => 1, :path => ['images']
69 69 assert_response :success
70 70 assert_template 'browse'
71 71 assert_not_nil assigns(:entries)
72 72 assert_equal ['add.png', 'delete.png', 'edit.png'], assigns(:entries).collect(&:name)
73 73 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
74 74 assert_not_nil entry
75 75 assert_equal 'file', entry.kind
76 76 assert_equal 'images/edit.png', entry.path
77 77 end
78 78
79 79 def test_browse_at_given_revision
80 80 Project.find(1).repository.fetch_changesets
81 81 get :browse, :id => 1, :path => ['images'], :rev => 1
82 82 assert_response :success
83 83 assert_template 'browse'
84 84 assert_not_nil assigns(:entries)
85 85 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
86 86 end
87 87
88 88 def test_entry
89 89 get :entry, :id => 1, :path => ['sources', 'watchers_controller.rb']
90 90 assert_response :success
91 91 assert_template 'entry'
92 92 assert_no_tag :tag => 'td', :attributes => { :class => /line-code/},
93 93 :content => /before_filter/
94 94 end
95 95
96 96 def test_entry_at_given_revision
97 97 # changesets must be loaded
98 98 Project.find(1).repository.fetch_changesets
99 99 get :entry, :id => 1, :path => ['sources', 'watchers_controller.rb'], :rev => 2
100 100 assert_response :success
101 101 assert_template 'entry'
102 102 # this line was removed in r3
103 103 assert_tag :tag => 'td', :attributes => { :class => /line-code/},
104 104 :content => /before_filter/
105 105 end
106 106
107 107 def test_entry_not_found
108 108 get :entry, :id => 1, :path => ['sources', 'zzz.c']
109 109 assert_tag :tag => 'div', :attributes => { :class => /error/ },
110 110 :content => /The entry or revision was not found in the repository/
111 111 end
112 112
113 113 def test_entry_download
114 114 get :entry, :id => 1, :path => ['sources', 'watchers_controller.rb'], :format => 'raw'
115 115 assert_response :success
116 116 end
117 117
118 118 def test_directory_entry
119 119 get :entry, :id => 1, :path => ['sources']
120 120 assert_response :success
121 121 assert_template 'browse'
122 122 assert_not_nil assigns(:entry)
123 123 assert_equal 'sources', assigns(:entry).name
124 124 end
125 125
126 126 def test_diff
127 127 Project.find(1).repository.fetch_changesets
128 128 get :diff, :id => 1, :rev => 3, :type => 'inline'
129 129 assert_response :success
130 130 assert_template 'diff'
131 131 assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_out' },
132 132 :content => /watched.remove_watcher/
133 133 assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_in' },
134 134 :content => /watched.remove_all_watcher/
135 135 end
136 136
137 137 def test_annotate
138 138 Project.find(1).repository.fetch_changesets
139 139 get :annotate, :id => 1, :path => ['sources', 'watchers_controller.rb']
140 140 assert_response :success
141 141 assert_template 'annotate'
142 142 # 1.1 line
143 143 assert_tag :tag => 'th', :attributes => { :class => 'line-num' },
144 144 :content => '18',
145 145 :sibling => { :tag => 'td', :attributes => { :class => 'revision' },
146 146 :content => /1.1/,
147 147 :sibling => { :tag => 'td', :attributes => { :class => 'author' },
148 148 :content => /LANG/
149 149 }
150 150 }
151 151 # 1.2 line
152 152 assert_tag :tag => 'th', :attributes => { :class => 'line-num' },
153 153 :content => '32',
154 154 :sibling => { :tag => 'td', :attributes => { :class => 'revision' },
155 155 :content => /1.2/,
156 156 :sibling => { :tag => 'td', :attributes => { :class => 'author' },
157 157 :content => /LANG/
158 158 }
159 159 }
160 160 end
161 161 else
162 162 puts "CVS test repository NOT FOUND. Skipping functional tests !!!"
163 163 def test_fake; assert true end
164 164 end
165 165 end
@@ -1,146 +1,146
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2008 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.dirname(__FILE__) + '/../test_helper'
19 19 require 'repositories_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class RepositoriesController; def rescue_action(e) raise e end; end
23 23
24 24 class RepositoriesGitControllerTest < Test::Unit::TestCase
25 25 fixtures :projects, :users, :roles, :members, :repositories, :enabled_modules
26 26
27 27 # No '..' in the repository path
28 28 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/git_repository'
29 REPOSITORY_PATH.gsub!(/\//, "\\") if RUBY_PLATFORM =~ /mswin/
29 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
30 30
31 31 def setup
32 32 @controller = RepositoriesController.new
33 33 @request = ActionController::TestRequest.new
34 34 @response = ActionController::TestResponse.new
35 35 User.current = nil
36 36 Repository::Git.create(:project => Project.find(3), :url => REPOSITORY_PATH)
37 37 end
38 38
39 39 if File.directory?(REPOSITORY_PATH)
40 40 def test_show
41 41 get :show, :id => 3
42 42 assert_response :success
43 43 assert_template 'show'
44 44 assert_not_nil assigns(:entries)
45 45 assert_not_nil assigns(:changesets)
46 46 end
47 47
48 48 def test_browse_root
49 49 get :browse, :id => 3
50 50 assert_response :success
51 51 assert_template 'browse'
52 52 assert_not_nil assigns(:entries)
53 53 assert_equal 3, assigns(:entries).size
54 54 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
55 55 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
56 56 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
57 57 end
58 58
59 59 def test_browse_directory
60 60 get :browse, :id => 3, :path => ['images']
61 61 assert_response :success
62 62 assert_template 'browse'
63 63 assert_not_nil assigns(:entries)
64 64 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
65 65 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
66 66 assert_not_nil entry
67 67 assert_equal 'file', entry.kind
68 68 assert_equal 'images/edit.png', entry.path
69 69 end
70 70
71 71 def test_browse_at_given_revision
72 72 get :browse, :id => 3, :path => ['images'], :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518'
73 73 assert_response :success
74 74 assert_template 'browse'
75 75 assert_not_nil assigns(:entries)
76 76 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
77 77 end
78 78
79 79 def test_changes
80 80 get :changes, :id => 3, :path => ['images', 'edit.png']
81 81 assert_response :success
82 82 assert_template 'changes'
83 83 assert_tag :tag => 'h2', :content => 'edit.png'
84 84 end
85 85
86 86 def test_entry_show
87 87 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb']
88 88 assert_response :success
89 89 assert_template 'entry'
90 90 # Line 19
91 91 assert_tag :tag => 'th',
92 92 :content => /10/,
93 93 :attributes => { :class => /line-num/ },
94 94 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
95 95 end
96 96
97 97 def test_entry_download
98 98 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'], :format => 'raw'
99 99 assert_response :success
100 100 # File content
101 101 assert @response.body.include?('WITHOUT ANY WARRANTY')
102 102 end
103 103
104 104 def test_directory_entry
105 105 get :entry, :id => 3, :path => ['sources']
106 106 assert_response :success
107 107 assert_template 'browse'
108 108 assert_not_nil assigns(:entry)
109 109 assert_equal 'sources', assigns(:entry).name
110 110 end
111 111
112 112 def test_diff
113 113 # Full diff of changeset 2f9c0091
114 114 get :diff, :id => 3, :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
115 115 assert_response :success
116 116 assert_template 'diff'
117 117 # Line 22 removed
118 118 assert_tag :tag => 'th',
119 119 :content => /22/,
120 120 :sibling => { :tag => 'td',
121 121 :attributes => { :class => /diff_out/ },
122 122 :content => /def remove/ }
123 123 end
124 124
125 125 def test_annotate
126 126 get :annotate, :id => 3, :path => ['sources', 'watchers_controller.rb']
127 127 assert_response :success
128 128 assert_template 'annotate'
129 129 # Line 23, changeset 2f9c0091
130 130 assert_tag :tag => 'th', :content => /23/,
131 131 :sibling => { :tag => 'td', :child => { :tag => 'a', :content => /2f9c0091/ } },
132 132 :sibling => { :tag => 'td', :content => /jsmith/ },
133 133 :sibling => { :tag => 'td', :content => /watcher =/ }
134 134 end
135 135
136 136 def test_annotate_binary_file
137 137 get :annotate, :id => 3, :path => ['images', 'delete.png']
138 138 assert_response 500
139 139 assert_tag :tag => 'div', :attributes => { :class => /error/ },
140 140 :content => /can not be annotated/
141 141 end
142 142 else
143 143 puts "Git test repository NOT FOUND. Skipping functional tests !!!"
144 144 def test_fake; assert true end
145 145 end
146 146 end
@@ -1,60 +1,60
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.dirname(__FILE__) + '/../test_helper'
19 19 require 'pp'
20 20 class RepositoryCvsTest < Test::Unit::TestCase
21 21 fixtures :projects
22 22
23 23 # No '..' in the repository path
24 24 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/cvs_repository'
25 REPOSITORY_PATH.gsub!(/\//, "\\") if RUBY_PLATFORM =~ /mswin/
25 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
26 26 # CVS module
27 27 MODULE_NAME = 'test'
28 28
29 29 def setup
30 30 @project = Project.find(1)
31 31 assert @repository = Repository::Cvs.create(:project => @project,
32 32 :root_url => REPOSITORY_PATH,
33 33 :url => MODULE_NAME)
34 34 end
35 35
36 36 if File.directory?(REPOSITORY_PATH)
37 37 def test_fetch_changesets_from_scratch
38 38 @repository.fetch_changesets
39 39 @repository.reload
40 40
41 41 assert_equal 5, @repository.changesets.count
42 42 assert_equal 14, @repository.changes.count
43 43 assert_not_nil @repository.changesets.find_by_comments('Two files changed')
44 44 end
45 45
46 46 def test_fetch_changesets_incremental
47 47 @repository.fetch_changesets
48 48 # Remove the 3 latest changesets
49 49 @repository.changesets.find(:all, :order => 'committed_on DESC', :limit => 3).each(&:destroy)
50 50 @repository.reload
51 51 assert_equal 2, @repository.changesets.count
52 52
53 53 @repository.fetch_changesets
54 54 assert_equal 5, @repository.changesets.count
55 55 end
56 56 else
57 57 puts "CVS test repository NOT FOUND. Skipping unit tests !!!"
58 58 def test_fake; assert true end
59 59 end
60 60 end
@@ -1,56 +1,56
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.dirname(__FILE__) + '/../test_helper'
19 19
20 20 class RepositoryGitTest < Test::Unit::TestCase
21 21 fixtures :projects
22 22
23 23 # No '..' in the repository path
24 24 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/git_repository'
25 REPOSITORY_PATH.gsub!(/\//, "\\") if RUBY_PLATFORM =~ /mswin/
25 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
26 26
27 27 def setup
28 28 @project = Project.find(1)
29 29 assert @repository = Repository::Git.create(:project => @project, :url => REPOSITORY_PATH)
30 30 end
31 31
32 32 if File.directory?(REPOSITORY_PATH)
33 33 def test_fetch_changesets_from_scratch
34 34 @repository.fetch_changesets
35 35 @repository.reload
36 36
37 37 assert_equal 6, @repository.changesets.count
38 38 assert_equal 11, @repository.changes.count
39 39 assert_equal "Initial import.\nThe repository contains 3 files.", @repository.changesets.find(:first, :order => 'id ASC').comments
40 40 end
41 41
42 42 def test_fetch_changesets_incremental
43 43 @repository.fetch_changesets
44 44 # Remove the 3 latest changesets
45 45 @repository.changesets.find(:all, :order => 'id DESC', :limit => 3).each(&:destroy)
46 46 @repository.reload
47 47 assert_equal 3, @repository.changesets.count
48 48
49 49 @repository.fetch_changesets
50 50 assert_equal 6, @repository.changesets.count
51 51 end
52 52 else
53 53 puts "Git test repository NOT FOUND. Skipping unit tests !!!"
54 54 def test_fake; assert true end
55 55 end
56 56 end
General Comments 0
You need to be logged in to leave comments. Login now