Skip to content

Commit

Permalink
library/uri: insure string-like arguments are accepted for URI.join,
Browse files Browse the repository at this point in the history
URI#merge, URI#route_to, URI#route_from.
  • Loading branch information
marcandre committed Jul 21, 2010
1 parent 0cc4482 commit 6d2cbe4
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 6 deletions.
14 changes: 14 additions & 0 deletions library/uri/join_spec.rb
Expand Up @@ -14,6 +14,20 @@
end
end

ruby_bug "redmine:3506", "1.9.2" do
it "accepts string-like arguments with to_str" do
str = mock('string-like')
str.should_receive(:to_str).and_return("http://ruby-lang.org")
str2 = mock('string-like also')
str2.should_receive(:to_str).and_return("foo/bar")
URI.join(str, str2).should == URI.parse("http://ruby-lang.org/foo/bar")
end
end

it "raises an error if given no argument" do
lambda{ URI.join }.should raise_error
end

it "doesn't create redundant '/'s" do
URI.join("http://localhost/", "/main.rbx").should == URI.parse("http://localhost/main.rbx")
end
Expand Down
8 changes: 8 additions & 0 deletions library/uri/merge_spec.rb
Expand Up @@ -11,4 +11,12 @@
it "accepts URI objects as argument" do
URI("http://localhost/").merge(URI("main.rbx")).should == URI.parse("http://localhost/main.rbx")
end

ruby_bug "redmine:3506", "1.9.2" do
it "accepts a string-like argument" do
str = mock('string-like')
str.should_receive(:to_str).and_return("foo/bar")
URI("http://localhost/").merge(str).should == URI.parse("http://localhost/foo/bar")
end
end
end
25 changes: 25 additions & 0 deletions library/uri/route_from_spec.rb
@@ -0,0 +1,25 @@
require File.expand_path('../../../spec_helper', __FILE__)
require 'uri'

describe "URI#route_from" do

#this could be split out a good bit better
it "gives the minimal difference between the current URI and the target" do
URI("http://example.com/a.html").route_from('http://example.com/a.html').to_s.should == ""
URI("http://example.com/a.html").route_from('http://example.com/b.html').to_s.should == "a.html"
URI("http://example.com/a/").route_from('http://example.com/b/').to_s.should == "../a/"
URI("http://example.com/b/").route_from('http://example.com/a/c').to_s.should == "../b/"
URI("http://example.com/b/").route_from('http://example.com/a/b/').to_s.should == "../../b/"
URI("http://example.com/b/").route_from('http://EXAMPLE.cOm/a/b/').to_s.should == "../../b/"
URI("http://example.net/b/").route_from('http://example.com/a/b/').to_s.should == "//example.net/b/"
URI("mailto:foo@example.com#bar").route_from('mailto:foo@example.com').to_s.should == "#bar"
end

ruby_bug "redmine:3506", "1.9.2" do
it "accepts a string-like argument" do
str = mock('string-like')
str.should_receive(:to_str).and_return("http://example.com/b.html")
URI("http://example.com/a.html").route_from(str).to_s.should == "a.html"
end
end
end
19 changes: 13 additions & 6 deletions library/uri/route_to.rb → library/uri/route_to_spec.rb
Expand Up @@ -11,11 +11,18 @@
URI("http://example.com/a/c").route_to('http://example.com/b/').to_s.should == "../b/"
URI("http://example.com/a/b/").route_to('http://example.com/b/').to_s.should == "../../b/"
URI("http://example.com/a/b/").route_to('http://EXAMPLE.cOm/b/').to_s.should == "../../b/"
URI("http://example.com/a/b/").route_to('http://example.net/b/').to_s.should == "//example.net/b/"
URI("mailto:foo@example.com").route_to('mailto:foo@example.com#bar').to_s.should == "#bar"
URI("http://example.com/a/b/").route_to('http://example.net/b/').to_s.should == "//example.net/b/"
URI("mailto:foo@example.com").route_to('mailto:foo@example.com#bar').to_s.should == "#bar"

#this was a little surprising to me
URI("mailto:foo@example.com#bar").route_to('mailto:foo@example.com').to_s.should == ""
URI("mailto:foo@example.com#bar").route_to('mailto:foo@example.com').to_s.should == ""
end

ruby_bug "redmine:3506", "1.9.2" do
it "accepts a string-like argument" do
str = mock('string-like')
str.should_receive(:to_str).and_return("http://example.com/b.html")
URI("http://example.com/a.html").route_to(str).to_s.should == "b.html"
end
end

end
end
6 changes: 6 additions & 0 deletions library/uri/uri_spec.rb
Expand Up @@ -11,6 +11,12 @@
Kernel::URI("http://ruby-lang.org").should == result
end

it "converts its argument with to_str" do
str = mock('string-like')
str.should_receive(:to_str).and_return("http://ruby-lang.org")
URI(str).should == URI.parse("http://ruby-lang.org")
end

ruby_bug "redmine:3505", "1.9.2" do
it "returns the argument if it is a URI object" do
result = URI.parse("http://ruby-lang.org")
Expand Down

0 comments on commit 6d2cbe4

Please sign in to comment.