Skip to content

Commit

Permalink
Make class level ARTA::Route annotation consistent with method level (
Browse files Browse the repository at this point in the history
  • Loading branch information
Blacksmoke16 authored Dec 11, 2024
1 parent ae77304 commit 4274791
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,21 @@ class PrefixedController < ATH::Controller
def slash_param(id : String) : Nil; end
end

@[ARTA::Route("pos-prefix")]
class PositionalPrefixedController < ATH::Controller
@[ARTA::Post("")]
def empty : Nil; end

@[ARTA::Post("/")]
def slash : Nil; end

@[ARTA::Get("{id}")]
def empty_param(id : String) : Nil; end

@[ARTA::Get("/{id}")]
def slash_param(id : String) : Nil; end
end

@[ARTA::Route(
schemes: ["BAR", "foo", "baz"],
methods: ["foo", "baz", "bar"],
Expand Down Expand Up @@ -504,6 +519,46 @@ describe ATH::Routing::AnnotationRouteLoader do
path: "/prefix/{id}",
)
end

it "normalizes positional prefixed route paths" do
routes = ATH::Routing::AnnotationRouteLoader.populate_collection(PositionalPrefixedController).routes.to_a

routes.size.should eq 4

route = routes[0]

assert_route(
route,
name: "positional_prefixed_controller_empty",
path: "/pos-prefix",
methods: Set{"POST"}
)

route = routes[1]

assert_route(
route,
name: "positional_prefixed_controller_slash",
path: "/pos-prefix/",
methods: Set{"POST"}
)

route = routes[2]

assert_route(
route,
name: "positional_prefixed_controller_empty_param",
path: "/pos-prefix/{id}",
)

route = routes[3]

assert_route(
route,
name: "positional_prefixed_controller_slash_param",
path: "/pos-prefix/{id}",
)
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module Athena::Framework::Routing::AnnotationRouteLoader
}

if controller_ann = klass.annotation ARTA::Route
if (ann_path = controller_ann[:path]) && ann_path.is_a? HashLiteral
if (ann_path = (controller_ann[:path] || controller_ann[0])) && ann_path.is_a? HashLiteral
globals[:localized_paths] = ann_path
elsif ann_path != nil
ann_path = ann_path.resolve if ann_path.is_a?(Path)
Expand Down

0 comments on commit 4274791

Please sign in to comment.