From 283de5af02cad8141f3c28d57b0d0855e71b9148 Mon Sep 17 00:00:00 2001 From: hsbt Date: Mon, 12 Sep 2016 04:46:27 +0000 Subject: * lib/uri/mailto.rb: Removed needless `return` and use `.`` instead of `::` with class method. * test/uri/test_mailto.rb: Added tests for coverage. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56139 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ lib/uri/mailto.rb | 10 +++++----- test/uri/test_mailto.rb | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1144544a57..566d8a9c3f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Mon Sep 12 13:46:23 2016 Anton Davydov + + * lib/uri/mailto.rb: Removed needless `return` and use `.`` instead of `::` + with class method. + * test/uri/test_mailto.rb: Added tests for coverage. + Sun Sep 11 21:30:26 2016 Kazuhiro NISHIYAMA * NEWS: News about Module.used_modules. diff --git a/lib/uri/mailto.rb b/lib/uri/mailto.rb index 7299550d3f..b9e98e66bb 100644 --- a/lib/uri/mailto.rb +++ b/lib/uri/mailto.rb @@ -84,7 +84,7 @@ module URI # puts m3.to_s -> mailto:listman@example.com?subject=subscribe # def self.build(args) - tmp = Util::make_components_hash(self, args) + tmp = Util.make_components_hash(self, args) case tmp[:to] when Array @@ -118,7 +118,7 @@ module URI end end - return super(tmp) + super(tmp) end # @@ -187,7 +187,7 @@ module URI end end - return true + true end private :check_to @@ -214,7 +214,7 @@ module URI "bad component(expected opaque component): #{v}" end - return true + true end private :check_headers @@ -282,7 +282,7 @@ module URI end end - return "To: #{to} + "To: #{to} #{head} #{body} " diff --git a/test/uri/test_mailto.rb b/test/uri/test_mailto.rb index c09b001e0f..39a0f9cdeb 100644 --- a/test/uri/test_mailto.rb +++ b/test/uri/test_mailto.rb @@ -97,6 +97,11 @@ class TestMailTo < Test::Unit::TestCase ok[-1] << {:to => 'listman@example.com', :headers => [['subject', 'subscribe']]} ok[-1] << {:to => 'listman@example.com', :headers => [['subject', 'subscribe']]} + # mailto:listman@example.com?subject=subscribe + ok << ["mailto:listman@example.com?subject=subscribe"] + ok[-1] << {:to => 'listman@example.com', :headers => { 'subject' => 'subscribe' }} + ok[-1] << {:to => 'listman@example.com', :headers => 'subject=subscribe' } + ok_all = ok.flatten.join("\0") # mailto:joe@example.com?cc=bob@example.com?body=hello ; WRONG! @@ -129,6 +134,52 @@ class TestMailTo < Test::Unit::TestCase assert_equal(ok_all, ok.flatten.join("\0")) end + def test_initializer + assert_raise(InvalidComponentError) do + URI::MailTo.new('mailto', 'sdmitry:bla', 'localhost', '2000', nil, + 'joe@example.com', nil, nil, 'subject=Ruby') + end + end + + def test_check_to + u = URI::MailTo.build(['joe@example.com', 'subject=Ruby']) + + assert_raise(InvalidComponentError) do + u.to = '#1@mail.com' + end + + assert_raise(InvalidComponentError) do + u.to = '@invalid.email' + end + end + + def test_to_s + u = URI::MailTo.build([nil, 'subject=Ruby']) + + u.send(:set_to, nil) + assert_equal('mailto:?subject=Ruby', u.to_s) + + u.fragment = 'test' + assert_equal('mailto:?subject=Ruby#test', u.to_s) + end + + def test_to_mailtext + results = [] + results << ["To: ruby-list@ruby-lang.org\nSubject: subscribe\n\n\n"] + results[-1] << { to: 'ruby-list@ruby-lang.org', headers: { 'subject' => 'subscribe' } } + + results << ["To: ruby-list@ruby-lang.org\n\nBody\n"] + results[-1] << { to: 'ruby-list@ruby-lang.org', headers: { 'body' => 'Body' } } + + results << ["To: ruby-list@ruby-lang.org, cc@ruby-lang.org\n\n\n"] + results[-1] << { to: 'ruby-list@ruby-lang.org', headers: { 'to' => 'cc@ruby-lang.org' } } + + results.each do |expected, params| + u = URI::MailTo.build(params) + assert_equal(expected, u.to_mailtext) + end + end + def test_select u = URI.parse('mailto:joe@example.com?cc=bob@example.com&body=hello') assert_equal(uri_to_ary(u), u.select(*u.component)) -- cgit v1.2.3