From 0c95e0543f8e0ffc7e7b3d33799b78e03c1049d2 Mon Sep 17 00:00:00 2001 From: Patrick J Cherry Date: Tue, 1 May 2012 13:41:01 +0100 Subject: Updated sender to try and get things into UTF8 where poss. --- test/tc_mauve_sender.rb | 79 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 test/tc_mauve_sender.rb (limited to 'test') diff --git a/test/tc_mauve_sender.rb b/test/tc_mauve_sender.rb new file mode 100644 index 0000000..7db06c1 --- /dev/null +++ b/test/tc_mauve_sender.rb @@ -0,0 +1,79 @@ +$:.unshift "../lib" + +require 'th_mauve_resolv' +require 'test/unit' +require 'pp' +require 'timecop' +require 'mauve/sender' +require 'locale' +require 'iconv' + + +class TcMauveSender < Test::Unit::TestCase + include Mauve + + def setup + Timecop.freeze(Time.local(2011,8,1,0,0,0,0)) + end + + def teardown + Timecop.return + end + + def test_sanitise + Locale.clear + Locale.current = "en_GB.ISO-8859-1" + + # + # Set up a couple of crazy sources. + # + utf8_source = "Å ðîßtáñt plàñët" + iso88591_source = Iconv.conv(Locale.current.charset, "UTF-8", utf8_source) + + # + # Make sure our two sources are distinct + # + assert(iso88591_source != utf8_source) + + sender = Sender.new("test-1.example.com") + update = Mauve::Proto::AlertUpdate.new + update.source = iso88591_source + update.replace = false + + alert = Mauve::Proto::Alert.new + update.alert << alert + + alert_cleared = Mauve::Proto::Alert.new + update.alert << alert_cleared + alert_cleared.clear_time = Time.now.to_i + + # + # Make sure the update has the correct source + # + assert_equal(iso88591_source, update.source) + + # + # Sanitize + # + update = sender.sanitize(update) + + # + # Now make sure the sanitization has changed it back to UTF-8 + # + assert_equal(utf8_source, update.source) + + # + # Now make sure the transmission time + id have been set + # + assert_equal(Time.now.to_i, update.transmission_time) + assert_kind_of(Integer, update.transmission_id) + + # + # Make sure that the alert has its raise time set by default + # + assert_equal(Time.now.to_i, alert.raise_time) + assert_equal(0, alert_cleared.raise_time) + end + + +end -- cgit v1.2.3 From d9954431406a06305a5d970909489d90864f62df Mon Sep 17 00:00:00 2001 From: Patrick J Cherry Date: Tue, 1 May 2012 14:02:31 +0100 Subject: Tidied up sqlite mutex nonsense. --- lib/dm-sqlite-adapter-with-mutex.rb | 15 +++------------ test/tc_mauve_database_peculiarities.rb | 9 +++++++++ 2 files changed, 12 insertions(+), 12 deletions(-) (limited to 'test') diff --git a/lib/dm-sqlite-adapter-with-mutex.rb b/lib/dm-sqlite-adapter-with-mutex.rb index 2842c5e..6c5c022 100644 --- a/lib/dm-sqlite-adapter-with-mutex.rb +++ b/lib/dm-sqlite-adapter-with-mutex.rb @@ -5,20 +5,11 @@ require 'dm-sqlite-adapter' require 'monitor' -ADAPTER = DataMapper::Adapters::SqliteAdapter +class DataMapper::Adapters::SqliteAdapter -# better way to alias a private method? (other than "don't"? :) ) -ADAPTER.__send__(:alias_method, :initialize_old, :initialize) -ADAPTER.__send__(:undef_method, :initialize) -ADAPTER.__send__(:alias_method, :with_connection_old, :with_connection) -ADAPTER.__send__(:undef_method, :with_connection) + include MonitorMixin -class ADAPTER - - def initialize(*a) - extend(MonitorMixin) - initialize_old(*a) - end + alias_method :with_connection_old, :with_connection private diff --git a/test/tc_mauve_database_peculiarities.rb b/test/tc_mauve_database_peculiarities.rb index 9eb612e..b29bd95 100644 --- a/test/tc_mauve_database_peculiarities.rb +++ b/test/tc_mauve_database_peculiarities.rb @@ -81,5 +81,14 @@ class TcMauveDatabaseSqlite3Peculiarities < TcMauveDatabasePeculiarities # @pg_conn = PGconn.open(:dbname => @temp_db) @db_url = "sqlite3::memory:" end + + # + # This just makes sure our mixin has been added to the SqliteAdapter. + # + def test_has_mixin + assert DataMapper::Adapters::SqliteAdapter.private_instance_methods.include?("with_connection_old") + assert DataMapper::Adapters::SqliteAdapter.public_instance_methods.include?("synchronize") + end + end -- cgit v1.2.3 From fafac666b1d9f1b73fe4330af6b3c14d57ded2cb Mon Sep 17 00:00:00 2001 From: Patrick J Cherry Date: Tue, 1 May 2012 14:03:16 +0100 Subject: Don't clean stuff if not needed. --- test/th_mauve.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/th_mauve.rb b/test/th_mauve.rb index 99eaaed..4ec8dc5 100644 --- a/test/th_mauve.rb +++ b/test/th_mauve.rb @@ -1,5 +1,4 @@ require 'test/unit' -require 'mauve/datamapper' require 'timecop' require 'log4r' require 'pp' @@ -94,12 +93,12 @@ module Mauve end def setup_database - DataMapper::Model.raise_on_save_failure = true + DataMapper::Model.raise_on_save_failure = true if defined?(DataMapper::Model) end def teardown_database - DataObjects::Pooling.pools.each{|pool| pool.dispose} - end + DataObjects::Pooling.pools.each{|pool| pool.dispose} if defined?(DataObjects::Pooling) + end def setup_time Timecop.freeze(Time.local(2011,8,1,0,0,0,0)) @@ -110,7 +109,7 @@ module Mauve end def reset_mauve_configuration - Mauve::Configuration.current = Mauve::Configuration.new + Mauve::Configuration.current = Mauve::Configuration.new if defined?(Mauve::Configuration) end def reset_all_singletons -- cgit v1.2.3