@@ -247,7 +247,10 class Changeset < ActiveRecord::Base | |||||
247 | def self.to_utf8(str, encoding) |
|
247 | def self.to_utf8(str, encoding) | |
248 | return str if str.nil? |
|
248 | return str if str.nil? | |
249 | str.force_encoding("ASCII-8BIT") if str.respond_to?(:force_encoding) |
|
249 | str.force_encoding("ASCII-8BIT") if str.respond_to?(:force_encoding) | |
250 |
|
|
250 | if str.empty? | |
|
251 | str.force_encoding("UTF-8") if str.respond_to?(:force_encoding) | |||
|
252 | return str | |||
|
253 | end | |||
251 | str.force_encoding("UTF-8") if str.respond_to?(:force_encoding) |
|
254 | str.force_encoding("UTF-8") if str.respond_to?(:force_encoding) | |
252 | if str.respond_to?(:force_encoding) |
|
255 | if str.respond_to?(:force_encoding) | |
253 | enc = encoding.blank? ? "UTF-8" : encoding |
|
256 | enc = encoding.blank? ? "UTF-8" : encoding |
@@ -292,6 +292,42 class ChangesetTest < ActiveSupport::TestCase | |||||
292 | assert_equal s4, c.comments |
|
292 | assert_equal s4, c.comments | |
293 | end |
|
293 | end | |
294 |
|
294 | |||
|
295 | def test_comments_nil | |||
|
296 | proj = Project.find(3) | |||
|
297 | r = Repository::Bazaar.create!( | |||
|
298 | :project => proj, :url => '/tmp/test/bazaar', | |||
|
299 | :log_encoding => 'ISO-8859-1' ) | |||
|
300 | assert r | |||
|
301 | c = Changeset.new(:repository => r, | |||
|
302 | :committed_on => Time.now, | |||
|
303 | :revision => '123', | |||
|
304 | :scmid => '12345', | |||
|
305 | :comments => nil) | |||
|
306 | assert( c.save ) | |||
|
307 | assert_equal "", c.comments | |||
|
308 | if c.comments.respond_to?(:force_encoding) | |||
|
309 | assert_equal "UTF-8", c.comments.encoding.to_s | |||
|
310 | end | |||
|
311 | end | |||
|
312 | ||||
|
313 | def test_comments_empty | |||
|
314 | proj = Project.find(3) | |||
|
315 | r = Repository::Bazaar.create!( | |||
|
316 | :project => proj, :url => '/tmp/test/bazaar', | |||
|
317 | :log_encoding => 'ISO-8859-1' ) | |||
|
318 | assert r | |||
|
319 | c = Changeset.new(:repository => r, | |||
|
320 | :committed_on => Time.now, | |||
|
321 | :revision => '123', | |||
|
322 | :scmid => '12345', | |||
|
323 | :comments => "") | |||
|
324 | assert( c.save ) | |||
|
325 | assert_equal "", c.comments | |||
|
326 | if c.comments.respond_to?(:force_encoding) | |||
|
327 | assert_equal "UTF-8", c.comments.encoding.to_s | |||
|
328 | end | |||
|
329 | end | |||
|
330 | ||||
295 | def test_identifier |
|
331 | def test_identifier | |
296 | c = Changeset.find_by_revision('1') |
|
332 | c = Changeset.find_by_revision('1') | |
297 | assert_equal c.revision, c.identifier |
|
333 | assert_equal c.revision, c.identifier |
General Comments 0
You need to be logged in to leave comments.
Login now