1 require File.dirname(__FILE__) + '/../test_helper'
3 class MessageTest < Test::Unit::TestCase
4 fixtures :messages, :users
6 EURO = "\xe2\x82\xac" #euro symbol
8 # This needs to be updated when new fixtures are added
10 def test_check_message_count
11 assert_equal 2, Message.count
14 def test_check_empty_message_fails
16 assert !message.valid?
17 assert message.errors.invalid?(:title)
18 assert message.errors.invalid?(:body)
19 assert message.errors.invalid?(:sent_on)
20 assert true, message.message_read
23 def test_validating_msgs
24 message = messages(:one)
26 massage = messages(:two)
30 def test_invalid_send_recipient
31 message = messages(:one)
33 message.recipient = nil
34 assert !message.valid?
36 assert_raise(ActiveRecord::RecordNotFound) { User.find(0) }
37 message.from_user_id = 0
38 message.to_user_id = 0
39 assert_raise(ActiveRecord::RecordInvalid) {message.save!}
42 def test_utf8_roundtrip
44 assert_message_ok('c', i)
45 assert_message_ok(EURO, i)
49 def test_length_oversize
50 assert_raise(ActiveRecord::RecordInvalid) { make_message('c', 256).save! }
51 assert_raise(ActiveRecord::RecordInvalid) { make_message(EURO, 256).save! }
54 def make_message(char, count)
55 message = messages(:one)
56 message.title = char * count
60 def assert_message_ok(char, count)
61 message = make_message(char, count)
63 response = message.class.find(message.id) # stand by for some über-generalisation...
64 assert_equal char * count, response.title, "message with #{count} #{char} chars (i.e. #{char.length*count} bytes) fails"