[前][次][番号順一覧][スレッド一覧]

ruby-changes:44067

From: hsbt <ko1@a...>
Date: Mon, 12 Sep 2016 13:46:34 +0900 (JST)
Subject: [ruby-changes:44067] hsbt:r56139 (trunk): * lib/uri/mailto.rb: Removed needless `return` and use `.`` instead of `::`

hsbt	2016-09-12 13:46:27 +0900 (Mon, 12 Sep 2016)

  New Revision: 56139

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56139

  Log:
    * lib/uri/mailto.rb: Removed needless `return` and use `.`` instead of `::`
      with class method.
    * test/uri/test_mailto.rb: Added tests for coverage.

  Modified files:
    trunk/ChangeLog
    trunk/lib/uri/mailto.rb
    trunk/test/uri/test_mailto.rb
Index: lib/uri/mailto.rb
===================================================================
--- lib/uri/mailto.rb	(revision 56138)
+++ lib/uri/mailto.rb	(revision 56139)
@@ -84,7 +84,7 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/mailto.rb#L84
     #    puts m3.to_s  ->  mailto:listman@e...?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 https://github.com/ruby/ruby/blob/trunk/lib/uri/mailto.rb#L118
         end
       end
 
-      return super(tmp)
+      super(tmp)
     end
 
     #
@@ -187,7 +187,7 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/mailto.rb#L187
         end
       end
 
-      return true
+      true
     end
     private :check_to
 
@@ -214,7 +214,7 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/mailto.rb#L214
           "bad component(expected opaque component): #{v}"
       end
 
-      return true
+      true
     end
     private :check_headers
 
@@ -282,7 +282,7 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/mailto.rb#L282
         end
       end
 
-      return "To: #{to}
+      "To: #{to}
 #{head}
 #{body}
 "
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 56138)
+++ ChangeLog	(revision 56139)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Sep 12 13:46:23 2016  Anton Davydov  <mail@d...>
+
+	* 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  <zn@m...>
 
 	* NEWS: News about Module.used_modules.
Index: test/uri/test_mailto.rb
===================================================================
--- test/uri/test_mailto.rb	(revision 56138)
+++ test/uri/test_mailto.rb	(revision 56139)
@@ -97,6 +97,11 @@ class TestMailTo < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/uri/test_mailto.rb#L97
     ok[-1] << {:to => 'listman@e...', :headers => [['subject', 'subscribe']]}
     ok[-1] << {:to => 'listman@e...', :headers => [['subject', 'subscribe']]}
 
+    # mailto:listman@e...?subject=subscribe
+    ok << ["mailto:listman@e...?subject=subscribe"]
+    ok[-1] << {:to => 'listman@e...', :headers => { 'subject' => 'subscribe' }}
+    ok[-1] << {:to => 'listman@e...', :headers => 'subject=subscribe' }
+
     ok_all = ok.flatten.join("\0")
 
     # mailto:joe@e...?cc=bob@e...?body=hello   ; WRONG!
@@ -129,6 +134,52 @@ class TestMailTo < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/uri/test_mailto.rb#L134
     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@e...', nil, nil, 'subject=Ruby')
+    end
+  end
+
+  def test_check_to
+    u = URI::MailTo.build(['joe@e...', 'subject=Ruby'])
+
+    assert_raise(InvalidComponentError) do
+      u.to = '#1@m...'
+    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@r...\nSubject: subscribe\n\n\n"]
+    results[-1] << { to: 'ruby-list@r...', headers: { 'subject' => 'subscribe' } }
+
+    results << ["To: ruby-list@r...\n\nBody\n"]
+    results[-1] << { to: 'ruby-list@r...', headers: { 'body' => 'Body' } }
+
+    results << ["To: ruby-list@r..., cc@r...\n\n\n"]
+    results[-1] << { to: 'ruby-list@r...', headers: { 'to' => 'cc@r...' } }
+
+    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@e...?cc=bob@e...&body=hello')
     assert_equal(uri_to_ary(u), u.select(*u.component))

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]