Skip to content

Commit

Permalink
Added support for LINK and UNLINK
Browse files Browse the repository at this point in the history
  • Loading branch information
jodosha committed Oct 4, 2016
1 parent 66b9a55 commit 85db62d
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 6 deletions.
38 changes: 38 additions & 0 deletions lib/hanami/router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,44 @@ def trace(path, options = {}, &blk)
@router.trace(path, options, &blk)
end

# Defines a route that accepts a LINK request for the given path.
#
# @param path [String] the relative URL to be matched
#
# @param options [Hash] the options to customize the route
# @option options [String,Proc,Class,Object#call] :to the endpoint
#
# @param blk [Proc] the anonymous proc to be used as endpoint for the route
#
# @return [Hanami::Routing::Route] this may vary according to the :route
# option passed to the constructor
#
# @see Hanami::Router#get
#
# @since x.x.x
def link(path, options = {}, &blk)
@router.link(path, options, &blk)
end

# Defines a route that accepts an UNLINK request for the given path.
#
# @param path [String] the relative URL to be matched
#
# @param options [Hash] the options to customize the route
# @option options [String,Proc,Class,Object#call] :to the endpoint
#
# @param blk [Proc] the anonymous proc to be used as endpoint for the route
#
# @return [Hanami::Routing::Route] this may vary according to the :route
# option passed to the constructor
#
# @see Hanami::Router#get
#
# @since x.x.x
def unlink(path, options = {}, &blk)
@router.unlink(path, options, &blk)
end

# Defines a root route (a GET route for '/')
#
# @param options [Hash] the options to customize the route
Expand Down
5 changes: 0 additions & 5 deletions lib/hanami/routing/http_router.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
require 'uri'
require 'http_router'
require 'hanami/utils/io'
require 'hanami/routing/endpoint_resolver'
require 'hanami/routing/route'
require 'hanami/routing/parsers'
require 'hanami/routing/force_ssl'
require 'hanami/routing/error'
require 'hanami/utils/path_prefix'

Hanami::Utils::IO.silence_warnings do
HttpRouter::Route::VALID_HTTP_VERBS = %w{GET POST PUT PATCH DELETE HEAD OPTIONS TRACE}
end

module Hanami
module Routing
# Invalid route
Expand Down
2 changes: 1 addition & 1 deletion test/mount_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@app = Rack::MockRequest.new(@router)
end

[ 'get', 'post', 'delete', 'put', 'patch', 'trace', 'options' ].each do |verb|
[ 'get', 'post', 'delete', 'put', 'patch', 'trace', 'options', 'link', 'unklink' ].each do |verb|
it "accepts #{ verb } for a class endpoint" do
@app.request(verb.upcase, '/backend', lint: true).body.must_equal 'home'
end
Expand Down
8 changes: 8 additions & 0 deletions test/namespace_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@
@app.request('TRACE', '/trees/cypress', lint: true).body.must_equal 'Trees (TRACE)!'
end

it 'recognizes options path' do
@router.namespace 'trees' do
options '/oak', to: ->(env) { [200, {}, ['Trees (OPTIONS)!']] }
end

@app.request('OPTIONS', '/trees/oak', lint: true).body.must_equal 'Trees (OPTIONS)!'
end

describe 'nested' do
it 'defines HTTP methods correctly' do
@router.namespace 'animals' do
Expand Down

0 comments on commit 85db62d

Please sign in to comment.