From f74d72c4011b2429bf6cf838aa762c2dfa477fc5 Mon Sep 17 00:00:00 2001 From: Antonio Pagano Date: Mon, 15 May 2017 20:20:55 -0500 Subject: [PATCH 1/7] [cleaning] moving g action tests to be filetests --- Dockerfile | 9 +++- .../cmd/filetests/generate_action_all.json | 24 ++++++++++ .../filetests/generate_action_existing.json | 13 +++++ buffalo/cmd/generate/action_test.go | 47 ++++++++----------- 4 files changed, 64 insertions(+), 29 deletions(-) create mode 100644 buffalo/cmd/filetests/generate_action_all.json create mode 100644 buffalo/cmd/filetests/generate_action_existing.json diff --git a/Dockerfile b/Dockerfile index d8cd40caa..c55b8c00f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -71,10 +71,17 @@ RUN buffalo db g model ouch RUN buffalo d model -y ouch RUN filetest -c $GOPATH/src/github.com/gobuffalo/buffalo/buffalo/cmd/filetests/destroy_model_all.json -RUN buffalo db g actions ouch build edit +RUN buffalo g actions ouch build edit RUN buffalo d action -y ouch RUN filetest -c $GOPATH/src/github.com/gobuffalo/buffalo/buffalo/cmd/filetests/destroy_action_all.json +RUN buffalo g actions comments show edit +RUN filetest -c $GOPATH/src/github.com/gobuffalo/buffalo/buffalo/cmd/filetests/generate_action_all.json + +RUN buffalo g actions comments destroy +RUN filetest -c $GOPATH/src/github.com/gobuffalo/buffalo/buffalo/cmd/filetests/generate_action_existing.json + + WORKDIR $GOPATH/src RUN buffalo new --skip-pop simple_world WORKDIR ./simple_world diff --git a/buffalo/cmd/filetests/generate_action_all.json b/buffalo/cmd/filetests/generate_action_all.json new file mode 100644 index 000000000..302d50fe6 --- /dev/null +++ b/buffalo/cmd/filetests/generate_action_all.json @@ -0,0 +1,24 @@ +//buffalo g action comments show edit +[{ + "path": "actions/comments.go", + "contains": [ + "func CommentsShow(c buffalo.Context) error {", + "func CommentsEdit(c buffalo.Context) error {", + + "comments/edit.html", + "comments/show.html" + ] +}, +{ + "path": "actions/app.go", + "contains": [ + "app.GET(\"comments/show\", CommentsShow)", + "app.GET(\"comments/edit\", CommentsEdit)" + ] +}, +{ + "path": "templates/comments/show.html", + "contains": [ + "

Comments#Show

