Skip to content

Commit

Permalink
Merge 8747843 into f7ca044
Browse files Browse the repository at this point in the history
  • Loading branch information
josephmancuso authored Jul 1, 2018
2 parents f7ca044 + 8747843 commit b94aea9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions masonite/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,12 @@ def back(self, input_parameter='back'):
"""
self.redirect(self.input(input_parameter))
return self

def is_named_route(self, name, params={}):
if self._get_named_route(name, params) == self.path:
return True

return False

def contains(self, route):
return re.match(compile_route_to_regex(route), self.path)
Expand Down
16 changes: 16 additions & 0 deletions tests/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,21 @@ def test_request_sets_request_method(self):
assert request.get_request_method() == 'PUT'


def test_is_named_route(self):
app = App()
app.bind('Request', self.request)
app.bind('WebRoutes', [
get('/test/url', None).name('test.url'),
get('/test/url/@id', None).name('test.id')
])
request = app.make('Request').load_app(app)

request.path = '/test/url'
assert request.is_named_route('test.url')

request.path = '/test/url/1'
assert request.is_named_route('test.id', {'id': 1})

def test_request_url_from_controller(self):
app = App()
app.bind('Request', self.request)
Expand All @@ -357,6 +372,7 @@ def test_request_url_from_controller(self):
assert request.url_from_controller('ControllerTest@show', {'id': 1}) == '/test/url/1'
assert request.url_from_controller(TestController.show, {'id': 1}) == '/test/url/controller/1'


def test_contains_for_path_detection(self):
self.request.path = '/test/path'
assert self.request.contains('/test/*')
Expand Down

0 comments on commit b94aea9

Please sign in to comment.