spec/route_spec.rb in rasti-web-0.2.3 vs spec/route_spec.rb in rasti-web-1.0.0

- old
+ new

@@ -2,10 +2,14 @@ describe Rasti::Web::Route do ROUTES = [ '/', + '/*/wildcard/action', + '/wildcard/*/action', + '/wildcard/*/action/:id', + '/wildcard/*', '/resource', '/resource/:id/:action', '/:resource(/:id(/:action))' ] @@ -43,20 +47,62 @@ it 'Params' do path = '/resource/123/show' route = route_for path route.pattern.must_equal '/resource/:id/:action' - route.extract_params(path).must_equal 'id' => '123', 'action' => 'show' + route.extract_params(path).must_equal id: '123', action: 'show' route.call({}).must_equal RESPONSE end ['/other', '/other/456', '/other/456/edit'].each do |path| it "Optional params '#{path}'" do route = route_for path sections = path[1..-1].split('/') route.pattern.must_equal '/:resource(/:id(/:action))' - route.extract_params(path).must_equal 'resource' => sections[0], 'id' => sections[1], 'action' => sections[2] + route.extract_params(path).must_equal resource: sections[0], id: sections[1], action: sections[2] + route.call({}).must_equal RESPONSE + end + end + + describe 'Wildcard' do + it 'Head' do + path = '/section/sub_section/wildcard/action' + + route = route_for path + + route.pattern.must_equal '/*/wildcard/action' + route.extract_params(path).must_equal wildcard: 'section/sub_section' + route.call({}).must_equal RESPONSE + end + + it 'Middle' do + path = '/wildcard/section/sub_section/action' + + route = route_for path + + route.pattern.must_equal '/wildcard/*/action' + route.extract_params(path).must_equal wildcard: 'section/sub_section' + route.call({}).must_equal RESPONSE + end + + ['/wildcard', '/wildcard/123', '/wildcard/123/edit'].each do |path| + it "Tail #{path}" do + route = route_for path + + route.pattern.must_equal '/wildcard/*' + route.extract_params(path).must_equal wildcard: path["/wildcard/".size..-1] + route.call({}).must_equal RESPONSE + end + end + + it 'Params' do + path = '/wildcard/section/sub_section/action/123' + + route = route_for path + + route.pattern.must_equal '/wildcard/*/action/:id' + route.extract_params(path).must_equal wildcard: 'section/sub_section', id: '123' route.call({}).must_equal RESPONSE end end end \ No newline at end of file