" + ] +}] \ No newline at end of file diff --git a/buffalo/cmd/filetests/generate_action_existing.json b/buffalo/cmd/filetests/generate_action_existing.json new file mode 100644 index 000000000..fdf12a043 --- /dev/null +++ b/buffalo/cmd/filetests/generate_action_existing.json @@ -0,0 +1,13 @@ +//buffalo g action comments destroy +[{ + "path": "actions/comments.go", + "contains": [ + "func CommentsShow(c buffalo.Context) error {", + "func CommentsEdit(c buffalo.Context) error {", + "func CommentsDestroy(c buffalo.Context) error {", + + "comments/edit.html", + "comments/destroy.html", + "comments/show.html" + ] +}] \ No newline at end of file diff --git a/buffalo/cmd/generate/action_test.go b/buffalo/cmd/generate/action_test.go index 851c4c4bf..1c9fae007 100644 --- a/buffalo/cmd/generate/action_test.go +++ b/buffalo/cmd/generate/action_test.go @@ -1,39 +1,29 @@ package generate -import ( - "io/ioutil" - "os" - "path/filepath" - "strings" - "testing" - - "github.com/spf13/cobra" - "github.com/stretchr/testify/require" -) - -func TestGenerateActionArgsComplete(t *testing.T) { - dir := os.TempDir() - packagePath := filepath.Join(dir, "src", "sample") - os.MkdirAll(packagePath, 0755) - os.Chdir(packagePath) +// func TestGenerateActionArgsComplete(t *testing.T) { +// dir := os.TempDir() +// packagePath := filepath.Join(dir, "src", "sample") +// os.MkdirAll(packagePath, 0755) +// os.Chdir(packagePath) - r := require.New(t) +// r := require.New(t) - cmd := cobra.Command{} +// cmd := cobra.Command{} - e := ActionCmd.RunE(&cmd, []string{}) - r.NotNil(e) +// e := ActionCmd.RunE(&cmd, []string{}) +// r.NotNil(e) - e = ActionCmd.RunE(&cmd, []string{"nodes"}) - r.NotNil(e) +// e = ActionCmd.RunE(&cmd, []string{"nodes"}) +// r.NotNil(e) - os.Mkdir("actions", 0755) - ioutil.WriteFile("actions/app.go", appGo, 0755) +// os.Mkdir("actions", 0755) +// ioutil.WriteFile("actions/app.go", appGo, 0755) - e = ActionCmd.RunE(&cmd, []string{"nodes", "show"}) - r.Nil(e) -} +// e = ActionCmd.RunE(&cmd, []string{"nodes", "show"}) +// r.Nil(e) +// } +/* func TestGenerateActionActionsFolderExists(t *testing.T) { dir := os.TempDir() packagePath := filepath.Join(dir, "src", "sample") @@ -64,7 +54,7 @@ func TestGenerateActionActionsFolderExists(t *testing.T) { r.Contains(string(data), `c.Render(200, r.HTML("comments/show.html"))`) data, _ = ioutil.ReadFile("templates/comments/show.html") - r.Contains(string(data), "

Comments#Show

") + r.Contains(string(data), "") } func TestGenerateActionActionsFileExists(t *testing.T) { @@ -166,3 +156,4 @@ func App() *buffalo.App { return app } `) +*/ From 2b01512a67431f4c7a79560eafb0967176f06372 Mon Sep 17 00:00:00 2001 From: Antonio Pagano Date: Mon, 15 May 2017 20:46:59 -0500 Subject: [PATCH 2/7] moving resource tests to be filetest as well --- Dockerfile | 4 + .../filetests/generate_resource_plural.json | 22 +++ .../filetests/generate_resource_singular.json | 22 +++ buffalo/cmd/generate/action_test.go | 159 ------------------ buffalo/cmd/generate/resource_test.go | 69 -------- 5 files changed, 48 insertions(+), 228 deletions(-) create mode 100644 buffalo/cmd/filetests/generate_resource_plural.json create mode 100644 buffalo/cmd/filetests/generate_resource_singular.json delete mode 100644 buffalo/cmd/generate/action_test.go delete mode 100644 buffalo/cmd/generate/resource_test.go diff --git a/Dockerfile b/Dockerfile index c55b8c00f..36f0b4a21 100644 --- a/Dockerfile +++ b/Dockerfile @@ -82,6 +82,10 @@ RUN buffalo g actions comments destroy RUN filetest -c $GOPATH/src/github.com/gobuffalo/buffalo/buffalo/cmd/filetests/generate_action_existing.json +RUN buffalo g resource user +RUN filetest -c $GOPATH/src/github.com/gobuffalo/buffalo/buffalo/cmd/filetests/generate_resource_singular.json + + WORKDIR $GOPATH/src RUN buffalo new --skip-pop simple_world WORKDIR ./simple_world diff --git a/buffalo/cmd/filetests/generate_resource_plural.json b/buffalo/cmd/filetests/generate_resource_plural.json new file mode 100644 index 000000000..304c660f8 --- /dev/null +++ b/buffalo/cmd/filetests/generate_resource_plural.json @@ -0,0 +1,22 @@ +[{ + "path": "actions/comments.go", + "contains": [ + "func (v CommentsResource) List(c buffalo.Context) error {", + "func (v CommentsResource) Destroy(c buffalo.Context) error {", + "type CommentsResource struct {" + ] +}, +{ + "path": "actions/app.go", + "contains": [ + "app.Resource(\"/comments\", CommentsResource{&buffalo.BaseResource{}})" + ] +}, +{ + "path": "actions/comments_test.go", + "contains": [ + "func (as *ActionSuite) Test_CommentsResource_List", + "func (as *ActionSuite) Test_CommentsResource_Show", + "func (as *ActionSuite) Test_CommentsResource_Create" + ] +}] \ No newline at end of file diff --git a/buffalo/cmd/filetests/generate_resource_singular.json b/buffalo/cmd/filetests/generate_resource_singular.json new file mode 100644 index 000000000..144c90511 --- /dev/null +++ b/buffalo/cmd/filetests/generate_resource_singular.json @@ -0,0 +1,22 @@ +[{ + "path": "actions/users.go", + "contains": [ + "func (v UsersResource) List(c buffalo.Context) error {", + "func (v UsersResource) Destroy(c buffalo.Context) error {", + "type UsersResource struct {" + ] +}, +{ + "path": "actions/app.go", + "contains": [ + "app.Resource(\"/users\", UsersResource{&buffalo.BaseResource{}})" + ] +}, +{ + "path": "actions/users_test.go", + "contains": [ + "func (as *ActionSuite) Test_UsersResource_List", + "func (as *ActionSuite) Test_UsersResource_Show", + "func (as *ActionSuite) Test_UsersResource_Create" + ] +}] \ No newline at end of file diff --git a/buffalo/cmd/generate/action_test.go b/buffalo/cmd/generate/action_test.go deleted file mode 100644 index 1c9fae007..000000000 --- a/buffalo/cmd/generate/action_test.go +++ /dev/null @@ -1,159 +0,0 @@ -package generate - -// func TestGenerateActionArgsComplete(t *testing.T) { -// dir := os.TempDir() -// packagePath := filepath.Join(dir, "src", "sample") -// os.MkdirAll(packagePath, 0755) -// os.Chdir(packagePath) - -// r := require.New(t) - -// cmd := cobra.Command{} - -// e := ActionCmd.RunE(&cmd, []string{}) -// r.NotNil(e) - -// e = ActionCmd.RunE(&cmd, []string{"nodes"}) -// r.NotNil(e) - -// os.Mkdir("actions", 0755) -// ioutil.WriteFile("actions/app.go", appGo, 0755) - -// e = ActionCmd.RunE(&cmd, []string{"nodes", "show"}) -// r.Nil(e) -// } - -/* -func TestGenerateActionActionsFolderExists(t *testing.T) { - dir := os.TempDir() - packagePath := filepath.Join(dir, "src", "sample") - os.MkdirAll(packagePath, 0755) - os.Chdir(packagePath) - - os.RemoveAll("actions") - os.RemoveAll("templates") - - r := require.New(t) - cmd := cobra.Command{} - - e := ActionCmd.RunE(&cmd, []string{"comments", "show", "edit"}) - r.NotNil(e) - - os.Mkdir("actions", 0755) - ioutil.WriteFile("actions/app.go", appGo, 0755) - - e = ActionCmd.RunE(&cmd, []string{"comments", "show", "edit"}) - r.Nil(e) - - data, _ := ioutil.ReadFile("actions/comments.go") - r.Contains(string(data), "package actions") - r.Contains(string(data), `import "github.com/gobuffalo/buffalo"`) - r.Contains(string(data), "func CommentsShow(c buffalo.Context) error {") - r.Contains(string(data), "func CommentsEdit(c buffalo.Context) error {") - r.Contains(string(data), `r.HTML("comments/edit.html")`) - r.Contains(string(data), `c.Render(200, r.HTML("comments/show.html"))`) - - data, _ = ioutil.ReadFile("templates/comments/show.html") - r.Contains(string(data), "") -} - -func TestGenerateActionActionsFileExists(t *testing.T) { - dir := os.TempDir() - packagePath := filepath.Join(dir, "src", "sample") - os.MkdirAll(packagePath, 0755) - os.Chdir(packagePath) - - os.Mkdir("actions", 0755) - ioutil.WriteFile("actions/app.go", appGo, 0755) - r := require.New(t) - cmd := cobra.Command{} - usersContent := `package actions -import "log" - -func UsersShow(c buffalo.Context) error { - log.Println("Something Here!") - return c.Render(200, r.String("OK")) -} -` - ioutil.WriteFile("actions/users.go", []byte(usersContent), 0755) - - e := ActionCmd.RunE(&cmd, []string{"users", "show"}) - r.Nil(e) - - data, _ := ioutil.ReadFile("actions/users.go") - r.Contains(string(data), "log.Println(") - r.Contains(string(data), "func UsersShow") - -} - -func TestGenerateNewActionWithExistingActions(t *testing.T) { - dir := os.TempDir() - packagePath := filepath.Join(dir, "src", "sample") - os.MkdirAll(packagePath, 0755) - os.Chdir(packagePath) - - os.RemoveAll("actions") - os.RemoveAll("templates") - - os.Mkdir("actions", 0755) - ioutil.WriteFile("actions/app.go", appGo, 0755) - r := require.New(t) - cmd := cobra.Command{} - e := ActionCmd.RunE(&cmd, []string{"posts", "show", "edit"}) - r.Nil(e) - - data, _ := ioutil.ReadFile("actions/posts.go") - r.Contains(string(data), "package actions") - r.Contains(string(data), "github.com/gobuffalo/buffalo") - r.Contains(string(data), "func PostsShow(c buffalo.Context) error {") - r.Contains(string(data), "func PostsEdit(c buffalo.Context) error {") - r.Contains(string(data), `r.HTML("posts/edit.html")`) - r.Contains(string(data), `c.Render(200, r.HTML("posts/show.html"))`) - - e = ActionCmd.RunE(&cmd, []string{"posts", "list"}) - r.Nil(e) - - data, _ = ioutil.ReadFile("actions/posts.go") - r.Contains(string(data), "package actions") - r.Contains(string(data), "github.com/gobuffalo/buffalo") - r.Contains(string(data), "func PostsShow(c buffalo.Context) error {") - r.Contains(string(data), "func PostsEdit(c buffalo.Context) error {") - r.Contains(string(data), "func PostsList(c buffalo.Context) error {") - r.Contains(string(data), `c.Render(200, r.HTML("posts/list.html"))`) - - data, _ = ioutil.ReadFile("templates/posts/list.html") - r.Contains(string(data), "

Posts#List

") - - data, _ = ioutil.ReadFile("actions/posts_test.go") - r.Contains(string(data), "package actions_test") - r.Contains(string(data), "func (as *ActionSuite) Test_Posts_Show() {") - r.Contains(string(data), "func (as *ActionSuite) Test_Posts_Edit() {") - r.Contains(string(data), "func (as *ActionSuite) Test_Posts_List() {") - - e = ActionCmd.RunE(&cmd, []string{"posts", "list"}) - r.Nil(e) - - data, _ = ioutil.ReadFile("actions/posts_test.go") - r.Equal(strings.Count(string(data), "func (as *ActionSuite) Test_Posts_List() {"), 1) - - data, _ = ioutil.ReadFile("actions/app.go") - r.Equal(strings.Count(string(data), "app.GET(\"/posts/list\", PostsList)"), 1) -} - -var appGo = []byte(` -package actions -var app *buffalo.App -func App() *buffalo.App { - if app == nil { - app = buffalo.Automatic(buffalo.Options{ - Env: "test", - }) - app.GET("/", func (c buffalo.Context) error { - return c.Render(200, r.String("hello")) - }) - } - - return app -} -`) -*/ diff --git a/buffalo/cmd/generate/resource_test.go b/buffalo/cmd/generate/resource_test.go deleted file mode 100644 index bbdf02814..000000000 --- a/buffalo/cmd/generate/resource_test.go +++ /dev/null @@ -1,69 +0,0 @@ -package generate - -import ( - "io/ioutil" - "os" - "path/filepath" - "testing" - - "github.com/spf13/cobra" - "github.com/stretchr/testify/require" -) - -func TestGenerateResourceCode(t *testing.T) { - dir := os.TempDir() - packagePath := filepath.Join(dir, "src", "sample") - os.MkdirAll(packagePath, 0755) - os.Chdir(packagePath) - - r := require.New(t) - - cmd := cobra.Command{} - - e := ActionCmd.RunE(&cmd, []string{}) - r.NotNil(e) - - e = ActionCmd.RunE(&cmd, []string{"users"}) - r.NotNil(e) - - os.Mkdir("actions", 0755) - ioutil.WriteFile("actions/app.go", appGo, 0755) - - SkipResourceMigration = false - SkipResourceModel = false - - // Testing generator with singular definition - e = ResourceCmd.RunE(&cmd, []string{"user"}) - r.Nil(e) - - fileData, _ := ioutil.ReadFile("actions/app.go") - r.Contains(string(fileData), "app.Resource(\"/users\", UsersResource{&buffalo.BaseResource{}})") - - fileData, _ = ioutil.ReadFile("actions/users.go") - r.Contains(string(fileData), "type UsersResource struct {") - r.Contains(string(fileData), "func (v UsersResource) List(c buffalo.Context) error {") - r.Contains(string(fileData), "func (v UsersResource) Destroy(c buffalo.Context) error {") - - fileData, _ = ioutil.ReadFile("actions/users_test.go") - r.Contains(string(fileData), "func (as *ActionSuite) Test_UsersResource_List") - r.Contains(string(fileData), "func (as *ActionSuite) Test_UsersResource_Show") - r.Contains(string(fileData), "func (as *ActionSuite) Test_UsersResource_Create") - - // Testing generator with plural definition - e = ResourceCmd.RunE(&cmd, []string{"comments"}) - r.Nil(e) - - fileData, _ = ioutil.ReadFile("actions/app.go") - r.Contains(string(fileData), "app.Resource(\"/comments\", CommentsResource{&buffalo.BaseResource{}})") - - fileData, _ = ioutil.ReadFile("actions/comments.go") - r.Contains(string(fileData), "type CommentsResource struct {") - r.Contains(string(fileData), "func (v CommentsResource) List(c buffalo.Context) error {") - r.Contains(string(fileData), "func (v CommentsResource) Destroy(c buffalo.Context) error {") - - fileData, _ = ioutil.ReadFile("actions/comments_test.go") - r.Contains(string(fileData), "func (as *ActionSuite) Test_CommentsResource_List") - r.Contains(string(fileData), "func (as *ActionSuite) Test_CommentsResource_Show") - r.Contains(string(fileData), "func (as *ActionSuite) Test_CommentsResource_Create") - -} From bca760e18d8ed557bb7ee63bb5b1749f4366c03b Mon Sep 17 00:00:00 2001 From: Antonio Pagano Date: Mon, 15 May 2017 21:07:20 -0500 Subject: [PATCH 3/7] changing the name of the resource being generated --- Dockerfile | 3 +++ .../filetests/generate_resource_plural.json | 18 +++++++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 36f0b4a21..5f59b2ce8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -85,6 +85,9 @@ RUN filetest -c $GOPATH/src/github.com/gobuffalo/buffalo/buffalo/cmd/filetests/g RUN buffalo g resource user RUN filetest -c $GOPATH/src/github.com/gobuffalo/buffalo/buffalo/cmd/filetests/generate_resource_singular.json +RUN buffalo g resource cars +RUN filetest -c $GOPATH/src/github.com/gobuffalo/buffalo/buffalo/cmd/filetests/generate_resource_plural.json + WORKDIR $GOPATH/src RUN buffalo new --skip-pop simple_world diff --git a/buffalo/cmd/filetests/generate_resource_plural.json b/buffalo/cmd/filetests/generate_resource_plural.json index 304c660f8..4deb7951d 100644 --- a/buffalo/cmd/filetests/generate_resource_plural.json +++ b/buffalo/cmd/filetests/generate_resource_plural.json @@ -1,22 +1,22 @@ [{ - "path": "actions/comments.go", + "path": "actions/cars.go", "contains": [ - "func (v CommentsResource) List(c buffalo.Context) error {", - "func (v CommentsResource) Destroy(c buffalo.Context) error {", - "type CommentsResource struct {" + "func (v CarsResource) List(c buffalo.Context) error {", + "func (v CarsResource) Destroy(c buffalo.Context) error {", + "type CarsResource struct {" ] }, { "path": "actions/app.go", "contains": [ - "app.Resource(\"/comments\", CommentsResource{&buffalo.BaseResource{}})" + "app.Resource(\"/cars\", CarsResource{&buffalo.BaseResource{}})" ] }, { - "path": "actions/comments_test.go", + "path": "actions/cars_test.go", "contains": [ - "func (as *ActionSuite) Test_CommentsResource_List", - "func (as *ActionSuite) Test_CommentsResource_Show", - "func (as *ActionSuite) Test_CommentsResource_Create" + "func (as *ActionSuite) Test_CarsResource_List", + "func (as *ActionSuite) Test_CarsResource_Show", + "func (as *ActionSuite) Test_CarsResource_Create" ] }] \ No newline at end of file From dfacbe0dff39d0dbf2157b0309965e027b08357b Mon Sep 17 00:00:00 2001 From: Antonio Pagano Date: Mon, 15 May 2017 21:17:51 -0500 Subject: [PATCH 4/7] logging error --- generators/helpers_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/generators/helpers_test.go b/generators/helpers_test.go index 38eab9325..e4086b9c1 100644 --- a/generators/helpers_test.go +++ b/generators/helpers_test.go @@ -50,7 +50,7 @@ func App() *buffalo.App { AddRoute("GET", "/new/route", "UserCoolHandler") - contentAfter, _ := ioutil.ReadFile(filepath.Join(packagePath, "actions", "app.go")) + contentAfter, err := ioutil.ReadFile(filepath.Join(packagePath, "actions", "app.go")) r.Equal(`package actions import ( @@ -79,6 +79,6 @@ func App() *buffalo.App { } return app -}`, string(contentAfter)) +}`, string(contentAfter), err.Error()) } From c582874cc4d1e398f22fcd6f4b01a7f0613801e6 Mon Sep 17 00:00:00 2001 From: Antonio Pagano Date: Mon, 15 May 2017 21:22:30 -0500 Subject: [PATCH 5/7] changing permission for the helper test --- generators/helpers_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/generators/helpers_test.go b/generators/helpers_test.go index e4086b9c1..15b69b75b 100644 --- a/generators/helpers_test.go +++ b/generators/helpers_test.go @@ -46,11 +46,11 @@ func App() *buffalo.App { return app }` - ioutil.WriteFile(filepath.Join(packagePath, "actions", "app.go"), []byte(shortAppFileExample), 0755) + ioutil.WriteFile(filepath.Join(packagePath, "actions", "app.go"), []byte(shortAppFileExample), 0644) AddRoute("GET", "/new/route", "UserCoolHandler") - contentAfter, err := ioutil.ReadFile(filepath.Join(packagePath, "actions", "app.go")) + contentAfter, _ := ioutil.ReadFile(filepath.Join(packagePath, "actions", "app.go")) r.Equal(`package actions import ( @@ -79,6 +79,6 @@ func App() *buffalo.App { } return app -}`, string(contentAfter), err.Error()) +}`, string(contentAfter)) } From c9f304b271eaa0227fecb519d4a07a35931d315b Mon Sep 17 00:00:00 2001 From: Antonio Pagano Date: Mon, 15 May 2017 21:27:17 -0500 Subject: [PATCH 6/7] permissions for the directory --- generators/helpers_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generators/helpers_test.go b/generators/helpers_test.go index 15b69b75b..0cff9eaf6 100644 --- a/generators/helpers_test.go +++ b/generators/helpers_test.go @@ -14,7 +14,7 @@ func TestAppendRoute(t *testing.T) { tmpDir := os.TempDir() packagePath := filepath.Join(tmpDir, "src", "sample") - os.MkdirAll(packagePath, 0755) + os.MkdirAll(packagePath, 0644) os.Chdir(packagePath) const shortAppFileExample = `package actions From 40040b6e286e684ae456b45c7060b646e360b12e Mon Sep 17 00:00:00 2001 From: Antonio Pagano Date: Tue, 16 May 2017 11:10:09 -0500 Subject: [PATCH 7/7] fixing issue with the helper tests --- Dockerfile | 1 - buffalo/cmd/filetests/generate_action_all.json | 10 ++++------ .../cmd/filetests/generate_action_existing.json | 14 ++++++++++---- generators/helpers_test.go | 5 ++++- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5f59b2ce8..9b40dafd6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -81,7 +81,6 @@ RUN filetest -c $GOPATH/src/github.com/gobuffalo/buffalo/buffalo/cmd/filetests/g RUN buffalo g actions comments destroy RUN filetest -c $GOPATH/src/github.com/gobuffalo/buffalo/buffalo/cmd/filetests/generate_action_existing.json - RUN buffalo g resource user RUN filetest -c $GOPATH/src/github.com/gobuffalo/buffalo/buffalo/cmd/filetests/generate_resource_singular.json diff --git a/buffalo/cmd/filetests/generate_action_all.json b/buffalo/cmd/filetests/generate_action_all.json index 302d50fe6..296f03c97 100644 --- a/buffalo/cmd/filetests/generate_action_all.json +++ b/buffalo/cmd/filetests/generate_action_all.json @@ -1,19 +1,17 @@ -//buffalo g action comments show edit [{ "path": "actions/comments.go", "contains": [ "func CommentsShow(c buffalo.Context) error {", - "func CommentsEdit(c buffalo.Context) error {", - + "func CommentsEdit(c buffalo.Context) error {", "comments/edit.html", - "comments/show.html" + "comments/show.html" ] }, { "path": "actions/app.go", "contains": [ - "app.GET(\"comments/show\", CommentsShow)", - "app.GET(\"comments/edit\", CommentsEdit)" + "app.GET(\"/comments/show\", CommentsShow)", + "app.GET(\"/comments/edit\", CommentsEdit)" ] }, { diff --git a/buffalo/cmd/filetests/generate_action_existing.json b/buffalo/cmd/filetests/generate_action_existing.json index fdf12a043..9e7c7d598 100644 --- a/buffalo/cmd/filetests/generate_action_existing.json +++ b/buffalo/cmd/filetests/generate_action_existing.json @@ -1,13 +1,19 @@ -//buffalo g action comments destroy [{ "path": "actions/comments.go", "contains": [ "func CommentsShow(c buffalo.Context) error {", - "func CommentsEdit(c buffalo.Context) error {", + "func CommentsEdit(c buffalo.Context) error {", "func CommentsDestroy(c buffalo.Context) error {", - "comments/edit.html", "comments/destroy.html", - "comments/show.html" + "comments/show.html" + ] +}, +{ + "path": "actions/app.go", + "contains": [ + "app.GET(\"/comments/destroy\", CommentsDestroy)", + "app.GET(\"/comments/edit\", CommentsEdit)", + "app.GET(\"/comments/show\", CommentsShow)" ] }] \ No newline at end of file diff --git a/generators/helpers_test.go b/generators/helpers_test.go index 0cff9eaf6..f7336325f 100644 --- a/generators/helpers_test.go +++ b/generators/helpers_test.go @@ -14,7 +14,9 @@ func TestAppendRoute(t *testing.T) { tmpDir := os.TempDir() packagePath := filepath.Join(tmpDir, "src", "sample") - os.MkdirAll(packagePath, 0644) + err := os.MkdirAll(packagePath, 0644) + println(err) + os.Chdir(packagePath) const shortAppFileExample = `package actions @@ -46,6 +48,7 @@ func App() *buffalo.App { return app }` + os.MkdirAll("actions", 0644) ioutil.WriteFile(filepath.Join(packagePath, "actions", "app.go"), []byte(shortAppFileExample), 0644) AddRoute("GET", "/new/route", "UserCoolHandler")