mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
a3af2d1edb
commit
52f9d387e6
3 changed files with 62 additions and 5 deletions
|
@ -1,3 +1,9 @@
|
|||
Mon Sep 12 13:46:23 2016 Anton Davydov <mail@davydovanton.com>
|
||||
|
||||
* 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@mbf.nifty.com>
|
||||
|
||||
* NEWS: News about Module.used_modules.
|
||||
|
|
|
@ -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}
|
||||
"
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Add table
Reference in a new issue