+ def test_from_mail_plain
+ mail = Mail.new do
+ from "from@example.com"
+ to "to@example.com"
+ subject "Test message"
+ date Time.now
+ content_type 'text/plain; charset=utf-8'
+ body "This is a test & a message"
+ end
+ message = Message.from_mail(mail, users(:normal_user), users(:public_user))
+ assert_equal users(:normal_user), message.sender
+ assert_equal users(:public_user), message.recipient
+ assert_equal mail.date, message.sent_on
+ assert_equal "Test message", message.title
+ assert_equal "This is a test & a message", message.body
+ assert_equal "text", message.body_format
+ end
+
+ def test_from_mail_html
+ mail = Mail.new do
+ from "from@example.com"
+ to "to@example.com"
+ subject "Test message"
+ date Time.now
+ content_type 'text/html; charset=utf-8'
+ body "<p>This is a <b>test</b> & a message</p>"
+ end
+ message = Message.from_mail(mail, users(:normal_user), users(:public_user))
+ assert_equal users(:normal_user), message.sender
+ assert_equal users(:public_user), message.recipient
+ assert_equal mail.date, message.sent_on
+ assert_equal "Test message", message.title
+ assert_match /^ *This is a test & a message *$/, message.body
+ assert_equal "text", message.body_format
+ end
+
+ def test_from_mail_multipart
+ mail = Mail.new do
+ from "from@example.com"
+ to "to@example.com"
+ subject "Test message"
+ date Time.now
+
+ text_part do
+ content_type 'text/plain; charset=utf-8'
+ body "This is a test & a message in text format"
+ end
+
+ html_part do
+ content_type 'text/html; charset=utf-8'
+ body "<p>This is a <b>test</b> & a message in HTML format</p>"
+ end
+ end
+ message = Message.from_mail(mail, users(:normal_user), users(:public_user))
+ assert_equal users(:normal_user), message.sender
+ assert_equal users(:public_user), message.recipient
+ assert_equal mail.date, message.sent_on
+ assert_equal "Test message", message.title
+ assert_equal "This is a test & a message in text format", message.body
+ assert_equal "text", message.body_format
+
+ mail = Mail.new do
+ from "from@example.com"
+ to "to@example.com"
+ subject "Test message"
+ date Time.now
+
+ html_part do
+ content_type 'text/html; charset=utf-8'
+ body "<p>This is a <b>test</b> & a message in HTML format</p>"
+ end
+ end
+ message = Message.from_mail(mail, users(:normal_user), users(:public_user))
+ assert_equal users(:normal_user), message.sender
+ assert_equal users(:public_user), message.recipient
+ assert_equal mail.date, message.sent_on
+ assert_equal "Test message", message.title
+ assert_match /^ *This is a test & a message in HTML format *$/, message.body
+ assert_equal "text", message.body_format
+ end
+
+ def test_from_mail_prefix
+ mail = Mail.new do
+ from "from@example.com"
+ to "to@example.com"
+ subject "[OpenStreetMap] Test message"
+ date Time.now
+ content_type 'text/plain; charset=utf-8'
+ body "This is a test & a message"
+ end
+ message = Message.from_mail(mail, users(:normal_user), users(:public_user))
+ assert_equal users(:normal_user), message.sender
+ assert_equal users(:public_user), message.recipient
+ assert_equal mail.date, message.sent_on
+ assert_equal "Test message", message.title
+ assert_equal "This is a test & a message", message.body
+ assert_equal "text", message.body_format
+ end
+
+private
+