Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate request spec by default when generating scaffolds #2230

Closed
klyonrad opened this issue Dec 15, 2019 · 9 comments
Closed

Generate request spec by default when generating scaffolds #2230

klyonrad opened this issue Dec 15, 2019 · 9 comments
Assignees
Labels

Comments

@klyonrad
Copy link
Contributor

Similar problem like in #2056. Upon using rails generate scaffold it would be good if controller tests would not get generated and instead request specs are generated.

@JonRowe
Copy link
Member

JonRowe commented Dec 20, 2019

Now that #2222 is merged do you fancy a go at this as well @klyonrad ?

@klyonrad
Copy link
Contributor Author

Yes, that's why I created this issue 😉

@klyonrad
Copy link
Contributor Author

klyonrad commented Jan 11, 2020

Hey @JonRowe do you happen to have an idea why the Scaffold Generator creates the empty request spec?

I think my previous PR had this effect

See


rails generate scaffold product title:string body:text published:boolean -p

....
      invoke    rspec
      create      spec/controllers/products_controller_spec.rb
      create      spec/views/products/edit.html.erb_spec.rb
      create      spec/views/products/index.html.erb_spec.rb
      create      spec/views/products/new.html.erb_spec.rb
      create      spec/views/products/show.html.erb_spec.rb
      create      spec/routing/products_routing_spec.rb
      invoke      rspec
      create        spec/requests/products_spec.rb

...

I suspect that it is caused because the scaffolds generator executes the controller Generator and the Controller Generator has the default option for the request spec from my previous PR

@JonRowe
Copy link
Member

JonRowe commented Jan 20, 2020

I am unsure, I can see it happens although it is not empty for me.., the fact there is extra indented output seems wrong too

@JonRowe
Copy link
Member

JonRowe commented Mar 10, 2020

So I investigated, and I'm pretty certain this happens even without your changes...

@JonRowe
Copy link
Member

JonRowe commented Mar 10, 2020

In fact its hook_for that triggers it

@klyonrad
Copy link
Contributor Author

klyonrad commented Mar 10, 2020

So I investigated, and I'm pretty certain this happens even without your changes...

@JonRowe Are you sure or did I maybe make things confusing? I didn't mean the PR that is linked to this PR, but rather #2222 is the culprit. Should I open a separate issue to avoid confusion?

My theory is that the added class_option :request_specs, type: :boolean, default: true, desc: "Generate request specs" in the controller generator gets picked up somehow by the scaffold generator. This theory comes from the fact that scaffold generator acts weird even when I use a current stable version (3.8.3) and add the --request_specs option through the command line usage, for example rails generate scaffold product title:string body:text published:boolean -p --request_specs.

In fact its hook_for that triggers it

It was not obvious to me why the hook_for was added there. I went into the git history in the file and landed at the historic initial commits f06aa50. In 8cfb234 (the WiP PR) I removed it

@JonRowe
Copy link
Member

JonRowe commented Mar 11, 2020

@JonRowe Are you sure or did I maybe make things confusing? I didn't mean the PR that is linked to this PR, but rather #2222 is the culprit. Should I open a separate issue to avoid confusion?

I'm sure, I reverted #2222, and it still happened. What happens is hook_for is a trigger for activating other generators, and it runs the equivalent of rails generate integration product which is currently implemented as a request spec.

@JonRowe
Copy link
Member

JonRowe commented Mar 13, 2020

Fixed in #2288

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants