[#383] Fixed failing tests due to a helper method name conflict (to_utf8)
Introduced in 1eee7312f6
This commit is contained in:
parent
d29315341d
commit
13de4cc4b0
|
@ -28,7 +28,7 @@ module AttachmentsHelper
|
|||
end
|
||||
end
|
||||
|
||||
def to_utf8(str)
|
||||
def to_utf8_for_attachments(str)
|
||||
if str.respond_to?(:force_encoding)
|
||||
str.force_encoding('UTF-8')
|
||||
return str if str.valid_encoding?
|
||||
|
|
|
@ -116,7 +116,7 @@ module RepositoriesHelper
|
|||
output
|
||||
end
|
||||
|
||||
def to_utf8(str)
|
||||
def to_utf8_for_repositories(str)
|
||||
return str if str.nil?
|
||||
str = to_utf8_internal(str)
|
||||
if str.respond_to?(:force_encoding)
|
||||
|
|
|
@ -144,7 +144,7 @@ module TimelogHelper
|
|||
headers = criterias.collect {|criteria| l(@available_criterias[criteria][:label]) }
|
||||
headers += periods
|
||||
headers << l(:label_total)
|
||||
csv << headers.collect {|c| to_utf8(c) }
|
||||
csv << headers.collect {|c| to_utf8_for_timelogs(c) }
|
||||
# Content
|
||||
report_criteria_to_csv(csv, criterias, periods, hours)
|
||||
# Total row
|
||||
|
@ -166,7 +166,7 @@ module TimelogHelper
|
|||
hours_for_value = select_hours(hours, criterias[level], value)
|
||||
next if hours_for_value.empty?
|
||||
row = [''] * level
|
||||
row << to_utf8(format_criteria_value(criterias[level], value))
|
||||
row << to_utf8_for_timelogs(format_criteria_value(criterias[level], value))
|
||||
row += [''] * (criterias.length - level - 1)
|
||||
total = 0
|
||||
periods.each do |period|
|
||||
|
@ -183,7 +183,7 @@ module TimelogHelper
|
|||
end
|
||||
end
|
||||
|
||||
def to_utf8(s)
|
||||
def to_utf8_for_timelogs(s)
|
||||
@ic ||= Iconv.new(l(:general_csv_encoding), 'UTF-8')
|
||||
begin; @ic.iconv(s.to_s); rescue; s.to_s; end
|
||||
end
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
<% else -%>
|
||||
<table class="filecontent">
|
||||
<thead>
|
||||
<tr><th colspan="3" class="filename"><%=to_utf8 table_file.file_name %></th></tr>
|
||||
<tr><th colspan="3" class="filename"><%=to_utf8_for_attachments table_file.file_name %></th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% table_file.each_line do |spacing, line| %>
|
||||
|
@ -44,7 +44,7 @@
|
|||
<th class="line-num"><%= line.nb_line_left %></th>
|
||||
<th class="line-num"><%= line.nb_line_right %></th>
|
||||
<td class="line-code <%= line.type_diff %>">
|
||||
<pre><%=to_utf8 line.html_line %></pre>
|
||||
<pre><%=to_utf8_for_attachments line.html_line %></pre>
|
||||
</td>
|
||||
</tr>
|
||||
<% end -%>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<table class="filecontent syntaxhl">
|
||||
<tbody>
|
||||
<% line_num = 1 %>
|
||||
<% syntax_highlight(filename, to_utf8(content)).each_line do |line| %>
|
||||
<% syntax_highlight(filename, to_utf8_for_attachments(content)).each_line do |line| %>
|
||||
<tr><th class="line-num" id="L<%= line_num %>"><a href="#L<%= line_num %>"><%= line_num %></a></th><td class="line-code"><pre><%= line %></pre></td></tr>
|
||||
<% line_num += 1 %>
|
||||
<% end %>
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
<table class="filecontent annotate syntaxhl">
|
||||
<tbody>
|
||||
<% line_num = 1 %>
|
||||
<% syntax_highlight(@path, to_utf8(@annotate.content)).each_line do |line| %>
|
||||
<% syntax_highlight(@path, to_utf8_for_repositories(@annotate.content)).each_line do |line| %>
|
||||
<% revision = @annotate.revisions[line_num-1] %>
|
||||
<tr class="bloc-<%= revision.nil? ? 0 : colors[revision.identifier || revision.revision] %>">
|
||||
<th class="line-num" id="L<%= line_num %>"><a href="#L<%= line_num %>"><%= line_num %></a></th>
|
||||
|
|
|
@ -20,7 +20,7 @@ require File.expand_path('../../../test_helper', __FILE__)
|
|||
class RepositoryHelperTest < HelperTestCase
|
||||
include RepositoriesHelper
|
||||
|
||||
def test_from_latin1_to_utf8
|
||||
def test_from_latin1_to_utf8_for_repositories
|
||||
with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
|
||||
s1 = "Texte encod\xc3\xa9"
|
||||
s2 = "Texte encod\xe9"
|
||||
|
@ -30,12 +30,12 @@ class RepositoryHelperTest < HelperTestCase
|
|||
s2.force_encoding("ASCII-8BIT")
|
||||
s3.force_encoding("UTF-8")
|
||||
end
|
||||
assert_equal s1, to_utf8(s2)
|
||||
assert_equal s1, to_utf8(s3)
|
||||
assert_equal s1, to_utf8_for_repositories(s2)
|
||||
assert_equal s1, to_utf8_for_repositories(s3)
|
||||
end
|
||||
end
|
||||
|
||||
def test_from_euc_jp_to_utf8
|
||||
def test_from_euc_jp_to_utf8_for_repositories
|
||||
with_settings :repositories_encodings => 'UTF-8,EUC-JP' do
|
||||
s1 = "\xe3\x83\xac\xe3\x83\x83\xe3\x83\x89\xe3\x83\x9e\xe3\x82\xa4\xe3\x83\xb3"
|
||||
s2 = "\xa5\xec\xa5\xc3\xa5\xc9\xa5\xde\xa5\xa4\xa5\xf3"
|
||||
|
@ -45,12 +45,12 @@ class RepositoryHelperTest < HelperTestCase
|
|||
s2.force_encoding("ASCII-8BIT")
|
||||
s3.force_encoding("UTF-8")
|
||||
end
|
||||
assert_equal s1, to_utf8(s2)
|
||||
assert_equal s1, to_utf8(s3)
|
||||
assert_equal s1, to_utf8_for_repositories(s2)
|
||||
assert_equal s1, to_utf8_for_repositories(s3)
|
||||
end
|
||||
end
|
||||
|
||||
def test_to_utf8_should_be_converted_all_latin1_to_utf8
|
||||
def test_to_utf8_for_repositories_should_be_converted_all_latin1_to_utf8
|
||||
with_settings :repositories_encodings => 'ISO-8859-1' do
|
||||
s1 = "\xc3\x82\xc2\x80"
|
||||
s2 = "\xC2\x80"
|
||||
|
@ -60,25 +60,25 @@ class RepositoryHelperTest < HelperTestCase
|
|||
s2.force_encoding("ASCII-8BIT")
|
||||
s3.force_encoding("UTF-8")
|
||||
end
|
||||
assert_equal s1, to_utf8(s2)
|
||||
assert_equal s1, to_utf8(s3)
|
||||
assert_equal s1, to_utf8_for_repositories(s2)
|
||||
assert_equal s1, to_utf8_for_repositories(s3)
|
||||
end
|
||||
end
|
||||
|
||||
def test_to_utf8_blank_string
|
||||
assert_equal "", to_utf8("")
|
||||
assert_equal nil, to_utf8(nil)
|
||||
def test_to_utf8_for_repositories_blank_string
|
||||
assert_equal "", to_utf8_for_repositories("")
|
||||
assert_equal nil, to_utf8_for_repositories(nil)
|
||||
end
|
||||
|
||||
def test_to_utf8_returns_ascii_as_utf8
|
||||
def test_to_utf8_for_repositories_returns_ascii_as_utf8
|
||||
s1 = "ASCII"
|
||||
s2 = s1.dup
|
||||
if s1.respond_to?(:force_encoding)
|
||||
s1.force_encoding("UTF-8")
|
||||
s2.force_encoding("ISO-8859-1")
|
||||
end
|
||||
str1 = to_utf8(s1)
|
||||
str2 = to_utf8(s2)
|
||||
str1 = to_utf8_for_repositories(s1)
|
||||
str2 = to_utf8_for_repositories(s2)
|
||||
assert_equal s1, str1
|
||||
assert_equal s1, str2
|
||||
if s1.respond_to?(:force_encoding)
|
||||
|
@ -87,10 +87,10 @@ class RepositoryHelperTest < HelperTestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_to_utf8_invalid_utf8_sequences_should_be_stripped
|
||||
def test_to_utf8_for_repositories_invalid_utf8_sequences_should_be_stripped
|
||||
with_settings :repositories_encodings => '' do
|
||||
s1 = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
|
||||
str = to_utf8(s1)
|
||||
str = to_utf8_for_repositories(s1)
|
||||
if str.respond_to?(:force_encoding)
|
||||
assert_equal "Texte encod? en ISO-8859-1.", str
|
||||
assert str.valid_encoding?
|
||||
|
|
Loading…
Reference in New Issue