Skip to content

Commit 89b45d6

Browse files
committed
Restore default behaviour for with(path:).
Fixes <socketry/cloudflare#75>.
1 parent 21ce240 commit 89b45d6

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

lib/protocol/http/reference.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def base
120120
# @argument fragment [String] Set the fragment to this value.
121121
# @argument pop [Boolean] If the path contains a trailing filename, pop the last component of the path before appending the new path.
122122
# @argument merge [Boolean] If the parameters are specified, merge them with the existing parameters.
123-
def with(path: nil, parameters: nil, fragment: @fragment, pop: true, merge: true)
123+
def with(path: nil, parameters: nil, fragment: @fragment, pop: false, merge: true)
124124
if @parameters
125125
if parameters and merge
126126
parameters = @parameters.merge(parameters)

test/protocol/http/reference.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@
5050
end
5151

5252
with '#with' do
53+
it "can nest paths" do
54+
reference = subject.new('/foo')
55+
expect(reference.path).to be == '/foo'
56+
57+
nested_resource = reference.with(path: 'bar')
58+
expect(nested_resource.path).to be == '/foo/bar'
59+
end
60+
5361
it "can update path" do
5462
copy = reference.with(path: "foo/bar.html")
5563
expect(copy.path).to be == "/foo/bar.html"
@@ -113,13 +121,13 @@
113121
let(:reference) {subject.new('foo/bar/baz.html', nil, nil, nil)}
114122

115123
it "can compute new relative path" do
116-
copy = reference.with(path: "../index.html")
124+
copy = reference.with(path: "../index.html", pop: true)
117125

118126
expect(copy.path).to be == "foo/index.html"
119127
end
120128

121129
it "can compute relative path with more uplevels" do
122-
copy = reference.with(path: "../../../index.html")
130+
copy = reference.with(path: "../../../index.html", pop: true)
123131

124132
expect(copy.path).to be == "../index.html"
125133
end

0 commit comments

Comments
 (0)