Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F115102
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/test/tesla/middleware/path_params_test.exs b/test/tesla/middleware/path_params_test.exs
index 886c7c8..a6a0da6 100644
--- a/test/tesla/middleware/path_params_test.exs
+++ b/test/tesla/middleware/path_params_test.exs
@@ -1,37 +1,61 @@
defmodule Tesla.Middleware.PathParamsTest do
use ExUnit.Case, async: true
alias Tesla.Env
@middleware Tesla.Middleware.PathParams
test "no params" do
assert {:ok, env} = @middleware.call(%Env{url: "/users/:id"}, [], nil)
assert env.url == "/users/:id"
end
test "passed params" do
opts = [path_params: [id: 42]]
assert {:ok, env} = @middleware.call(%Env{url: "/users/:id", opts: opts}, [], nil)
assert env.url == "/users/42"
end
test "value is not given" do
opts = [path_params: [y: 42]]
assert {:ok, env} = @middleware.call(%Env{url: "/users/:x", opts: opts}, [], nil)
assert env.url == "/users/:x"
end
test "value is nil" do
opts = [path_params: [id: nil]]
assert {:ok, env} = @middleware.call(%Env{url: "/users/:id", opts: opts}, [], nil)
assert env.url == "/users/:id"
end
test "placeholder contains another placeholder" do
opts = [path_params: [id: 1, id_post: 2]]
assert {:ok, env} = @middleware.call(%Env{url: "/users/:id/p/:id_post", opts: opts}, [], nil)
assert env.url == "/users/1/p/2"
end
+
+ test "placeholder start by number" do
+ opts = [path_params: ["1id": 1, id_post: 2]]
+
+ assert {:ok, env} = @middleware.call(%Env{url: "/users/:1id/p/:id_post", opts: opts}, [], nil)
+
+ assert env.url == "/users/:1id/p/2"
+ end
+
+ test "placeholder with only 1 character" do
+ opts = [path_params: [i: 1, id_post: 2]]
+
+ assert {:ok, env} = @middleware.call(%Env{url: "/users/:i/p/:id_post", opts: opts}, [], nil)
+
+ assert env.url == "/users/1/p/2"
+ end
+
+ test "placeholder with numbers, underscore and characters" do
+ opts = [path_params: [id_1_a: 1, id_post: 2]]
+
+ assert {:ok, env} = @middleware.call(%Env{url: "/users/:id_1_a/p/:id_post", opts: opts}, [], nil)
+
+ assert env.url == "/users/1/p/2"
+ end
end
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Wed, Nov 27, 7:32 AM (1 d, 21 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
40089
Default Alt Text
(2 KB)
Attached To
Mode
R28 tesla
Attached
Detach File
Event Timeline
Log In to Comment