From bb7dfdfceea4c5deb9fbc40065b6c56040457d40 Mon Sep 17 00:00:00 2001 From: "Gerasimos (Makis) Maropoulos" Date: Tue, 24 Mar 2020 02:12:10 +0200 Subject: [PATCH] fix https://github.com/kataras/iris/issues/1473 and add test for https://github.com/kataras/iris/issues/1468 https://github.com/kataras/iris/pull/1474 https://github.com/kataras/iris/pull/1475 --- .gitignore | 1 + context/context.go | 2 +- mvc/controller_test.go | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 0072ff552..9f686b6a4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .vscode _authortools +/_examples/issue-*/ .directory node_modules package-lock.json diff --git a/context/context.go b/context/context.go index 39fd73c59..52b6f812d 100644 --- a/context/context.go +++ b/context/context.go @@ -1382,8 +1382,8 @@ func (ctx *context) Next() { // or context.Next(ctx) // it sends a Status Not Found (404) to the client and it stops the execution. func (ctx *context) NextOr(handlers ...Handler) bool { if next := ctx.NextHandler(); next != nil { - next(ctx) ctx.Skip() // skip this handler from the chain. + next(ctx) return true } diff --git a/mvc/controller_test.go b/mvc/controller_test.go index 0995efad2..1919b08c5 100644 --- a/mvc/controller_test.go +++ b/mvc/controller_test.go @@ -585,3 +585,42 @@ func TestControllerRequestScopedDependencies(t *testing.T) { }) e.GET("/custom/context").Expect().Status(httptest.StatusOK).Body().Equal("test") } + +type ( + testServiceDoSomething struct{} + + TestControllerAsDeepDep struct { + Ctx iris.Context + Service *testServiceDoSomething + } + + FooController struct { + TestControllerAsDeepDep + } + + BarController struct { + FooController + } + + FinalController struct { + BarController + } +) + +func (s *testServiceDoSomething) DoSomething(ctx iris.Context) { + ctx.WriteString("foo bar") +} + +func (c *FinalController) GetSomething() { + c.Service.DoSomething(c.Ctx) +} + +func TestControllersInsideControllerDeep(t *testing.T) { + app := iris.New() + m := New(app) + m.Register(new(testServiceDoSomething)) + m.Handle(new(FinalController)) + + e := httptest.New(t, app) + e.GET("/something").Expect().Status(httptest.StatusOK).Body().Equal("foo bar") +}