Skip to content

Commit

Permalink
Get tests passing on ruby 2.0.0-p598
Browse files Browse the repository at this point in the history
  • Loading branch information
bmalex committed Apr 20, 2015
1 parent d92499d commit 2ec8ca7
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 31 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -18,7 +18,7 @@ gem "dm-transactions", "=1.2.0"
gem "dm-types", "=1.2.0"
gem "dm-validations", "=1.2.0"
gem "sanitize", "=2.0.3"
gem "rmail", "=0.17"
gem "rmail", "=1.1.0"
gem "xmpp4r", "=0.5.6"
gem "eventmachine", "=0.12.10"
gem "thin", "=1.2.4"
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Expand Up @@ -77,7 +77,7 @@ GEM
rack
rack-test (0.6.1)
rack (>= 1.0)
rmail (0.17)
rmail (1.1.0)
ruby_protobuf (0.4.11)
safe_yaml (1.0.4)
sanitize (2.0.3)
Expand Down Expand Up @@ -129,7 +129,7 @@ DEPENDENCIES
rack (= 1.3.4)
rack-protection (= 1.1.4)
rack-test (= 0.6.1)
rmail (= 0.17)
rmail (= 1.1.0)
ruby_protobuf (= 0.4.11)
sanitize (= 2.0.3)
simplecov
Expand Down
29 changes: 6 additions & 23 deletions lib/mauve/sender.rb
Expand Up @@ -7,12 +7,6 @@
# Do nothing -- these are bonus libraries :)
end

begin
require 'iconv' unless String.new.respond_to?(:encode)
rescue LoadError
# Do nothing -- these are bonus libraries :)
end

require 'mauve/mauve_resolv'
require 'mauve/mauve_time'
require 'mauve/proto'
Expand Down Expand Up @@ -172,16 +166,10 @@ def sanitize(update)
#
# Make sure all string fields are UTF8 -- to ensure the maximal amount of information is sent.
#
if value.is_a?(String)
if value.respond_to?(:encode)
value = value.encode("UTF-8", :undef => :replace, :invalid => :replace)
elsif defined? Iconv
value = Iconv.conv("UTF-8//IGNORE", from_charset, value)
end

update.__send__("#{field.name}=", value)
if value.respond_to?(:encode)
value = value.encode("UTF-8", :undef => :replace, :invalid => :replace)
end

update.__send__("#{field.name}=", value)
end

update.alert.each do |alert|
Expand All @@ -194,15 +182,10 @@ def sanitize(update)
#
# Make sure all string fields are UTF8 -- to ensure the maximal amount of information is sent.
#
if value.is_a?(String)
if value.respond_to?(:encode)
value = value.encode("UTF-8", :undef => :replace, :invalid => :replace)
elsif defined? Iconv
value = Iconv.conv("UTF-8//IGNORE", from_charset, value)
end

alert.__send__("#{field.name}=", value)
if value.respond_to?(:encode)
value = value.encode("UTF-8", :undef => :replace, :invalid => :replace)
end
alert.__send__("#{field.name}=", value)
end
end

Expand Down
5 changes: 2 additions & 3 deletions test/tc_mauve_database_peculiarities.rb
Expand Up @@ -7,7 +7,6 @@
require 'mauve/configuration'
require 'mauve/configuration_builder'
require 'mauve/configuration_builders'
require 'iconv'

class TcMauveDatabasePeculiarities < Mauve::UnitTest
include Mauve
Expand Down Expand Up @@ -43,10 +42,10 @@ def test_encoding
x["fi"] = "Ole hyvä kiirehtiä minulle kannettavan mursu kiillotukseen pakki!"
x["jp"] = "私に私のポータブルセイウチの研磨キットを急いでください!"

%w(UTF-8 WINDOWS-1252 SHIFT-JIS).each do |enc|
%w(UTF-8 WINDOWS-1252 SJIS).each do |enc|
x.each do |lang, str|
assert_nothing_raised("Failed to use iconv to convert to #{enc}") {
str = Iconv.conv(enc+"//IGNORE", "utf8", str)
str = str.encode(enc, :invalid => :replace, :undef => :replace, :replace => '?')
}

alert = Alert.new(
Expand Down
3 changes: 1 addition & 2 deletions test/tc_mauve_sender.rb
Expand Up @@ -7,7 +7,6 @@
require 'timecop'
require 'mauve/sender'
require 'locale'
require 'iconv'


class TcMauveSender < Test::Unit::TestCase
Expand All @@ -29,7 +28,7 @@ def test_sanitise
# Set up a couple of crazy sources.
#
utf8_source = "Å ðîßtáñt plàñët"
iso88591_source = Iconv.conv(Locale.current.charset, "UTF-8", utf8_source)
iso88591_source = utf8_source.encode(Locale.current.charset)

#
# Make sure our two sources are distinct
Expand Down

0 comments on commit 2ec8ca7

Please sign in to comment.