diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/mauve_test_helper.rb | 2 | ||||
-rw-r--r-- | test/tc_mauve_authentication.rb | 2 | ||||
-rw-r--r-- | test/tc_mauve_configuration_builders_person.rb | 3 | ||||
-rw-r--r-- | test/tc_mauve_database_peculiarities.rb | 69 | ||||
-rw-r--r-- | test/tc_mauve_web_interface.rb | 10 |
5 files changed, 44 insertions, 42 deletions
diff --git a/test/mauve_test_helper.rb b/test/mauve_test_helper.rb index 8653bd5..ca2db61 100644 --- a/test/mauve_test_helper.rb +++ b/test/mauve_test_helper.rb @@ -74,7 +74,7 @@ module MauveTestHelper # # [destination, alert, other_alerts] # - # e.g. destination will be an email address, phone number or xmpp ID, just + # e.g. destination will be an email address, or phone number, just # as in the configuration file. alert will be the subject of this # alert, and other_alerts will be the other notifications that # are relevant for this person at this time. diff --git a/test/tc_mauve_authentication.rb b/test/tc_mauve_authentication.rb index a770bc9..0f1a158 100644 --- a/test/tc_mauve_authentication.rb +++ b/test/tc_mauve_authentication.rb @@ -67,7 +67,7 @@ EOF end - def test_local_auth + def test_local_auth_again config=<<EOF failed_login_delay 0 diff --git a/test/tc_mauve_configuration_builders_person.rb b/test/tc_mauve_configuration_builders_person.rb index 76841a3..77bae3b 100644 --- a/test/tc_mauve_configuration_builders_person.rb +++ b/test/tc_mauve_configuration_builders_person.rb @@ -13,7 +13,6 @@ person("test1") { email "test1@example.com" sms "01234567890" - xmpp "test1@chat.example.com" password "topsekrit" @@ -35,7 +34,6 @@ EOF person = x.people["test1"] assert_equal("test1@example.com", person.email) assert_equal("01234567890", person.sms) - assert_equal("test1@chat.example.com", person.xmpp) assert_equal("topsekrit", person.password) # assert_equal(300, x.people["test1"].every) @@ -59,7 +57,6 @@ EOF assert_equal(nil, person.sms) assert_equal(nil, person.email) - assert_equal(nil, person.xmpp) assert_kind_of(Proc, person.low) assert_kind_of(Proc, person.normal) diff --git a/test/tc_mauve_database_peculiarities.rb b/test/tc_mauve_database_peculiarities.rb index ceef9ad..8696ce7 100644 --- a/test/tc_mauve_database_peculiarities.rb +++ b/test/tc_mauve_database_peculiarities.rb @@ -1,5 +1,5 @@ # encoding: utf-8 -$:.unshift "../lib" +$LOAD_PATH.unshift '../lib' require 'th_mauve' require 'mauve/datamapper' @@ -14,7 +14,7 @@ class TcMauveDatabasePeculiarities < Mauve::UnitTest def setup super setup_database - @temp_db = "mauve_test.#{10.times.collect{ rand(36).to_s(36) }.join}" + @temp_db = "mauve_test.#{Array.new(10) { rand(36).to_s(36) }.join}" end def teardown @@ -28,7 +28,7 @@ class TcMauveDatabasePeculiarities < Mauve::UnitTest # return unless @db_url - config=<<EOF + config = <<EOF server { database "#{@db_url}" } @@ -37,21 +37,21 @@ EOF Configuration.current = ConfigurationBuilder.parse(config) Server.instance.setup - x = Hash.new - x["en"] = "Please rush me my portable walrus polishing kit!" - x["fi"] = "Ole hyvä kiirehtiä minulle kannettavan mursu kiillotukseen pakki!" - x["jp"] = "私に私のポータブルセイウチの研磨キットを急いでください!" + x = {} + x['en'] = 'Please rush me my portable walrus polishing kit!' + x['fi'] = 'Ole hyvä kiirehtiä minulle kannettavan mursu kiillotukseen pakki!' + x['jp'] = '私に私のポータブルセイウチの研磨キットを急いでください!' %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 = str.encode(enc, :invalid => :replace, :undef => :replace, :replace => '?') - } + assert_nothing_raised("Failed to use iconv to convert to #{enc}") do + str = str.encode(enc, invalid: :replace, undef: :replace, replace: '?') + end alert = Alert.new( - :alert_id => "#{lang}:#{enc}", - :source => "test", - :subject => str + alert_id: "#{lang}:#{enc}", + source: 'test', + subject: str ) assert_nothing_raised("failed to insert #{enc}") { alert.save } @@ -60,30 +60,32 @@ EOF end end - - class TcMauveDatabasePostgresPeculiarities < TcMauveDatabasePeculiarities def setup super - system("createdb #{@temp_db} --encoding UTF8") - unless $?.success? - msg = "Skipping postgres tests, as DB creation (#{@temp_db}) failed." + + if ENV['POSTGRES_URL'] + @db_url = ENV['POSTGRES_URL'] @temp_db = nil - flunk(msg) + else + system("createdb #{@temp_db} --encoding UTF8") + unless $?.success? + msg = "Skipping postgres tests, as DB creation (#{@temp_db}) failed." + @temp_db = nil + omit(msg) + end + # @pg_conn = PGconn.open(:dbname => @temp_db) + @db_url = "postgres:///#{@temp_db}" end - # @pg_conn = PGconn.open(:dbname => @temp_db) - @db_url = "postgres:///#{@temp_db}" end def teardown - # @pg_conn.finish if @pg_conn.is_a?(PGconn) and @pg_conn.status == PGconn::CONNECTION_OK super (system("dropdb #{@temp_db}") || puts("Failed to drop #{@temp_db}")) if @temp_db end - def test_reminders_only_go_once - config=<<EOF + config = <<EOF server { database "#{@db_url}" use_notification_buffer false @@ -109,16 +111,16 @@ alert_group("default") { } EOF Configuration.current = ConfigurationBuilder.parse(config) - notification_buffer = Configuration.current.notification_methods["email"].deliver_to_queue + notification_buffer = Configuration.current.notification_methods['email'].deliver_to_queue Server.instance.setup - a = Alert.new( - :alert_id => "test", - :source => "test", - :subject => "test" + a = Alert.new( + alert_id: 'test', + source: 'test', + subject: 'test' ) - assert(a.raise!, "raise was not successful") + assert(a.raise!, 'raise was not successful') assert(a.saved?) assert_equal(1, notification_buffer.length) notification_buffer.pop @@ -133,17 +135,14 @@ EOF assert_equal(1, notification_buffer.length) notification_buffer.pop end - end - - end class TcMauveDatabaseSqlite3Peculiarities < TcMauveDatabasePeculiarities def setup super # @pg_conn = PGconn.open(:dbname => @temp_db) - @db_url = "sqlite3::memory:" + @db_url = 'sqlite3::memory:' end # @@ -153,6 +152,4 @@ class TcMauveDatabaseSqlite3Peculiarities < TcMauveDatabasePeculiarities assert DataMapper::Adapters::SqliteAdapter.private_instance_methods.include?(:with_connection_old) assert DataMapper::Adapters::SqliteAdapter.public_instance_methods.include?(:synchronize) end - end - diff --git a/test/tc_mauve_web_interface.rb b/test/tc_mauve_web_interface.rb index 54c9697..c93c25c 100644 --- a/test/tc_mauve_web_interface.rb +++ b/test/tc_mauve_web_interface.rb @@ -112,13 +112,21 @@ EOF assert last_response.body.include?("Mauve: Login") assert session['__FLASH__'].empty? - # Check we can access this page before logging in. + # Check we can't access this page before logging in. get '/alerts' assert(session['__FLASH__'].has_key?(:error),"The flash error wasn't set following forbidden access") follow_redirect! while last_response.redirect? assert_equal(403, last_response.status, "The HTTP status wasn't 403") assert last_response.body.include?("Mauve: Login") assert session['__FLASH__'].empty? + + # Check we can't access AJAX requests before logging in. + get '/ajax/alerts_table/raised/subject', {}, {:xhr => true} + refute(session['__FLASH__'].has_key?(:error), "The flash error shouldn't have been set from an AJAX call") + follow_redirect! while last_response.redirect? + assert_equal(403, last_response.status, "The HTTP status wasn't 403") + assert last_response.body.include?('You must be logged in to access this page') + assert session['__FLASH__'].empty? # # Try to falsify our login. |