spec/unit/mail_spec.rb in jpmobile-1.0.6 vs spec/unit/mail_spec.rb in jpmobile-1.0.7
- old
+ new
@@ -17,10 +17,35 @@
it "sets multi-tos" do
expect{@mail.to = ["a@hoge.com", "b@hoge.com"]}.to_not raise_error
end
end
+ describe "Non-mobile" do
+ before(:each) do
+ @mail = Mail.new do
+ subject "万葉"
+ from "ちはやふる <info@jpmobile-rails.org>"
+ end
+ end
+ context "has multipart body" do
+ before(:each) do
+ @mail.parts << Mail::Part.new { body "ほげ" }
+ @mail.parts << Mail::Part.new { body "ほげほげ" }
+ @mail.parts.each{|p| p.charset = "ISO-2022-JP" }
+ end
+ context "to_s" do
+ subject {
+ Mail.new ascii_8bit(@mail.to_s)
+ }
+ it "should be able to decode bodies" do
+ subject.parts[0].body == "ほげ"
+ subject.parts[1].body == "ほげほげ"
+ end
+ end
+ end
+ end
+
describe "AbstractMobile" do
before(:each) do
@mobile = Jpmobile::Mobile::AbstractMobile.new(nil, nil)
@mail.mobile = @mobile
@mail.to = "むすめふさほせ <info+to@jpmobile-rails.org>"
@@ -225,8 +250,54 @@
ascii_8bit(@mail.to_s).should match(Regexp.compile(Regexp.escape("=?ISO-2022-JP?B?GyRCJFAkSiQkJDMkSCRyPzQkNyRGJCokJCRGJGIkaSQkGyhC?=")))
ascii_8bit(@mail.to_s).should match(Regexp.compile(Regexp.escape("=?ISO-2022-JP?B?GyRCJD8kJCRINmw4QCRyRGgkOSRrOE4kS0pAPFIkTzBdGyhC?=")))
ascii_8bit(@mail.to_s).should match(Regexp.compile(Regexp.escape("=?ISO-2022-JP?B?GyRCO30kNyRGJCQkayROJEckORsoQg==?=")))
end
end
+ end
+ end
+
+ context "with attachments" do
+ before(:each) do
+ @mobile = Jpmobile::Mobile::AbstractMobile.new(nil, nil)
+ @mail.mobile = @mobile
+ @mail.to = "むすめふさほせ <info+to@jpmobile-rails.org>"
+ @photo = open(File.join(File.expand_path(File.dirname(__FILE__)), "email-fixtures/photo.jpg")).read
+ end
+
+ it "should encodes itself successfully" do
+ @mail.attachments['photo.jpg'] = @photo
+
+ lambda {
+ @mail.to_s
+ }.should_not raise_error
+ end
+
+ it "should encodes itself successfully with an inline attachment" do
+ @mail.attachments.inline['photo.jpg'] = @photo
+
+ lambda {
+ @mail.to_s
+ }.should_not raise_error
+ end
+ end
+
+ context "encoding conversion" do
+ before(:each) do
+ @mobile = Jpmobile::Mobile::AbstractMobile.new(nil, nil)
+ @mail.mobile = @mobile
+ @mail.to = "むすめふさほせ <info+to@jpmobile-rails.org>"
+ @photo = open(File.join(File.expand_path(File.dirname(__FILE__)), "email-fixtures/photo.jpg")).read
+ end
+
+ it "wave dash converting correctly" do
+ @mail.body = '10:00〜12:00'
+
+ ascii_8bit(@mail.to_s).should match(Regexp.compile(Regexp.escape(ascii_8bit("\x31\x30\x3a\x30\x30\x1b\x24\x42\x21\x41\x1b\x28\x42\x31\x32\x3a\x30\x30"))))
+ end
+
+ it "full width tilde converting correctly" do
+ @mail.body = "10:00#{[0xff5e].pack("U")}12:00"
+
+ ascii_8bit(@mail.to_s).should match(Regexp.compile(Regexp.escape(ascii_8bit("\x31\x30\x3a\x30\x30\x1b\x24\x42\x21\x41\x1b\x28\x42\x31\x32\x3a\x30\x30"))))
end
end
end