X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/1bcc2242c0a5bc58abb0ab23964d474af04923fa..79284559afc15f462b0a93e3ff581b350728bc70:/test/unit/message_test.rb diff --git a/test/unit/message_test.rb b/test/unit/message_test.rb index 4de1a7b29..e95c698c9 100644 --- a/test/unit/message_test.rb +++ b/test/unit/message_test.rb @@ -3,6 +3,8 @@ require File.dirname(__FILE__) + '/../test_helper' class MessageTest < Test::Unit::TestCase fixtures :messages, :users + EURO = "\xe2\x82\xac" #euro symbol + # This needs to be updated when new fixtures are added # or removed. def test_check_message_count @@ -30,5 +32,36 @@ class MessageTest < Test::Unit::TestCase message.sender = nil message.recipient = nil assert !message.valid? + + assert_raise(ActiveRecord::RecordNotFound) { User.find(0) } + message.from_user_id = 0 + message.to_user_id = 0 + assert_raise(ActiveRecord::RecordInvalid) {message.save!} + end + + def test_utf8_roundtrip + (1..255).each do |i| + assert_message_ok('c', i) + assert_message_ok(EURO, i) + end + end + + def test_length_oversize + assert_raise(ActiveRecord::RecordInvalid) { make_message('c', 256).save! } + assert_raise(ActiveRecord::RecordInvalid) { make_message(EURO, 256).save! } end + + def make_message(char, count) + message = messages(:one) + message.title = char * count + return message + end + + def assert_message_ok(char, count) + message = make_message(char, count) + assert message.save! + response = message.class.find(message.id) # stand by for some über-generalisation... + assert_equal char * count, response.title, "message with #{count} #{char} chars (i.e. #{char.length*count} bytes) fails" + end + end