Skip to content

Commit

Permalink
Add specs for allowing matching dynamic fragments at start
Browse files Browse the repository at this point in the history
Closes #17
  • Loading branch information
paulcsmith committed Apr 30, 2020
1 parent 5f96a4a commit 8b66bbd
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions spec/integration_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ describe LuckyRouter do
router.add("get", "#{(rand * 100).to_i}/new/edit", :fake_new_edit)
end

router.add("get", "/:organization", :organization)
router.add("get", "/:organization/:repo", :repo)
router.add("get", "/posts/:id", :post_index)
router.add("get", "/users", :index)
router.add("post", "/users", :create)
Expand All @@ -24,6 +26,8 @@ describe LuckyRouter do
router.add("get", "/complex_posts/:required/?:optional_1/?:optional_2", :posts_with_complex_params)

1000.times do
router.match!("get", "/luckyframework").payload.should eq :organization
router.match!("get", "/luckyframework/lucky").payload.should eq :repo
router.match!("get", "/posts/1").payload.should eq :post_index
router.match!("get", "/users").payload.should eq :index
router.match!("post", "/users").payload.should eq :create
Expand Down Expand Up @@ -100,6 +104,16 @@ describe LuckyRouter do
})
end

it "gets params when starting with dynamic paths" do
router = LuckyRouter::Matcher(Symbol).new
router.add("get", "/:organization/:repo", :unused)

router.match!("get", "/luckyframework/lucky").params.should eq({
"organization" => "luckyframework",
"repo" => "lucky",
})
end

it "does not add params if there is a static match" do
router = LuckyRouter::Matcher(Symbol).new
router.add("get", "/users/foo/tasks/bar", :show)
Expand Down

0 comments on commit 8b66bbd

Please sign in to comment.