Skip to content

Commit

Permalink
Add missing specs for the routes management command
Browse files Browse the repository at this point in the history
  • Loading branch information
ellmetha committed Aug 22, 2024
1 parent 91328a9 commit ef00d0d
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
56 changes: 56 additions & 0 deletions spec/marten/cli/manage/command/routes_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
require "./spec_helper"

describe Marten::CLI::Manage::Command::Routes do
describe "#run" do
it "displays top-level routes as expected" do
stdout = IO::Memory.new
stderr = IO::Memory.new

command = Marten::CLI::Manage::Command::Routes.new(
options: [] of String,
stdout: stdout,
stderr: stderr
)

command.run

output = stdout.rewind.gets_to_end
output.includes?("/dummy/<id:int>/and/<scope:slug>").should be_true
output.includes?("[dummy_with_id_and_scope]").should be_true
end

it "displays nested routes involving a single namespace as expected" do
stdout = IO::Memory.new
stderr = IO::Memory.new

command = Marten::CLI::Manage::Command::Routes.new(
options: [] of String,
stdout: stdout,
stderr: stderr
)

command.run

output = stdout.rewind.gets_to_end
output.includes?("/nested-1/dummy/<id:int>").should be_true
output.includes?("[nested_1:dummy_with_id]").should be_true
end

it "displays nested routes involving multiple namespaces as expected" do
stdout = IO::Memory.new
stderr = IO::Memory.new

command = Marten::CLI::Manage::Command::Routes.new(
options: [] of String,
stdout: stdout,
stderr: stderr
)

command.run

output = stdout.rewind.gets_to_end
output.includes?("/nested-1/nested-2/dummy/<id:int>").should be_true
output.includes?("[nested_1:nested_2:dummy_with_id]").should be_true
end
end
end
10 changes: 10 additions & 0 deletions spec/test_project.cr
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ Marten.configure :test do |config|
config.media_files.root = "spec/media"
end

NESTED_ROUTES_2 = Marten::Routing::Map.draw do
path "/dummy/<id:int>", DummyHandler, name: "dummy_with_id"
end

NESTED_ROUTES_1 = Marten::Routing::Map.draw do
path "/dummy/<id:int>", DummyHandler, name: "dummy_with_id"
path "/nested-2", NESTED_ROUTES_2, name: "nested_2"
end

Marten.routes.draw do
path "/dummy", DummyHandler, name: "dummy"
path "/dummy/<id:int>", DummyHandler, name: "dummy_with_id"
Expand All @@ -111,4 +120,5 @@ Marten.routes.draw do
path "/cookie-value-set", CookieValueSetHandler, name: "cookie_value_set"
path "/simple-schema", SimpleSchemaHandler, name: "simple_schema"
path "/simple-file-schema", SimpleFileSchemaHandler, name: "simple_file_schema"
path "/nested-1", NESTED_ROUTES_1, name: "nested_1"
end

0 comments on commit ef00d0d

Please sign in to comment.