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

Headers instead of sessions on scaffolding for API apps #2043

Closed
exocode opened this issue Nov 27, 2018 · 6 comments
Closed

Headers instead of sessions on scaffolding for API apps #2043

exocode opened this issue Nov 27, 2018 · 6 comments

Comments

@exocode
Copy link

exocode commented Nov 27, 2018

I have a question regarding to scaffolding on API only apps.

Each time I scaffold an spec (controllers for example) it writes

session: valid_session

instead of

headers: valid_headers

  describe "GET #show" do
    it "returns a success response" do
      user = User.create! valid_attributes
      get :show, params: {id: user.to_param}, session: valid_session
      expect(response).to be_successful
    end
  end

Wouldn't it be better to scaffold with headers instead of sessions?
The most APIs are using JWT or other tokens to authenticate.
Aren't Sessions mostly obsolete in APIs?

  describe "GET #show" do
    it "returns a success response" do
      user = User.create! valid_attributes
      get :show, params: {id: user.to_param}, headers: valid_headers
      expect(response).to be_successful
    end
  end
@benoittgt
Copy link
Member

This is a choice that has been made two years ago but was not motivated e985c13

I don't know if we should change that. Maybe @JonRowe have an idea? 😃

@JonRowe
Copy link
Member

JonRowe commented Nov 28, 2018

The scaffolding was based on the old controller specs, it simply wasn't something considered. Only hesitation is that switching would have to consider the difference in how headers are handled across rails versions, this would need to be tested as working on all versions of Rails and not just as "output" is correct.

@benoittgt
Copy link
Member

@exocode Do you want to work on a PR to validate the behavior on Rails versions supported by rspec-rails?

@exocode
Copy link
Author

exocode commented Nov 30, 2018

@benoittgt I would give it a try :-)

@klyonrad
Copy link
Contributor

I was wondering about this when I worked on my PR. I am not sure if I understand the initial problem of this issue correctly, but in my opinion this is less of an issue now because since #2288 scaffolding with the --api option does actually generate request specs that generate a valid_headers method.

@JonRowe
Copy link
Member

JonRowe commented Mar 15, 2020

Closing since I think this is solved now.

@JonRowe JonRowe closed this as completed Mar 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants