Skip to content

Commit b5aa8fb

Browse files
committed
Added some tests for toptal#27
1 parent 1f3318a commit b5aa8fb

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

lib/haste/uploader.rb

+6-3
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,13 @@ def upload_raw(data)
4141

4242
private
4343

44+
def post_path
45+
parsed_uri = URI.parse(server_url)
46+
"#{parsed_uri.path}/documents"
47+
end
48+
4449
def do_post(data)
45-
posturi= URI.parse(server_url)
46-
posturi.path += '/documents'
47-
connection.post(posturi.path, data)
50+
connection.post(post_path, data)
4851
end
4952

5053
def connection

spec/examples/uploader_spec.rb

+36
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,42 @@
126126

127127
end
128128

129+
describe :post_path do
130+
131+
let(:post_path) { uploader.send(:post_path) }
132+
133+
context "when the server URL doesn't have a path" do
134+
135+
let(:base) { 'http://example.com/' }
136+
137+
it 'should return /documents' do
138+
expect(post_path).to eq('/documents')
139+
end
140+
141+
end
142+
143+
context "when the server URL has a path" do
144+
145+
let(:base) { 'http://example.com/friend' }
146+
147+
it 'should return /documents' do
148+
expect(post_path).to eq('/friend/documents')
149+
end
150+
151+
end
152+
153+
context "when the server URL has a path that ends with slash" do
154+
155+
let(:base) { 'http://example.com/friend/' }
156+
157+
it 'should return /documents appended to the path without a duplicate slash' do
158+
expect(post_path).to eq('/friend/documents')
159+
end
160+
161+
end
162+
163+
end
164+
129165
describe :server_url do
130166

131167
let(:server_url) { uploader.server_url }

0 commit comments

Comments
 (0)