Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Resource generator should generate default tests #245

Open
markbates opened this issue Apr 6, 2017 · 14 comments
Open

Resource generator should generate default tests #245

markbates opened this issue Apr 6, 2017 · 14 comments
Labels
enhancement New feature or request
Milestone

Comments

@markbates
Copy link
Member

Right now it generates tests that look like this:

func (as *ActionSuite) Test_BooksResource_List() {
	as.Fail("Not Implemented!")
}
...

It would be fantastic if these tests were actually implemented when generating a new resource.

This ticket is not for the faint of heart. :)

@paganotoni
Copy link
Member

@markbates i can take this one :)

@paganotoni paganotoni self-assigned this Apr 6, 2017
@as27
Copy link

as27 commented Apr 7, 2017

@apaganobeleno if you need some help, just let me know.

@stanislas-m stanislas-m added the enhancement New feature or request label Apr 7, 2017
@paganotoni
Copy link
Member

@as27 would you like to take this one? i'm afraid i wont have much time for the next month and don't want to delay this more.

@as27
Copy link

as27 commented Apr 26, 2017

@apaganobeleno yes of course. I would love to help out here.

@paganotoni paganotoni removed their assignment Apr 26, 2017
@as27 as27 self-assigned this Apr 27, 2017
@as27
Copy link

as27 commented Apr 28, 2017

@markbates I would make the tests analog to the todo app. The tests will also use ActionSuite like here:
https://github.com/gobuffalo/toodo/blob/master/actions/todos_test.go

@markbates
Copy link
Member Author

That makes sense.

@as27
Copy link

as27 commented May 26, 2017

The test generator is almost ready. But when I run the tests I receive always return code 500. I think I need a little help to understand why.

The template file for the generator would be here:
https://github.com/as27/buffalo/blob/resource-test-generator/generators/resource/templates/actions/resource-use_model_test.go.tmpl

I made a own repository for a generated example. The output after code generation is:
https://github.com/as27/buffaloresourcetest/blob/master/actions/users_test.go

But when I run buffalo test inside this repository I get always 500 as return code.

@stanislas-m
Copy link
Member

stanislas-m commented May 28, 2017

@as27 Giving a quick look, it seems you have a typo in https://github.com/as27/buffalo/blob/resource-test-generator/generators/resource/templates/actions/resource-use_model_test.go.tmpl line 49

{{.Singular}} -> {{.singular}}

The other errors seem linked to the lack of CSRF token in your request, but the suite utils should disable this middleware.

@as27
Copy link

as27 commented May 28, 2017

@stanislas-m thanks. CSRF was the missing link I didn't see. But that issue is more a gobuffalo/suite issue then a generator thing (look here)? Or am I wrong?

@stanislas-m
Copy link
Member

stanislas-m commented May 28, 2017

@as27, as I understand the way the CSRF is handled in the test suite, it just replaces the middleware with a no-op. Maybe I'm wrong, but I think the app.Use gets a copy of the middleware, so, if you replace it after the app.Use call it can't work.

Maybe the app.Use should take a pointer to allow this kind of override?

edit: I found a Replace method in the middleware stack, maybe it can be used to fix the problem in gobuffalo/suite?

@as27
Copy link

as27 commented May 28, 2017

@stanislas-m thank you. I had the same thoughts about this.
A possible fix here would be to deactivate CSRF middleware inside the action_test.go file. But I think that this would be a bad idea. I think the tests also have to have valid requests inside the ActionSuite type.
@markbates I would now make a PR just for the resource generator, because without the CSRF middleware the tests are passing. If you want I will open an issue for that at gobuffalo/suite.

@stanislas-m
Copy link
Member

@as27, I also think preventing the middleware to do its work is a bad thing. What we should test, is the normal case, with a given token.

The CSRF token is stored in the buffalo context, and in the session (key name is "authenticity_token"). Maybe you can do a first query to get a valid token, and manage to get the token from either the context or the session.

@benjaminch
Copy link

Hello guys !

I really like the idea of having a basic set of tests generated automatically.
Is it still something? Is someone working on this one?

Cheers

@lukasschlueter
Copy link

Will be looking into this once gobuffalo/buffalo#1521 is merged, it should make this change a lot easier

@lukasschlueter lukasschlueter self-assigned this Jan 4, 2019
@sio4 sio4 transferred this issue from gobuffalo/buffalo Nov 21, 2022
@sio4 sio4 added this to the Backlog milestone Nov 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

7 participants