Skip to content

Reenable routes with optional portions #275

Description

@timriley

All the following examples from spec/integration/hanami/router/generation_spec.rb are skipped.

I think these were most likely disabled when we first introduced the trie structure for 2.0, and then we did not reintroduce this behaviour afterwards.

I think this is useful to have. We should have a look to see whether we can achieve it again.

context "variable with optional format" do
  let(:router) do
    described_class.new do
      get "/:var(.:format)", as: :a, to: -> {}
    end
  end

  it "generates relative and absolute URLs" do
    runner.run!([
      [:a, "/test.html", {var: "test", format: "html"}],
      [:a, "/test", {var: "test"}]
    ])
  end
end

context "variable with optional variable" do
  let(:router) do
    described_class.new do
      get "/:var1(/:var2)", as: :a, to: -> {}
    end
  end

  xit "generates relative and absolute URLs" do
    runner.run!([
      [:a, "/foo/bar", {var1: "foo", var2: "bar"}],
      [:a, "/foo", {var1: "foo"}]
    ])
  end
end

context "variable with optional variable and format" do
  let(:router) do
    described_class.new do
      get "/:var1(/:var2.:format)", as: :a, to: -> {}
    end
  end

  xit "generates relative and absolute URLs" do
    runner.run!([
      [:a, "/test/test2.html", {var1: "test", var2: "test2", format: "html"}]
    ])
  end
end

context "variable with optional nested variables" do
  let(:router) do
    described_class.new do
      get "/:var1(/:var2(/:var3))", as: :a, to: -> {}
    end
  end

  xit "generates relative and absolute URLs" do
    runner.run!([
      [:a, "/var/fooz/baz", {var1: "var", var2: "fooz", var3: "baz"}],
      [:a, "/var/fooz", {var1: "var", var2: "fooz"}],
      [:a, "/var", {var1: "var"}]
    ])
  end
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions