-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Raise when adding a duplicate route (#42)
- Loading branch information
1 parent
61a3a4b
commit ef4d704
Showing
6 changed files
with
132 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
require "./spec_helper" | ||
|
||
describe LuckyRouter::PathNormalizer do | ||
describe ".normalize" do | ||
it "turns regular path parts into slash delimitted string" do | ||
path_parts = LuckyRouter::PathPart.split_path("/api/v1/users") | ||
|
||
result = LuckyRouter::PathNormalizer.normalize(path_parts) | ||
|
||
result.should eq("/api/v1/users") | ||
end | ||
|
||
it "gives path variables a generic name" do | ||
path_parts = LuckyRouter::PathPart.split_path("/users/:id") | ||
|
||
result = LuckyRouter::PathNormalizer.normalize(path_parts) | ||
|
||
result.should eq("/users/:path_variable") | ||
end | ||
|
||
it "removes question mark from optional path" do | ||
path_parts = LuckyRouter::PathPart.split_path("/users/?name") | ||
|
||
result = LuckyRouter::PathNormalizer.normalize(path_parts) | ||
|
||
result.should eq("/users/name") | ||
end | ||
|
||
it "removes question mark and gives generic name to optional path variables" do | ||
path_parts = LuckyRouter::PathPart.split_path("/users/?:name") | ||
|
||
result = LuckyRouter::PathNormalizer.normalize(path_parts) | ||
|
||
result.should eq("/users/:path_variable") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
require "spec" | ||
require "../src/lucky_router" | ||
require "uuid" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class LuckyRouter::PathNormalizer | ||
DEFAULT_PATH_VARIABLE_NAME = ":path_variable" | ||
|
||
def self.normalize(path_parts : Array(PathPart)) : String | ||
path_parts.map { |path_part| normalize(path_part) }.join('/') | ||
end | ||
|
||
private def self.normalize(path_part : PathPart) : String | ||
path_part.path_variable? ? DEFAULT_PATH_VARIABLE_NAME : path_part.name | ||
end | ||
end |